Changeset: 5b88be14db38 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5b88be14db38
Modified Files:
        gdk/ChangeLog.Dec2023
        gdk/gdk_logger.c
Branch: Dec2023
Log Message:

Fixed regression leaving unused bats around.


diffs (72 lines):

diff --git a/gdk/ChangeLog.Dec2023 b/gdk/ChangeLog.Dec2023
--- a/gdk/ChangeLog.Dec2023
+++ b/gdk/ChangeLog.Dec2023
@@ -1,3 +1,10 @@
 # ChangeLog file for GDK
 # This file is updated with Maddlog
 
+* Fri Mar  1 2024 Sjoerd Mullender <sjo...@acm.org>
+- Fixed a regression where bats weren't always cleaned up when they
+  weren't needed anymore.  In particular, after a DELETE FROM table query
+  without a WHERE clause (which deletes all rows from the table), the
+  bats for the table get replaced by new ones, and the old, now unused,
+  bats weren't removed from the database.
+
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1222,6 +1222,8 @@ log_read_transaction(logger *lg, uint32_
        bool ok = true;
        ATOMIC_BASE_TYPE dbg = ATOMIC_GET(&GDKdebug);
 
+       (void) maxupdated;      /* only used inside assert() */
+
        if (!lg->flushing)
                ATOMIC_AND(&GDKdebug, ~CHECKMASK);
 
@@ -1249,16 +1251,40 @@ log_read_transaction(logger *lg, uint32_
                        if (updated && BAThash(lg->catalog_id) == GDK_SUCCEED) {
                                BATiter cni = bat_iterator(lg->catalog_id);
                                BUN p;
+                               BUN posnew = BUN_NONE;
+                               BUN posold = BUN_NONE;
                                MT_rwlock_rdlock(&cni.b->thashlock);
                                HASHloop_int(cni, cni.b->thash, p, &l.id) {
-                                       (void)maxupdated;
-                                       assert(p < maxupdated);
-                                       updated[p / 32] |= 1U << (p % 32);
-                                       /* there should only be one hit */
-                                       break;
+                                       lng lid = *(lng *) 
Tloc(lg->catalog_lid, p);
+                                       if (lid == lng_nil || lid > tr->tid)
+                                               posnew = p;
+                                       else if (lid == tr->tid)
+                                               posold = p;
                                }
                                MT_rwlock_rdunlock(&cni.b->thashlock);
                                bat_iterator_end(&cni);
+                               /* Normally at this point, posnew is the
+                                * location of the bat that this
+                                * transaction is working on, and posold
+                                * is the location of the previous
+                                * version of the bat.  If LOG_CREATE,
+                                * both are relevant, since the latter
+                                * is the new bat, and the former is the
+                                * to-be-destroyed bat.  For
+                                * LOG_DESTROY, only posnew should be
+                                * relevant, but for the other types, if
+                                * the table is destroyed later in the
+                                * same transaction, we need posold, and
+                                * else (the normal case) we need
+                                * posnew. */
+                               if (posnew != BUN_NONE) {
+                                       assert(posnew < maxupdated);
+                                       updated[posnew / 32] |= 1U << (posnew % 
32);
+                               }
+                               if ((l.flag == LOG_CREATE || posnew == 
BUN_NONE) && posold != BUN_NONE) {
+                                       assert(posold < maxupdated);
+                                       updated[posold / 32] |= 1U << (posold % 
32);
+                               }
                        }
                        break;
                default:
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to