Changeset: 2b1d1822daa3 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2b1d1822daa3 Modified Files: sql/backends/monet5/sql_scenario.c sql/server/sql_mvc.c sql/server/sql_mvc.h sql/storage/store.c Branch: nospare Log Message:
less globals in the server directory. diffs (truncated from 599 to 300 lines): diff --git a/sql/backends/monet5/sql_scenario.c b/sql/backends/monet5/sql_scenario.c --- a/sql/backends/monet5/sql_scenario.c +++ b/sql/backends/monet5/sql_scenario.c @@ -61,8 +61,7 @@ sql_register(const char *name, const uns sql_modules++; } -static int SQLinitialized = 0; -static int SQLnewcatalog = 0; +static sql_store SQLstore = NULL; int SQLdebug = 0; static const char *sqlinit = NULL; static MT_Lock sql_contextLock = MT_LOCK_INITIALIZER(sql_contextLock); @@ -180,9 +179,9 @@ SQLexit(Client c) { (void) c; /* not used */ MT_lock_set(&sql_contextLock); - if (SQLinitialized) { - mvc_exit(); - SQLinitialized = FALSE; + if (SQLstore) { + mvc_exit(SQLstore); + SQLstore = NULL; } MT_lock_unset(&sql_contextLock); return MAL_SUCCEED; @@ -231,7 +230,7 @@ SQLprepareClient(Client c, int login) msg = createException(SQL,"sql.initClient", SQLSTATE(HY013) MAL_MALLOC_FAIL); goto bailout; } - m = mvc_create(sa, c->idx, SQLdebug, c->fdin, c->fdout); + m = mvc_create(SQLstore, sa, c->idx, SQLdebug, c->fdin, c->fdout); if (m == NULL) { msg = createException(SQL,"sql.initClient", SQLSTATE(HY013) MAL_MALLOC_FAIL); goto bailout; @@ -344,7 +343,7 @@ SQLinit(Client c) MT_lock_set(&sql_contextLock); - if (SQLinitialized) { + if (SQLstore) { MT_lock_unset(&sql_contextLock); return MAL_SUCCEED; } @@ -366,11 +365,10 @@ SQLinit(Client c) MT_lock_unset(&sql_contextLock); throw(SQL,"sql.init",SQLSTATE(HY013) MAL_MALLOC_FAIL); } - if ((SQLnewcatalog = mvc_init(sa, SQLdebug, GDKinmemory(0) ? store_mem : store_bat, readonly, single_user)) < 0) { + if ((SQLstore = mvc_init(sa, SQLdebug, GDKinmemory(0) ? store_mem : store_bat, readonly, single_user)) == NULL) { MT_lock_unset(&sql_contextLock); throw(SQL, "SQLinit", SQLSTATE(42000) "Catalogue initialization failed"); } - SQLinitialized = TRUE; sqlinit = GDKgetenv("sqlinit"); if (sqlinit) { /* add sqlinit to the fdin stack */ buffer *b = (buffer *) GDKmalloc(sizeof(buffer)); @@ -413,17 +411,18 @@ SQLinit(Client c) be = c->sqlcontext; m = be->mvc; /* initialize the database with predefined SQL functions */ - if (SQLnewcatalog == 0) { + sqlstore *store = SQLstore; + if (store->first == 0) { /* check whether table sys.systemfunctions exists: if * it doesn't, this is probably a restart of the * server after an incomplete initialization */ sql_schema *s = mvc_bind_schema(m, "sys"); sql_table *t = s ? mvc_bind_table(m, s, "systemfunctions") : NULL; if (t == NULL) - SQLnewcatalog = 1; + store->first = 1; } - if (SQLnewcatalog > 0) { - SQLnewcatalog = 0; + if (store->first > 0) { + store->first = 0; maybeupgrade = 0; for (int i = 0; i < sql_modules && !msg; i++) { @@ -506,11 +505,11 @@ SQLinit(Client c) if (GDKinmemory(0)) return MAL_SUCCEED; - if ((sqllogthread = THRcreate((void (*)(void *)) mvc_logmanager, NULL, MT_THR_DETACHED, "logmanager")) == 0) { + if ((sqllogthread = THRcreate((void (*)(void *)) mvc_logmanager, SQLstore, MT_THR_DETACHED, "logmanager")) == 0) { throw(SQL, "SQLinit", SQLSTATE(42000) "Starting log manager failed"); } if (!(SQLdebug&1024)) { - if ((idlethread = THRcreate((void (*)(void *)) mvc_idlemanager, NULL, MT_THR_DETACHED, "idlemanager")) == 0) { + if ((idlethread = THRcreate((void (*)(void *)) mvc_idlemanager, SQLstore, MT_THR_DETACHED, "idlemanager")) == 0) { throw(SQL, "SQLinit", SQLSTATE(42000) "Starting idle manager failed"); } } @@ -600,7 +599,7 @@ SQLinitClient(Client c) str msg = MAL_SUCCEED; MT_lock_set(&sql_contextLock); - if (SQLinitialized == 0) { + if (!SQLstore) { MT_lock_unset(&sql_contextLock); throw(SQL, "SQLinitClient", SQLSTATE(42000) "Catalogue not available"); } @@ -638,7 +637,7 @@ SQLexitClient(Client c) str err; MT_lock_set(&sql_contextLock); - if (SQLinitialized == FALSE) { + if (!SQLstore) { MT_lock_unset(&sql_contextLock); throw(SQL, "SQLexitClient", SQLSTATE(42000) "Catalogue not available"); } @@ -759,17 +758,8 @@ SQLreader(Client c) int language = -1; mvc *m = NULL; bool blocked = isa_block_stream(in->s); - int isSQLinitialized; - MT_lock_set(&sql_contextLock); - isSQLinitialized = SQLinitialized; - MT_lock_unset(&sql_contextLock); - - if (isSQLinitialized == FALSE) { - c->mode = FINISHCLIENT; - return MAL_SUCCEED; - } - if (!be || c->mode <= FINISHCLIENT) { + if (!SQLstore || !be || c->mode <= FINISHCLIENT) { c->mode = FINISHCLIENT; return MAL_SUCCEED; } diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c --- a/sql/server/sql_mvc.c +++ b/sql/server/sql_mvc.c @@ -86,7 +86,7 @@ mvc_init_create_view(mvc *m, sql_schema TRC_CRITICAL(SQL_TRANS, \ "Initialization: %s\n", output); \ freeException(output); \ - return -1; \ + return NULL; \ } \ } while (0) @@ -98,12 +98,10 @@ struct view_t { sqlid newid; }; -static sql_allocator *store_allocator = NULL; -static sqlstore *store = NULL; - static void mvc_fix_depend(mvc *m, sql_column *depids, struct view_t *v, int n) { + sqlstore *store = m->store; oid rid; rids *rs; @@ -118,31 +116,31 @@ mvc_fix_depend(mvc *m, sql_column *depid } } -int +sql_store mvc_init(sql_allocator *pa, int debug, store_type store_tpe, int ro, int su) { + sqlstore *store = NULL; sql_schema *s; sql_table *t; mvc *m; str msg; - store_allocator = pa; TRC_DEBUG(SQL_TRANS, "Initialization\n"); keyword_init(); if(scanner_init_keywords() != 0) { TRC_CRITICAL(SQL_TRANS, "Malloc failure\n"); - return -1; + return NULL; } if ((store = store_init(pa, debug, store_tpe, ro, su)) == NULL) { TRC_CRITICAL(SQL_TRANS, "Unable to create system tables\n"); - return -1; + return NULL; } - m = mvc_create(pa, 0, 0, NULL, NULL); + m = mvc_create((sql_store)store, pa, 0, 0, NULL, NULL); if (!m) { TRC_CRITICAL(SQL_TRANS, "Malloc failure\n"); - return -1; + return NULL; } assert(m->sa == NULL); @@ -150,7 +148,7 @@ mvc_init(sql_allocator *pa, int debug, s if (!m->sa) { mvc_destroy(m); TRC_CRITICAL(SQL_TRANS, "Malloc failure\n"); - return -1; + return NULL; } if (store->first || store->catalog_version) { @@ -262,7 +260,7 @@ mvc_init(sql_allocator *pa, int debug, s if (mvc_trans(m) < 0) { mvc_destroy(m); TRC_CRITICAL(SQL_TRANS, "Failed to start transaction\n"); - return -1; + return NULL; } s = m->session->schema = mvc_bind_schema(m, "sys"); assert(m->session->schema != NULL); @@ -276,7 +274,7 @@ mvc_init(sql_allocator *pa, int debug, s if (!t) { mvc_destroy(m); TRC_CRITICAL(SQL_TRANS, "Failed to create 'tables' view\n"); - return -1; + return NULL; } for (int i = 0; i < 9; i++) { @@ -288,7 +286,7 @@ mvc_init(sql_allocator *pa, int debug, s mvc_destroy(m); TRC_CRITICAL(SQL_TRANS, "Initialization: creation of sys.tables column %s failed\n", tview[i].name); - return -1; + return NULL; } tview[i].newid = col->base.id; } @@ -311,7 +309,7 @@ mvc_init(sql_allocator *pa, int debug, s if (!t) { mvc_destroy(m); TRC_CRITICAL(SQL_TRANS, "Failed to create 'columns' view\n"); - return -1; + return NULL; } for (int i = 0; i < 10; i++) { sql_column *col = mvc_create_column_(m, t, @@ -322,7 +320,7 @@ mvc_init(sql_allocator *pa, int debug, s mvc_destroy(m); TRC_CRITICAL(SQL_TRANS, "Initialization: creation of sys.tables column %s failed\n", cview[i].name); - return -1; + return NULL; } cview[i].newid = col->base.id; } @@ -348,14 +346,14 @@ mvc_init(sql_allocator *pa, int debug, s if ((msg = mvc_commit(m, 0, NULL, false)) != MAL_SUCCEED) { TRC_CRITICAL(SQL_TRANS, "Unable to commit system tables: %s\n", (msg + 6)); freeException(msg); - return -1; + return NULL; } } if (mvc_trans(m) < 0) { mvc_destroy(m); TRC_CRITICAL(SQL_TRANS, "Failed to start transaction\n"); - return -1; + return NULL; } //as the sql_parser is not yet initialized in the storage, we determine the sql type of the sql_parts here @@ -369,7 +367,7 @@ mvc_init(sql_allocator *pa, int debug, s if ((err = initialize_sql_parts(m, tt)) != NULL) { TRC_CRITICAL(SQL_TRANS, "Unable to start partitioned table: %s.%s: %s\n", ss->base.name, tt->base.name, err); freeException(err); - return -1; + return NULL; } } } @@ -379,30 +377,29 @@ mvc_init(sql_allocator *pa, int debug, s if ((msg = mvc_commit(m, 0, NULL, false)) != MAL_SUCCEED) { TRC_CRITICAL(SQL_TRANS, "Unable to commit system tables: %s\n", (msg + 6)); freeException(msg); - return -1; + return NULL; } mvc_destroy(m); - return store->first; + return store; } void -mvc_exit(void) +mvc_exit(sql_store store) { TRC_DEBUG(SQL_TRANS, "MVC exit\n"); store_exit(store); keyword_exit(); - sa_destroy(store_allocator); } void -mvc_logmanager(void) _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list