MonetDB: default - Set client context earlier in execution.

2022-07-05 Thread Lucas Pereira
Changeset: 16df13a4c611 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/16df13a4c611
Modified Files:
monetdb5/mal/mal.c
monetdb5/mal/mal_client.c
monetdb5/mal/mal_embedded.c
monetdb5/mal/mal_import.c
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_private.h
monetdb5/mal/mal_session.c
Branch: default
Log Message:

Set client context earlier in execution.


diffs (300 lines):

diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -68,11 +68,15 @@ getClientContext(void)
 }
 
 /* declared in mal_private.h so only the MAL interpreter core can access it */
-void
+Client
 setClientContext(Client cntxt)
 {
+   Client old = getClientContext();
+
if (pthread_setspecific(tl_client_key, cntxt) != 0)
GDKfatal("Failed to set thread local Client context");
+
+   return old;
 }
 
 #elif defined(Win32)
@@ -103,11 +107,15 @@ getClientContext(void)
 }
 
 /* declared in mal_private.h so only the MAL interpreter core can access it */
-void
+Client
 setClientContext(Client cntxt)
 {
+   Client old = getClientContext();
+
if (TlsSetValue(tl_client_key, cntxt) != 0)
GDKfatal("Failed to set thread local Client context");
+
+   return old;
 }
 
 #else
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -44,6 +44,7 @@
 #include "mal_parser.h"
 #include "mal_namespace.h"
 #include "mal_private.h"
+#include "mal_interpreter.h"
 #include "mal_runtime.h"
 #include "mal_authorize.h"
 #include "mapi_prompt.h"
@@ -206,6 +207,7 @@ MCexitClient(Client c)
c->fdout = NULL;
c->fdin = NULL;
}
+   setClientContext(NULL);
 }
 
 static Client
@@ -296,8 +298,11 @@ MCinitClient(oid user, bstream *fin, str
 
MT_lock_set(&mal_contextLock);
c = MCnewClient();
-   if (c)
+
+   if (c) {
+   assert(NULL == setClientContext(c));
c = MCinitClientRecord(c, user, fin, fout);
+   }
MT_lock_unset(&mal_contextLock);
return c;
 }
diff --git a/monetdb5/mal/mal_embedded.c b/monetdb5/mal/mal_embedded.c
--- a/monetdb5/mal/mal_embedded.c
+++ b/monetdb5/mal/mal_embedded.c
@@ -43,7 +43,7 @@ static bool embeddedinitialized = false;
 str
 malEmbeddedBoot(int workerlimit, int memorylimit, int querytimeout, int 
sessiontimeout, bool with_mapi_server)
 {
-   Client c;
+   Client c, c_old;
str msg = MAL_SUCCEED;
 
if( embeddedinitialized )
@@ -99,7 +99,7 @@ malEmbeddedBoot(int workerlimit, int mem
initParser();
initHeartbeat();
// initResource();
-
+   c_old = setClientContext(NULL); //save context
c = MCinitClient((oid) 0, 0, 0);
if(c == NULL)
throw(MAL, "malEmbeddedBoot", "Failed to initialize client");
@@ -110,31 +110,37 @@ malEmbeddedBoot(int workerlimit, int mem
c->curmodule = c->usermodule = userModule();
if(c->usermodule == NULL) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
throw(MAL, "malEmbeddedBoot", "Failed to initialize client MAL 
module");
}
if ( (msg = defaultScenario(c)) ) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
return msg;
}
if ((msg = MSinitClientPrg(c, "user", "main")) != MAL_SUCCEED) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
return msg;
}
char *modules[5] = { "embedded", "sql", "generator", "udf" };
if ((msg = malIncludeModules(c, modules, 0, !with_mapi_server)) != 
MAL_SUCCEED) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
return msg;
}
pushEndInstruction(c->curprg->def);
msg = chkProgram(c->usermodule, c->curprg->def);
if ( msg != MAL_SUCCEED || (msg= c->curprg->def->errors) != MAL_SUCCEED 
) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
return msg;
}
msg = MALengine(c);
if (msg == MAL_SUCCEED)
embeddedinitialized = true;
MCcloseClient(c);
+   setClientContext(c_old); // restore context
initProfiler();
return msg;
 }
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -274,7 +274,7 @@ malInclude(Client c, const char *name, i
 str
 evalFile(str fname, int listing)
 {
-   Client c;
+   Client c, c_old;
stream *fd;
str filename;
str msg = MAL_SUCCEED;
@@ -295,13 +295,15 @@ evalFile(str fname, int listing)
close_stream(fd);
throw(MAL,"mal.eval",SQLSTAT

MonetDB: Jul2021 - add some more debug output wal logging (or ca...

2022-07-05 Thread Niels Nes
Changeset: f79838acfedc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f79838acfedc
Modified Files:
sql/storage/store.c
Branch: Jul2021
Log Message:

add some more debug output wal logging (or cases unsucceful of log rotating)


diffs (23 lines):

diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2212,6 +2212,7 @@ store_apply_deltas(sqlstore *store)
store_lock(store);
ulng oldest = store_oldest_pending(store);
store_unlock(store);
+   TRC_DEBUG(SQL_STORE, "Store aplly deltas (" ULLFMT ")\n", oldest-1);
if (oldest)
res = store->logger_api.flush(store, oldest-1);
flusher.working = false;
@@ -2330,8 +2331,10 @@ store_manager(sqlstore *store)
MT_sleep_ms(sleeptime);
flusher.countdown_ms -= sleeptime;
MT_lock_set(&store->flush);
-   if (store->logger_api.changes(store) <= 0)
+   if (store->logger_api.changes(store) <= 0) {
+   TRC_DEBUG(SQL_STORE, "Store flusher, no changes\n");
continue;
+   }
if (GDKexiting())
break;
 
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: sql_profiler - merge with default

2022-07-05 Thread Lucas Pereira
Changeset: b0ab3915cdc9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b0ab3915cdc9
Modified Files:
monetdb5/mal/mal_client.c
Branch: sql_profiler
Log Message:

merge with default


diffs (300 lines):

diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -68,11 +68,15 @@ getClientContext(void)
 }
 
 /* declared in mal_private.h so only the MAL interpreter core can access it */
-void
+Client
 setClientContext(Client cntxt)
 {
+   Client old = getClientContext();
+
if (pthread_setspecific(tl_client_key, cntxt) != 0)
GDKfatal("Failed to set thread local Client context");
+
+   return old;
 }
 
 #elif defined(Win32)
@@ -103,11 +107,15 @@ getClientContext(void)
 }
 
 /* declared in mal_private.h so only the MAL interpreter core can access it */
-void
+Client
 setClientContext(Client cntxt)
 {
+   Client old = getClientContext();
+
if (TlsSetValue(tl_client_key, cntxt) != 0)
GDKfatal("Failed to set thread local Client context");
+
+   return old;
 }
 
 #else
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -44,6 +44,7 @@
 #include "mal_parser.h"
 #include "mal_namespace.h"
 #include "mal_private.h"
+#include "mal_interpreter.h"
 #include "mal_runtime.h"
 #include "mal_authorize.h"
 #include "mapi_prompt.h"
@@ -207,6 +208,7 @@ MCexitClient(Client c)
c->fdin = NULL;
}
// TODO PROFILER: EVENT("end of client connection", "client_id", 
TYPE_int, c->id)
+   setClientContext(NULL);
 }
 
 static Client
@@ -298,9 +300,10 @@ MCinitClient(oid user, bstream *fin, str
MT_lock_set(&mal_contextLock);
c = MCnewClient();
// TODO PROFILER: EVENT("start of client connection", "client_id", 
TYPE_int, c->id)
-
-   if (c)
+   if (c) {
+   assert(NULL == setClientContext(c));
c = MCinitClientRecord(c, user, fin, fout);
+   }
MT_lock_unset(&mal_contextLock);
return c;
 }
diff --git a/monetdb5/mal/mal_embedded.c b/monetdb5/mal/mal_embedded.c
--- a/monetdb5/mal/mal_embedded.c
+++ b/monetdb5/mal/mal_embedded.c
@@ -43,7 +43,7 @@ static bool embeddedinitialized = false;
 str
 malEmbeddedBoot(int workerlimit, int memorylimit, int querytimeout, int 
sessiontimeout, bool with_mapi_server)
 {
-   Client c;
+   Client c, c_old;
str msg = MAL_SUCCEED;
 
if( embeddedinitialized )
@@ -99,7 +99,7 @@ malEmbeddedBoot(int workerlimit, int mem
initParser();
initHeartbeat();
// initResource();
-
+   c_old = setClientContext(NULL); //save context
c = MCinitClient((oid) 0, 0, 0);
if(c == NULL)
throw(MAL, "malEmbeddedBoot", "Failed to initialize client");
@@ -110,31 +110,37 @@ malEmbeddedBoot(int workerlimit, int mem
c->curmodule = c->usermodule = userModule();
if(c->usermodule == NULL) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
throw(MAL, "malEmbeddedBoot", "Failed to initialize client MAL 
module");
}
if ( (msg = defaultScenario(c)) ) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
return msg;
}
if ((msg = MSinitClientPrg(c, "user", "main")) != MAL_SUCCEED) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
return msg;
}
char *modules[5] = { "embedded", "sql", "generator", "udf" };
if ((msg = malIncludeModules(c, modules, 0, !with_mapi_server)) != 
MAL_SUCCEED) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
return msg;
}
pushEndInstruction(c->curprg->def);
msg = chkProgram(c->usermodule, c->curprg->def);
if ( msg != MAL_SUCCEED || (msg= c->curprg->def->errors) != MAL_SUCCEED 
) {
MCcloseClient(c);
+   setClientContext(c_old); // restore context
return msg;
}
msg = MALengine(c);
if (msg == MAL_SUCCEED)
embeddedinitialized = true;
MCcloseClient(c);
+   setClientContext(c_old); // restore context
initProfiler();
return msg;
 }
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -274,7 +274,7 @@ malInclude(Client c, const char *name, i
 str
 evalFile(str fname, int listing)
 {
-   Client c;
+   Client c, c_old;
stream *fd;
str filename;
str msg = MAL_SUCCEED;
@@ -295,13 +295,15 @@ evalFile(str fname, int listing)
close_stream(fd);
throw(MAL,"mal.eval",SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
-   c= MCinitClient(MAL_ADMIN, bs

MonetDB: sql_profiler - Start emitting some genericEvents

2022-07-05 Thread Lucas Pereira
Changeset: 124e4e06ff1d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/124e4e06ff1d
Modified Files:
monetdb5/mal/mal_client.c
monetdb5/mal/mal_profiler.c
monetdb5/mal/mal_profiler.h
sql/backends/monet5/sql.c
Branch: sql_profiler
Log Message:

Start emitting some genericEvents


diffs (91 lines):

diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -207,7 +207,12 @@ MCexitClient(Client c)
c->fdout = NULL;
c->fdin = NULL;
}
-   // TODO PROFILER: EVENT("end of client connection", "client_id", 
TYPE_int, c->id)
+
+   genericEvent("End client connection.",
+(struct GenericEvent)
+{ &c->idx, (oid)NULL, NULL, NULL, NULL },
+1);
+
setClientContext(NULL);
 }
 
@@ -299,10 +304,13 @@ MCinitClient(oid user, bstream *fin, str
 
MT_lock_set(&mal_contextLock);
c = MCnewClient();
-   // TODO PROFILER: EVENT("start of client connection", "client_id", 
TYPE_int, c->id)
if (c) {
assert(NULL == setClientContext(c));
c = MCinitClientRecord(c, user, fin, fout);
+   genericEvent("Start client connection.",
+(struct GenericEvent)
+{ &c->idx, (oid)NULL, NULL, NULL, NULL 
},
+0);
}
MT_lock_unset(&mal_contextLock);
return c;
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -199,9 +199,9 @@ prepareGenericEvent(str msg, struct Gene
   ",\"state\":\"%d\""
   "}\n",
   msg ? msg : "",
-  0,
-  (oid)0,
-  e.transaction_id ? *e.transaction_id : 0,
+  e.clientId ? *(e.clientId) : -1,
+  e.tag ? e.tag : (oid)-1,
+  e.transactionId ? *e.transactionId : 0,
   e.query ? e.query : "",
   e.error ? e.error : "",
   state))
diff --git a/monetdb5/mal/mal_profiler.h b/monetdb5/mal/mal_profiler.h
--- a/monetdb5/mal/mal_profiler.h
+++ b/monetdb5/mal/mal_profiler.h
@@ -21,7 +21,9 @@ typedef struct rusage Rusage;
 #endif
 
 struct GenericEvent {
-   int* transaction_id;
+   int* clientId;
+   oid tag;
+   int* transactionId;
str query;
str error;
 };
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -127,17 +127,18 @@ sql_symbol2relation(backend *be, symbol 
lng Tbegin;
int value_based_opt = be->mvc->emode != m_prepare, storage_based_opt;
int profile = be->mvc->emode == m_plan;
-
-   // TODO PROFILER: EVENT("start of SQL compiler", "program_id", 
TYPE_int, log c->curprg->def->tag)
-   genericEvent("SQL compiler",
-(struct GenericEvent){ 0, NULL, NULL},
+   Client c = getClientContext();
+
+   genericEvent("Start SQL compiler",
+(struct GenericEvent)
+{ &(c->idx), c->curprg->def->tag, NULL, NULL, 
NULL },
 0);
 
rel = rel_semantic(query, sym);
 
-   // TODO PROFILER: EVENT("end of SQL compiler;start of relational 
optimizer","program_id", TYPE_int, be->c->curprg->def->tag, "error", TYPE_int, 
rel == NULL)
-   genericEvent("SQL compiler",
-(struct GenericEvent){ 0, NULL, NULL},
+   genericEvent("End SQL compiler",
+(struct GenericEvent)
+{ &(c->idx), c->curprg->def->tag, NULL, NULL, 
rel ? "Good" : "Error" },
 1);
 
storage_based_opt = value_based_opt && rel && !is_ddl(rel->op);
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: Jan2022 - merged with jul2021

2022-07-05 Thread Niels Nes
Changeset: e7b17001fbb3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e7b17001fbb3
Modified Files:
common/stream/stdio_stream.c
common/stream/stream.c
sql/storage/store.c
Branch: Jan2022
Log Message:

merged with jul2021


diffs (65 lines):

diff --git a/common/stream/stdio_stream.c b/common/stream/stdio_stream.c
--- a/common/stream/stdio_stream.c
+++ b/common/stream/stdio_stream.c
@@ -55,7 +55,8 @@ file_write(stream *restrict s, const voi
if (elmsize && cnt) {
size_t rc = fwrite(buf, elmsize, cnt, fp);
 
-   if (!rc && ferror(fp)) {
+   if (rc != cnt) {
+   // only happens if fwrite encountered an error.
mnstr_set_error_errno(s, MNSTR_WRITE_ERROR, "write 
error");
return -1;
}
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -72,11 +72,25 @@ static struct tl_error_buf *get_tl_error
 
 static pthread_key_t tl_error_key;
 
+static void
+clear_main_tl_error_buf(void)
+{
+   void *p = pthread_getspecific(tl_error_key);
+   if (p != NULL) {
+   pthread_setspecific(tl_error_key, NULL);
+   free(p);
+   }
+}
+
 static int
 tl_error_init(void)
 {
if (pthread_key_create(&tl_error_key, free) != 0)
return -1;
+   // Turns out the destructor registered with pthread_key_create() does 
not
+   // always run for the main thread. This atexit hook clears the main 
thread's
+   // error buffer to avoid this being reported as a memory leak.
+   atexit(clear_main_tl_error_buf);
return 0;
 }
 
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2229,6 +2229,7 @@ store_apply_deltas(sqlstore *store)
store_lock(store);
ulng oldest = store_oldest_pending(store);
store_unlock(store);
+   TRC_DEBUG(SQL_STORE, "Store aplly deltas (" ULLFMT ")\n", oldest-1);
if (oldest)
res = store->logger_api.flush(store, oldest-1);
flusher.working = false;
@@ -2347,8 +2348,10 @@ store_manager(sqlstore *store)
MT_sleep_ms(sleeptime);
flusher.countdown_ms -= sleeptime;
MT_lock_set(&store->flush);
-   if (store->logger_api.changes(store) <= 0)
+   if (store->logger_api.changes(store) <= 0) {
+   TRC_DEBUG(SQL_STORE, "Store flusher, no changes\n");
continue;
+   }
if (GDKexiting())
break;
 
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: default - small cleanup

2022-07-05 Thread Niels Nes
Changeset: 8c959b97dcd9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8c959b97dcd9
Modified Files:
sql/backends/monet5/CMakeLists.txt
sql/backends/monet5/UDF/capi/capi.c
sql/backends/monet5/rel_bin.c
Branch: default
Log Message:

small cleanup


diffs (64 lines):

diff --git a/sql/backends/monet5/CMakeLists.txt 
b/sql/backends/monet5/CMakeLists.txt
--- a/sql/backends/monet5/CMakeLists.txt
+++ b/sql/backends/monet5/CMakeLists.txt
@@ -32,6 +32,7 @@ set(sql_public_headers
   $
   $
   $
+  $
   $
   $
   $
diff --git a/sql/backends/monet5/UDF/capi/capi.c 
b/sql/backends/monet5/UDF/capi/capi.c
--- a/sql/backends/monet5/UDF/capi/capi.c
+++ b/sql/backends/monet5/UDF/capi/capi.c
@@ -1950,8 +1950,6 @@ static mel_func capi_init_funcs[] = {
  pattern("capi", "subeval_aggr", CUDFevalAggr, false, "grouped aggregates 
through CUDF", args(1,5, 
varargany("",0),arg("fptr",ptr),arg("cpp",bit),arg("expr",str),varargany("arg",0))),
  pattern("capi", "eval_aggr", CUDFevalAggr, false, "grouped aggregates through 
CUDF", args(1,5, 
varargany("",0),arg("fptr",ptr),arg("cpp",bit),arg("expr",str),varargany("arg",0))),
  pattern("batcapi", "eval", CUDFevalStd, false, "Execute a simple CUDF script 
value", args(1,5, 
varargany("",0),arg("fptr",ptr),arg("cpp",bit),arg("expr",str),varargany("arg",0))),
- pattern("batcapi", "subeval_aggr", CUDFevalAggr, false, "grouped aggregates 
through CUDF", args(1,5, 
varargany("",0),arg("fptr",ptr),arg("cpp",bit),arg("expr",str),varargany("arg",0))),
- pattern("batcapi", "eval_aggr", CUDFevalAggr, false, "grouped aggregates 
through CUDF", args(1,5, 
varargany("",0),arg("fptr",ptr),arg("cpp",bit),arg("expr",str),varargany("arg",0))),
  { .imp=NULL }
 };
 #include "mal_import.h"
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -4104,7 +4104,7 @@ insert_check_fkey(backend *be, list *ins
 
/* foreach column add predicate */
stmt_add_column_predicate(be, c->c);
-   
+
 // foreach column aggregate the nonil (literally 'null') values.
 // mind that null values are valid fkeys with undefined value so
 // we won't have an entry for them in the idx_inserts col
@@ -4114,20 +4114,20 @@ insert_check_fkey(backend *be, list *ins
 
if (!s && pin && list_length(pin->op4.lval))
s = pin->op4.lval->h->data;
-
+
 // we want to make sure that the data column(s) has the same number
 // of (nonil) rows as the index column. if that is **not** the case
-// then we are obviously dealing with an invalid foreign key 
+// then we are obviously dealing with an invalid foreign key
if (s->key && s->nrcols == 0) {
-   s = stmt_binop(be, 
-   stmt_aggr(be, idx_inserts, NULL, NULL, cnt, 1, 1, 1), 
-   stmt_aggr(be, const_column(be, nonil_rows), NULL, NULL, 
cnt, 1, 1, 1), 
+   s = stmt_binop(be,
+   stmt_aggr(be, idx_inserts, NULL, NULL, cnt, 1, 1, 1),
+   stmt_aggr(be, const_column(be, nonil_rows), NULL, NULL, 
cnt, 1, 1, 1),
NULL, ne);
} else {
/* relThetaJoin.notNull.count <> inserts[notNull(col1) && ... 
&& notNull(colN)].count */
-   s = stmt_binop(be, 
-   stmt_aggr(be, idx_inserts, NULL, NULL, cnt, 1, 1, 1), 
-   stmt_aggr(be, column(be, nonil_rows), NULL, NULL, cnt, 
1, 1, 1), 
+   s = stmt_binop(be,
+   stmt_aggr(be, idx_inserts, NULL, NULL, cnt, 1, 1, 1),
+   stmt_aggr(be, column(be, nonil_rows), NULL, NULL, cnt, 
1, 1, 1),
NULL, ne);
}
 
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: default - merged with jan2022

2022-07-05 Thread Niels Nes
Changeset: ec881cc10860 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ec881cc10860
Modified Files:
sql/storage/store.c
Branch: default
Log Message:

merged with jan2022


diffs (69 lines):

diff --git a/common/stream/stdio_stream.c b/common/stream/stdio_stream.c
--- a/common/stream/stdio_stream.c
+++ b/common/stream/stdio_stream.c
@@ -55,7 +55,8 @@ file_write(stream *restrict s, const voi
if (elmsize && cnt) {
size_t rc = fwrite(buf, elmsize, cnt, fp);
 
-   if (!rc && ferror(fp)) {
+   if (rc != cnt) {
+   // only happens if fwrite encountered an error.
mnstr_set_error_errno(s, MNSTR_WRITE_ERROR, "write 
error");
return -1;
}
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -72,11 +72,25 @@ static struct tl_error_buf *get_tl_error
 
 static pthread_key_t tl_error_key;
 
+static void
+clear_main_tl_error_buf(void)
+{
+   void *p = pthread_getspecific(tl_error_key);
+   if (p != NULL) {
+   pthread_setspecific(tl_error_key, NULL);
+   free(p);
+   }
+}
+
 static int
 tl_error_init(void)
 {
if (pthread_key_create(&tl_error_key, free) != 0)
return -1;
+   // Turns out the destructor registered with pthread_key_create() does 
not
+   // always run for the main thread. This atexit hook clears the main 
thread's
+   // error buffer to avoid this being reported as a memory leak.
+   atexit(clear_main_tl_error_buf);
return 0;
 }
 
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2101,7 +2101,6 @@ store_init(int debug, store_type store_t
for(int i = 0; icolumn_locks[i], "sqlstore_column");
 
-   MT_lock_set(&store->flush);
MT_lock_set(&store->lock);
 
/* initialize empty bats */
@@ -2208,6 +2207,7 @@ store_apply_deltas(sqlstore *store)
store_lock(store);
ulng oldest = store_oldest_pending(store);
store_unlock(store);
+   TRC_DEBUG(SQL_STORE, "Store aplly deltas (" ULLFMT ")\n", oldest-1);
if (oldest)
res = store->logger_api.flush(store, oldest-1);
return res;
@@ -2322,6 +2322,7 @@ store_manager(sqlstore *store)
MT_lock_set(&store->commit);
MT_lock_set(&store->flush);
if (store->logger_api.changes(store) <= 0) {
+   TRC_DEBUG(SQL_STORE, "Store flusher, no changes\n");
MT_lock_unset(&store->commit);
continue;
}
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: default - Misspelled WIN32

2022-07-05 Thread Joeri van Ruth
Changeset: 3e6b3ea59c8b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3e6b3ea59c8b
Modified Files:
monetdb5/mal/mal.c
Branch: default
Log Message:

Misspelled WIN32


diffs (12 lines):

diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -79,7 +79,7 @@ setClientContext(Client cntxt)
return old;
 }
 
-#elif defined(Win32)
+#elif defined(WIN32)
 
 static DWORD tl_client_key = 0;
 
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org