Changeset: 02c1a00c83ec for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/02c1a00c83ec
Modified Files:
        gdk/gdk_logger.c
        gdk/gdk_select.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_runtime.c
        monetdb5/optimizer/opt_mitosis.c
        sql/backends/monet5/sql_execute.c
        sql/backends/monet5/sql_scenario.c
        sql/storage/bat/bat_storage.c
        sql/storage/store.c
Branch: default
Log Message:

Merge with Sep2022 branch.


diffs (truncated from 408 to 300 lines):

diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1615,11 +1615,12 @@ cleanup_and_swap(logger *lg, int *r, con
        return rcnt;
 }
 
+/* this function is called with log_lock() held; it releases the lock
+ * before returning */
 static gdk_return
 bm_subcommit(logger *lg)
 {
        BUN p, q;
-       log_lock(lg);
        BAT *catalog_bid = lg->catalog_bid;
        BAT *catalog_id = lg->catalog_id;
        BAT *dcatalog = lg->dcatalog;
@@ -1936,6 +1937,8 @@ log_load(int debug, const char *fn, cons
                BBPretain(lg->catalog_id->batCacheid);
                BBPretain(lg->dcatalog->batCacheid);
 
+               log_lock(lg);
+               /* bm_subcommit releases the lock */
                if (bm_subcommit(lg) != GDK_SUCCEED) {
                        /* cannot commit catalog, so remove log */
                        MT_remove(filename);
@@ -3081,7 +3084,7 @@ bm_commit(logger *lg)
                        fprintf(stderr, "#bm_commit: create %d (%d)\n",
                                bid, BBP_lrefs(bid));
        }
-       log_unlock(lg);
+       /* bm_subcommit releases the lock */
        return bm_subcommit(lg);
 }
 
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -1722,7 +1722,7 @@ BATselect(BAT *b, BAT *s, const void *tl
                if ((oidxh = b->torderidx) != NULL)
                        HEAPincref(oidxh);
                MT_lock_unset(&b->batIdxLock);
-               if (oidxh == NULL && pb) {
+               if (oidxh == NULL && pb != NULL) {
                        (void) BATcheckorderidx(pb);
                        MT_lock_set(&pb->batIdxLock);
                        if ((oidxh = pb->torderidx) != NULL) {
@@ -1944,7 +1944,7 @@ BATselect(BAT *b, BAT *s, const void *tl
                } else if (b->thash->nunique == bi.count)
                        estimate = 1;
        }
-       if (estimate == BUN_NONE && (bi.key || (pb != NULL && pb->tkey))) {
+       if (estimate == BUN_NONE && (bi.key || (pb != NULL && pbi.key))) {
                /* exact result size in special cases */
                if (equi) {
                        estimate = 1;
@@ -2051,9 +2051,7 @@ BATselect(BAT *b, BAT *s, const void *tl
                if (!equi &&
                    /* DISABLES CODE */ (0) && imprintable(bi.type) &&
                    (!bi.transient ||
-                    (parent != 0 &&
-                     pb != NULL &&
-                     !pbi.transient)) &&
+                    (pb != NULL && !pbi.transient)) &&
                    BATimprints(b) == GDK_SUCCEED) {
                        if (pb != NULL) {
                                MT_lock_set(&pb->batIdxLock);
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
@@ -557,9 +557,11 @@ MCactiveClients(void)
        int active = 0;
        Client cntxt = mal_clients;
 
+       MT_lock_set(&mal_contextLock);
        for(cntxt = mal_clients;  cntxt<mal_clients+MAL_MAXCLIENTS; cntxt++){
                active += (cntxt->idle == 0 && cntxt->mode == RUNCLIENT);
        }
+       MT_lock_unset(&mal_contextLock);
        return active;
 }
 
@@ -574,14 +576,19 @@ MCmemoryClaim(void)
 
        Client cntxt = mal_clients;
 
-       for(cntxt = mal_clients;  cntxt<mal_clients+MAL_MAXCLIENTS; cntxt++)
+       MT_lock_set(&mal_contextLock);
+       for(cntxt = mal_clients;  cntxt<mal_clients+MAL_MAXCLIENTS; cntxt++) {
                if( cntxt->idle == 0 && cntxt->mode == RUNCLIENT){
                        if(cntxt->memorylimit){
                                claim += cntxt->memorylimit;
                                active ++;
-                       } else
+                       } else {
+                               MT_lock_unset(&mal_contextLock);
                                return GDK_mem_maxsize;
+                       }
                }
+       }
+       MT_lock_unset(&mal_contextLock);
        if(active == 0 ||  claim  * LL_CONSTANT(1048576) >= GDK_mem_maxsize)
                return GDK_mem_maxsize;
        return claim * LL_CONSTANT(1048576);
diff --git a/monetdb5/mal/mal_runtime.c b/monetdb5/mal/mal_runtime.c
--- a/monetdb5/mal/mal_runtime.c
+++ b/monetdb5/mal/mal_runtime.c
@@ -228,7 +228,6 @@ runtimeProfileInit(Client cntxt, MalBlkP
        }
 
        // add new invocation
-       cntxt->idle = 0;
        for (i = 0; i < qsize; i++) {
                size_t j = qlast;
                if (++qlast >= qsize)
@@ -259,6 +258,9 @@ runtimeProfileInit(Client cntxt, MalBlkP
                }
        }
        MT_lock_unset(&mal_delayLock);
+       MT_lock_set(&mal_contextLock);
+       cntxt->idle = 0;
+       MT_lock_unset(&mal_contextLock);
 }
 
 /*
@@ -290,7 +292,10 @@ runtimeProfileFinish(Client cntxt, MalBl
                        QRYqueue[i].ticks = GDKusec() - QRYqueue[i].ticks;
                        updateUserStats(cntxt, mb, QRYqueue[i].ticks, 
QRYqueue[i].start, QRYqueue[i].finished, QRYqueue[i].query);
                        // assume that the user is now idle
+                       MT_lock_unset(&mal_delayLock);
+                       MT_lock_set(&mal_contextLock);
                        cntxt->idle = time(0);
+                       MT_lock_unset(&mal_contextLock);
                        found = true;
                        break;
                }
@@ -313,9 +318,9 @@ runtimeProfileFinish(Client cntxt, MalBl
                                }
                        }
                }
+               MT_lock_unset(&mal_delayLock);
        }
 
-       MT_lock_unset(&mal_delayLock);
 }
 
 /* Used by mal_reset to do the grand final clean up of this area before 
MonetDB exits */
diff --git a/monetdb5/optimizer/opt_mitosis.c b/monetdb5/optimizer/opt_mitosis.c
--- a/monetdb5/optimizer/opt_mitosis.c
+++ b/monetdb5/optimizer/opt_mitosis.c
@@ -152,7 +152,9 @@ OPTmitosisImplementation(Client cntxt, M
         * Take into account the number of client connections,
         * because all user together are responsible for resource contentions
         */
+       MT_lock_set(&mal_contextLock);
        cntxt->idle = 0; // this one is definitely not idle
+       MT_lock_unset(&mal_contextLock);
 
 /* This code was used to experiment with block sizes, mis-using the 
memorylimit  variable
        if (cntxt->memorylimit){
diff --git a/sql/backends/monet5/sql_execute.c 
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -336,22 +336,28 @@ SQLrun(Client c, mvc *m)
                if( m->emod & mod_trace){
                        if((msg = SQLsetTrace(c,mb)) == MAL_SUCCEED) {
                                setVariableScope(mb);
+                               MT_lock_set(&mal_contextLock);
                                c->idle = 0;
                                c->lastcmd = time(0);
+                               MT_lock_unset(&mal_contextLock);
                                msg = runMAL(c, mb, 0, 0);
                                stopTrace(c);
                        }
                } else {
                        setVariableScope(mb);
+                       MT_lock_set(&mal_contextLock);
                        c->idle = 0;
                        c->lastcmd = time(0);
+                       MT_lock_unset(&mal_contextLock);
                        msg = runMAL(c, mb, 0, 0);
                }
                resetMalBlk(mb);
        }
        /* after the query has been finished we enter the idle state */
+       MT_lock_set(&mal_contextLock);
        c->idle = time(0);
        c->lastcmd = 0;
+       MT_lock_unset(&mal_contextLock);
        MT_thread_setworking(NULL);
        return msg;
 }
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
@@ -860,8 +860,11 @@ SQLreader(Client c)
                                break;
                        commit_done = true;
                }
-               if (m->session->tr && m->session->tr->active)
+               if (m->session->tr && m->session->tr->active) {
+                       MT_lock_set(&mal_contextLock);
                        c->idle = 0;
+                       MT_lock_unset(&mal_contextLock);
+               }
 
                if (go && in->pos >= in->len) {
                        ssize_t rd;
@@ -884,10 +887,12 @@ SQLreader(Client c)
                                        if (msg)
                                                break;
                                        commit_done = true;
+                                       MT_lock_set(&mal_contextLock);
                                        if (c->idle == 0 && (m->session->tr == 
NULL || !m->session->tr->active)) {
                                                /* now the session is idle */
                                                c->idle = time(0);
                                        }
+                                       MT_lock_unset(&mal_contextLock);
                                }
 
                                if (go && ((!blocked && mnstr_write(c->fdout, 
c->prompt, c->promptlength, 1) != 1) || mnstr_flush(c->fdout, 
MNSTR_FLUSH_DATA))) {
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -305,10 +305,11 @@ segments2cs(sql_trans *tr, segments *seg
        b->tkey = false;
        b->tnokey[0] = 0;
        b->tnokey[1] = 0;
+       b->theap->dirty = true;
+       BUN cnt = BATcount(b);
        MT_lock_unset(&b->theaplock);
 
        uint32_t *restrict dst;
-       BUN cnt = BATcount(b);
        MT_rwlock_wrlock(&b->thashlock);
        for (; s ; s=s->next) {
                if (s->start >= nr)
@@ -344,9 +345,6 @@ segments2cs(sql_trans *tr, segments *seg
                                }
                                assert(lnr==0);
                        }
-                       MT_lock_set(&b->theaplock);
-                       b->theap->dirty = true;
-                       MT_lock_unset(&b->theaplock);
                        size_t lnr = s->end-s->start;
                        size_t pos = s->start;
                        dst = (uint32_t *) Tloc(b, 0) + (pos/32);
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2206,6 +2206,18 @@ store_exit(sqlstore *store)
        MT_lock_unset(&store->flush);
        MT_lock_unset(&store->lock);
        sa_destroy(sa);
+       ATOMIC_DESTROY(&store->nr_active);
+       ATOMIC_DESTROY(&store->lastactive);
+       ATOMIC_DESTROY(&store->timestamp);
+       ATOMIC_DESTROY(&store->transaction);
+       ATOMIC_DESTROY(&store->function_counter);
+       MT_lock_destroy(&store->lock);
+       MT_lock_destroy(&store->commit);
+       MT_lock_destroy(&store->flush);
+       for(int i = 0; i<NR_TABLE_LOCKS; i++)
+               MT_lock_destroy(&store->table_locks[i]);
+       for(int i = 0; i<NR_COLUMN_LOCKS; i++)
+               MT_lock_destroy(&store->column_locks[i]);
        _DELETE(store);
 }
 
diff --git a/sql/test/merge-partitions/Tests/All 
b/sql/test/merge-partitions/Tests/All
--- a/sql/test/merge-partitions/Tests/All
+++ b/sql/test/merge-partitions/Tests/All
@@ -32,3 +32,4 @@ mergepart30
 mergepart31
 mergepart32
 mergepart33
+mergepart34
diff --git a/sql/test/merge-partitions/Tests/mergepart34.test 
b/sql/test/merge-partitions/Tests/mergepart34.test
new file mode 100644
--- /dev/null
+++ b/sql/test/merge-partitions/Tests/mergepart34.test
@@ -0,0 +1,126 @@
+
+statement ok
+CREATE MERGE TABLE table1 (a int) PARTITION BY RANGE ON (a)
+
+statement ok
+CREATE MERGE TABLE table2 (a int); 
+
+statement ok
+CREATE TABLE another1 (a int)
+
+statement ok
+CREATE TABLE another2 (a int)
+
+statement ok
+CREATE TABLE another3 (a int)
+
+statement ok
+ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM 10 TO 10
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to