Changeset: f87c263f1de8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f87c263f1de8
Modified Files:
        sql/storage/store.c
Branch: transaction-replication
Log Message:

Re-load the store after schema update from shared logger.

To facilitate that and reduce code duplication:
- Pull all basic store schema init and transaction loading in new function 
store_load
-- Store the backend stack and debug setting globally for store_load to access 
later
- When updating the store_oid on store load get the sequence id from the shared 
logger (if there's one)

- Delete the global transaction and reset store_oid to 0 before re-loading the 
store

While there:
- Fix a bug in destroy_spare_transactions, by resetting the spares to 0 once 
all transactions are deleted.


diffs (truncated from 720 to 300 lines):

diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -49,6 +49,8 @@ int keep_persisted_log_files = 0;
 int create_shared_logger = 0;
 int shared_drift_threshold = -1;
 
+backend_stack backend_stk;
+
 store_functions store_funcs;
 table_functions table_funcs;
 logger_functions logger_funcs;
@@ -57,6 +59,7 @@ logger_functions shared_logger_funcs;
 static int schema_number = 0; /* each committed schema change triggers a new
                                 schema number (session wise unique number) */
 static int bs_debug = 0;
+static int logger_debug = 0;
 
 #define MAX_SPARES 32
 static sql_trans *spare_trans[MAX_SPARES];
@@ -1294,19 +1297,215 @@ store_schema_number(void)
        return schema_number;
 }
 
+static int
+store_load() {
+       int first = 1;
+
+       sql_allocator *sa;
+       sql_trans *tr;
+       sql_table *t, *types, *funcs, *args;
+       sql_schema *s, *p = NULL;
+
+       lng lng_store_oid;
+       sqlid id = 0;
+
+       sa = sa_create();
+       MT_lock_unset(&bs_lock, "store_load");
+       types_init(sa, logger_debug);
+
+#define FUNC_OIDS 2000
+       assert( store_oid <= FUNC_OIDS );
+       /* we store some spare oids */
+       store_oid = FUNC_OIDS;
+
+       sequences_init();
+       gtrans = tr = create_trans(sa, backend_stk);
+       active_transactions = sa_list(sa);
+
+       if (logger_funcs.log_isnew()) {
+               /* cannot initialize database in readonly mode
+                * unless this is a slave instance with a read-only/shared 
logger */
+               if (store_readonly && !create_shared_logger) {
+                       return -1;
+               }
+               tr = sql_trans_create(backend_stk, NULL, NULL);
+       } else {
+               first = 0;
+       }
+
+       s = bootstrap_create_schema(tr, "sys", ROLE_SYSADMIN, USER_MONETDB);
+       if (!first) {
+               s->base.flag = TR_OLD;
+       }
+
+       t = bootstrap_create_table(tr, s, "schemas");
+       bootstrap_create_column(tr, t, "id", "int", 32);
+       bootstrap_create_column(tr, t, "name", "varchar", 1024);
+       bootstrap_create_column(tr, t, "authorization", "int", 32);
+       bootstrap_create_column(tr, t, "owner", "int", 32);
+       bootstrap_create_column(tr, t, "system", "boolean", 1);
+
+       types = t = bootstrap_create_table(tr, s, "types");
+       bootstrap_create_column(tr, t, "id", "int", 32);
+       bootstrap_create_column(tr, t, "systemname", "varchar", 256);
+       bootstrap_create_column(tr, t, "sqlname", "varchar", 1024);
+       bootstrap_create_column(tr, t, "digits", "int", 32);
+       bootstrap_create_column(tr, t, "scale", "int", 32);
+       bootstrap_create_column(tr, t, "radix", "int", 32);
+       bootstrap_create_column(tr, t, "eclass", "int", 32);
+       bootstrap_create_column(tr, t, "schema_id", "int", 32);
+
+       funcs = t = bootstrap_create_table(tr, s, "functions");
+       bootstrap_create_column(tr, t, "id", "int", 32);
+       bootstrap_create_column(tr, t, "name", "varchar", 256);
+       bootstrap_create_column(tr, t, "func", "varchar", 8196);
+       bootstrap_create_column(tr, t, "mod", "varchar", 8196);
+       /* sql or database internal */
+       bootstrap_create_column(tr, t, "sql", "boolean", 1);
+       /* func, proc, aggr or filter */
+       bootstrap_create_column(tr, t, "type", "int", 32);
+       bootstrap_create_column(tr, t, "side_effect", "boolean", 1);
+       bootstrap_create_column(tr, t, "varres", "boolean", 1);
+       bootstrap_create_column(tr, t, "vararg", "boolean", 1);
+       bootstrap_create_column(tr, t, "schema_id", "int", 32);
+
+       args = t = bootstrap_create_table(tr, s, "args");
+       bootstrap_create_column(tr, t, "id", "int", 32);
+       bootstrap_create_column(tr, t, "func_id", "int", 32);
+       bootstrap_create_column(tr, t, "name", "varchar", 256);
+       bootstrap_create_column(tr, t, "type", "varchar", 1024);
+       bootstrap_create_column(tr, t, "type_digits", "int", 32);
+       bootstrap_create_column(tr, t, "type_scale", "int", 32);
+       bootstrap_create_column(tr, t, "inout", "tinyint", 8);
+       bootstrap_create_column(tr, t, "number", "int", 32);
+
+       t = bootstrap_create_table(tr, s, "sequences");
+       bootstrap_create_column(tr, t, "id", "int", 32);
+       bootstrap_create_column(tr, t, "schema_id", "int", 32);
+       bootstrap_create_column(tr, t, "name", "varchar", 256);
+       bootstrap_create_column(tr, t, "start", "bigint", 64);
+       bootstrap_create_column(tr, t, "minvalue", "bigint", 64);
+       bootstrap_create_column(tr, t, "maxvalue", "bigint", 64);
+       bootstrap_create_column(tr, t, "increment", "bigint", 64);
+       bootstrap_create_column(tr, t, "cacheinc", "bigint", 64);
+       bootstrap_create_column(tr, t, "cycle", "boolean", 1);
+
+       t = bootstrap_create_table(tr, s, "dependencies");
+       bootstrap_create_column(tr, t, "id", "int", 32);
+       bootstrap_create_column(tr, t, "depend_id", "int", 32);
+       bootstrap_create_column(tr, t, "depend_type", "smallint", 16);
+
+       t = bootstrap_create_table(tr, s, "connections");
+       bootstrap_create_column(tr, t, "id", "int", 32);
+       bootstrap_create_column(tr, t, "server", "char", 1024);
+       bootstrap_create_column(tr, t, "port", "int", 32);
+       bootstrap_create_column(tr, t, "db", "char", 64);
+       bootstrap_create_column(tr, t, "db_alias", "char", 1024);
+       bootstrap_create_column(tr, t, "user", "char", 1024);
+       bootstrap_create_column(tr, t, "password", "char", 1024);
+       bootstrap_create_column(tr, t, "language", "char", 1024);
+
+       while(s) {
+               t = bootstrap_create_table(tr, s, "_tables");
+               bootstrap_create_column(tr, t, "id", "int", 32);
+               bootstrap_create_column(tr, t, "name", "varchar", 1024);
+               bootstrap_create_column(tr, t, "schema_id", "int", 32);
+               bootstrap_create_column(tr, t, "query", "varchar", 2048);
+               bootstrap_create_column(tr, t, "type", "smallint", 16);
+               bootstrap_create_column(tr, t, "system", "boolean", 1);
+               bootstrap_create_column(tr, t, "commit_action", "smallint", 16);
+               bootstrap_create_column(tr, t, "readonly", "boolean", 1);
+
+               t = bootstrap_create_table(tr, s, "_columns");
+               bootstrap_create_column(tr, t, "id", "int", 32);
+               bootstrap_create_column(tr, t, "name", "varchar", 1024);
+               bootstrap_create_column(tr, t, "type", "varchar", 1024);
+               bootstrap_create_column(tr, t, "type_digits", "int", 32);
+               bootstrap_create_column(tr, t, "type_scale", "int", 32);
+               bootstrap_create_column(tr, t, "table_id", "int", 32);
+               bootstrap_create_column(tr, t, "default", "varchar", 2048);
+               bootstrap_create_column(tr, t, "null", "boolean", 1);
+               bootstrap_create_column(tr, t, "number", "int", 32);
+               bootstrap_create_column(tr, t, "storage", "varchar", 2048);
+
+               t = bootstrap_create_table(tr, s, "keys");
+               bootstrap_create_column(tr, t, "id", "int", 32);
+               bootstrap_create_column(tr, t, "table_id", "int", 32);
+               bootstrap_create_column(tr, t, "type", "int", 32);
+               bootstrap_create_column(tr, t, "name", "varchar", 1024);
+               bootstrap_create_column(tr, t, "rkey", "int", 32);
+               bootstrap_create_column(tr, t, "action", "int", 32);
+
+               t = bootstrap_create_table(tr, s, "idxs");
+               bootstrap_create_column(tr, t, "id", "int", 32);
+               bootstrap_create_column(tr, t, "table_id", "int", 32);
+               bootstrap_create_column(tr, t, "type", "int", 32);
+               bootstrap_create_column(tr, t, "name", "varchar", 1024);
+
+               t = bootstrap_create_table(tr, s, "triggers");
+               bootstrap_create_column(tr, t, "id", "int", 32);
+               bootstrap_create_column(tr, t, "name", "varchar", 1024);
+               bootstrap_create_column(tr, t, "table_id", "int", 32);
+               bootstrap_create_column(tr, t, "time", "smallint", 16);
+               bootstrap_create_column(tr, t, "orientation", "smallint", 16);
+               bootstrap_create_column(tr, t, "event", "smallint", 16);
+               bootstrap_create_column(tr, t, "old_name", "varchar", 1024);
+               bootstrap_create_column(tr, t, "new_name", "varchar", 1024);
+               bootstrap_create_column(tr, t, "condition", "varchar", 2048);
+               bootstrap_create_column(tr, t, "statement", "varchar", 2048);
+
+               t = bootstrap_create_table(tr, s, "objects");
+               bootstrap_create_column(tr, t, "id", "int", 32);
+               bootstrap_create_column(tr, t, "name", "varchar", 1024);
+               bootstrap_create_column(tr, t, "nr", "int", 32);
+
+               if (!p) {
+                       p = s;
+                       /* now the same tables for temporaries */
+                       s = bootstrap_create_schema(tr, "tmp", ROLE_SYSADMIN, 
USER_MONETDB);
+               } else {
+                       s = NULL;
+               }
+       }
+
+       (void) bootstrap_create_schema(tr, dt_schema, ROLE_SYSADMIN, 
USER_MONETDB);
+
+       if (first) {
+               insert_types(tr, types);
+               insert_functions(tr, funcs, args);
+               insert_aggrs(tr, funcs, args);
+               insert_schemas(tr);
+
+               if (sql_trans_commit(tr) != SQL_OK) {
+                       fprintf(stderr, "cannot commit initial transaction\n");
+               }
+               sql_trans_destroy(tr);
+       }
+
+       id = store_oid; /* db objects up till id are already created */
+       if (!create_shared_logger) {
+               logger_funcs.get_sequence(OBJ_SID, &lng_store_oid);
+       } else {
+               shared_logger_funcs.get_sequence(OBJ_SID, &lng_store_oid);
+       }
+       prev_oid = store_oid = (sqlid)lng_store_oid;
+
+       /* load remaining schemas, tables, columns etc */
+       if (!first)
+               load_trans(gtrans, id);
+       return first;
+}
+
 int
 store_init(int debug, store_type store, int readonly, int singleuser, 
logger_settings *log_settings, backend_stack stk)
 {
-       sqlid id = 0;
-       lng lng_store_oid;
-       int first = 1;
-       sql_schema *s, *p = NULL;
-       sql_table *t, *types, *funcs, *args;
-       sql_trans *tr;
        int v = 1;
-       sql_allocator *sa;
-
+
+       backend_stk = stk;
+       logger_debug = debug;
        bs_debug = debug&2;
+       store_readonly = readonly;
+       store_singleuser = singleuser;
        /* get the set shared_drift_threshold
         * we will need it later in store_manager */
        shared_drift_threshold = log_settings->shared_drift_threshold;
@@ -1320,12 +1519,12 @@ store_init(int debug, store_type store, 
        MT_lock_set(&bs_lock, "store_init");
 
        /* check if all parameters for a shared log are set */
-       if (readonly && log_settings->shared_logdir != NULL && 
log_settings->shared_drift_threshold >= 0) {
+       if (store_readonly && log_settings->shared_logdir != NULL && 
log_settings->shared_drift_threshold >= 0) {
                create_shared_logger = 1;
        }
 
        /* initialize empty bats */
-       if (store == store_bat) 
+       if (store == store_bat)
                bat_utils_init();
        if (store == store_bat) {
                bat_storage_init(&store_funcs);
@@ -1353,189 +1552,8 @@ store_init(int debug, store_type store, 
                }
        }
 
-       sa = sa_create();
-       MT_lock_unset(&bs_lock, "store_init");
-       types_init(sa, debug);
-
-#define FUNC_OIDS 2000
-       assert( store_oid <= FUNC_OIDS );
-       /* we store some spare oids */
-       store_oid = FUNC_OIDS;
-
-       sequences_init();
-       gtrans = tr = create_trans(sa, stk);
-       active_transactions = sa_list(sa); 
-
-       store_readonly = readonly;
-       store_singleuser = singleuser;
-
-       if (logger_funcs.log_isnew()) {
-               /* cannot initialize database in readonly mode
-                * unless this is a slave instance with a read-only/shared 
logger */
-               if (readonly && !create_shared_logger) {
-                       return -1;
-               }
-               tr = sql_trans_create(stk, NULL, NULL);
-       } else {
-               first = 0;
-       }
-
-       s = bootstrap_create_schema(tr, "sys", ROLE_SYSADMIN, USER_MONETDB);
-       if (!first) 
-               s->base.flag = TR_OLD;
-
-       t = bootstrap_create_table(tr, s, "schemas");
-       bootstrap_create_column(tr, t, "id", "int", 32);
-       bootstrap_create_column(tr, t, "name", "varchar", 1024);
-       bootstrap_create_column(tr, t, "authorization", "int", 32);
-       bootstrap_create_column(tr, t, "owner", "int", 32);
-       bootstrap_create_column(tr, t, "system", "boolean", 1);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to