MonetDB: Dec2023 - Delay calling BBPretain until after bat_itera...

2024-04-29 Thread Sjoerd Mullender via checkin-list
Changeset: 84f66ba47ea2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/84f66ba47ea2
Modified Files:
gdk/gdk_bat.c
Branch: Dec2023
Log Message:

Delay calling BBPretain until after bat_iterator_end.
This fixes bug #7504.


diffs (53 lines):

diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -2575,6 +2575,7 @@ BATmode(BAT *b, bool transient)
 
BATiter bi = bat_iterator(b);
bool mustrelease = false;
+   bool mustretain = false;
bat bid = b->batCacheid;
 
if (transient != bi.transient) {
@@ -2591,16 +2592,20 @@ BATmode(BAT *b, bool transient)
}
}
 
-   /* persistent BATs get a logical reference */
+   /* we need to delay the calls to BBPretain and
+* BBPrelease until after we have released our reference
+* to the heaps (i.e. until after bat_iterator_end),
+* because in either case, BBPfree can be called (either
+* directly here or in BBPtrim) which waits for the heap
+* reference to come down.  BBPretain calls incref which
+* waits until the trim that is waiting for us is done,
+* so that causes deadlock, and BBPrelease can call
+* BBPfree which causes deadlock with a single thread */
if (!transient) {
-   BBPretain(bid);
+   /* persistent BATs get a logical reference */
+   mustretain = true;
} else if (!bi.transient) {
-   /* we need to delay the release because if there
-* is no fix and the bat is loaded, BBPrelease
-* can call BBPfree which calls BATfree which
-* may hang while waiting for the heap reference
-* that we have because of the BAT iterator to
-* come down, in other words, deadlock */
+   /* transient BATs loose their logical reference */
mustrelease = true;
}
MT_lock_set((bid));
@@ -2632,8 +2637,10 @@ BATmode(BAT *b, bool transient)
MT_lock_unset((bid));
}
bat_iterator_end();
-   /* release after bat_iterator_end because of refs to heaps */
-   if (mustrelease)
+   /* retain/release after bat_iterator_end because of refs to heaps */
+   if (mustretain)
+   BBPretain(bid);
+   else if (mustrelease)
BBPrelease(bid);
return GDK_SUCCEED;
 }
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: Dec2023 - Add an assert.

2024-04-29 Thread Sjoerd Mullender via checkin-list
Changeset: d14686f2294e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d14686f2294e
Modified Files:
gdk/gdk_bbp.c
Branch: Dec2023
Log Message:

Add an assert.


diffs (11 lines):

diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -4117,6 +4117,7 @@ BBPsync(int cnt, bat *restrict subcommit
/* move any tail/theap files we find for this bat that
 * are in the BACKUP directory to the SUBCOMMIT
 * directory */
+   assert(b->ttype > 0); /* no unknown types allowed */
char fname[16]; /* plenty big enough */
if (snprintf(fname, sizeof(fname), "%o", (unsigned) 
bid) < 16) {
/* the snprintf never fails, any of the
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: default - Merge with Dec2023 branch.

2024-04-29 Thread Sjoerd Mullender via checkin-list
Changeset: 6a013fec3b56 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/6a013fec3b56
Modified Files:
gdk/gdk_bbp.c
sql/backends/monet5/sql_scenario.c
sql/backends/monet5/sql_user.c
sql/include/sql_catalog.h
sql/storage/bat/bat_storage.c
sql/storage/store.c
Branch: default
Log Message:

Merge with Dec2023 branch.


diffs (237 lines):

diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1711,6 +1711,9 @@ BBPjson_upgrade(json_storage_conversion 
const char *nme;
 
nme = ATOMunknown_name(b->ttype);
+   int tt = ATOMindex(nme);
+   if (tt >= 0)
+   b->ttype = tt;
if (strcmp(nme, "json") != 0)
continue;
} else if (b->ttype != JSON_type) {
@@ -4065,34 +4068,41 @@ BBPsync(int cnt, bat *restrict subcommit
if (lock)
MT_lock_set((bid));
}
-   if (subcommit) {
+   BAT *b = BBP_desc(bid);
+   if (subcommit && b->ttype != TYPE_void) {
/* move any tail/theap files we find for this bat that
 * are in the BACKUP directory to the SUBCOMMIT
 * directory */
char fname[16]; /* plenty big enough */
-   if (snprintf(fname, sizeof(fname), "%o", i) < 16) {
+   if (snprintf(fname, sizeof(fname), "%o", (unsigned) 
bid) < 16) {
/* the snprintf never fails, any of the
 * below may fail */
-   if (GDKmove(0, BAKDIR, fname, "tail", SUBDIR, 
fname, "tail", false) == GDK_SUCCEED)
-   TRC_DEBUG(BAT_, "moved %s.tail from %s 
to %s\n",
+   uint8_t stpe = ATOMstorage(b->ttype);
+   if ((b->ttype != TYPE_str || b->twidth >= 8) &&
+   GDKmove(0, BAKDIR, fname, "tail", SUBDIR, 
fname, "tail", false) == GDK_SUCCEED)
+   TRC_DEBUG(IO_, "moved %s.tail from %s 
to %s\n",
  fname, BAKDIR, SUBDIR);
-   if (GDKmove(0, BAKDIR, fname, "tail1", SUBDIR, 
fname, "tail1", false) == GDK_SUCCEED)
-   TRC_DEBUG(BAT_, "moved %s.tail1 from %s 
to %s\n",
+   if (stpe == TYPE_str &&
+   GDKmove(0, BAKDIR, fname, "tail1", SUBDIR, 
fname, "tail1", false) == GDK_SUCCEED)
+   TRC_DEBUG(IO_, "moved %s.tail1 from %s 
to %s\n",
  fname, BAKDIR, SUBDIR);
-   if (GDKmove(0, BAKDIR, fname, "tail2", SUBDIR, 
fname, "tail2", false) == GDK_SUCCEED)
-   TRC_DEBUG(BAT_, "moved %s.tail2 from %s 
to %s\n",
+   if (stpe == TYPE_str && b->twidth >= 2 &&
+   GDKmove(0, BAKDIR, fname, "tail2", SUBDIR, 
fname, "tail2", false) == GDK_SUCCEED)
+   TRC_DEBUG(IO_, "moved %s.tail2 from %s 
to %s\n",
  fname, BAKDIR, SUBDIR);
 #if SIZEOF_VAR_T == 8
-   if (GDKmove(0, BAKDIR, fname, "tail4", SUBDIR, 
fname, "tail4", false) == GDK_SUCCEED)
-   TRC_DEBUG(BAT_, "moved %s.tail4 from %s 
to %s\n",
+   if (stpe == TYPE_str && b->twidth >= 4 &&
+   GDKmove(0, BAKDIR, fname, "tail4", SUBDIR, 
fname, "tail4", false) == GDK_SUCCEED)
+   TRC_DEBUG(IO_, "moved %s.tail4 from %s 
to %s\n",
  fname, BAKDIR, SUBDIR);
 #endif
-   if (GDKmove(0, BAKDIR, fname, "theap", SUBDIR, 
fname, "theap", false) == GDK_SUCCEED)
-   TRC_DEBUG(BAT_, "moved %s.theap from %s 
to %s\n",
+   if (ATOMvarsized(b->ttype) &&
+   GDKmove(0, BAKDIR, fname, "theap", SUBDIR, 
fname, "theap", false) == GDK_SUCCEED)
+   TRC_DEBUG(IO_, "moved %s.theap from %s 
to %s\n",
  fname, BAKDIR, SUBDIR);
}
}
-   BAT *b = dirty_bat(, subcommit != NULL);
+   b = dirty_bat(, subcommit != NULL);
if (i <= 0)
ret = GDK_FAIL;
else if (BBP_status(bid) & BBPEXISTING &&
diff --git a/sql/backends/monet5/sql_scenario.c