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; i<NR_COLUMN_LOCKS; i++)
                MT_lock_init(&store->column_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

Reply via email to