Changeset: 62847bc929f3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/62847bc929f3
Modified Files:
        gdk/gdk_bat.c
Branch: Sep2022
Log Message:

Wait until heap refs come down.
I saw the old assert go off, and I figured this was possibly because in
a parallel thread the bat had been used in a bat iterator without having
a fix (e.g. BBPsync calls bat_iterator(BBP_desc(i)) on many bats).  We
now wait patiently until the corresponding bat_iterator_end has been
called.


diffs (31 lines):

diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -683,11 +683,27 @@ BATfree(BAT *b)
        if (nunique != BUN_NONE) {
                b->tunique_est = (double) nunique;
        }
+       /* wait until there are no other references to the heap; a
+        * reference is possible in e.g. BBPsync that uses a
+        * bat_iterator directly on the BBP_desc, i.e. without fix */
+       while (b->theap && (ATOMIC_GET(&b->theap->refs) & HEAPREFS) > 1) {
+               MT_lock_unset(&b->theaplock);
+               MT_sleep_ms(1);
+               MT_lock_set(&b->theaplock);
+       }
        if (b->theap) {
                assert((ATOMIC_GET(&b->theap->refs) & HEAPREFS) == 1);
                assert(b->theap->parentid == b->batCacheid);
                HEAPfree(b->theap, false);
        }
+       /* wait until there are no other references to the heap; a
+        * reference is possible in e.g. BBPsync that uses a
+        * bat_iterator directly on the BBP_desc, i.e. without fix */
+       while (b->tvheap && (ATOMIC_GET(&b->tvheap->refs) & HEAPREFS) > 1) {
+               MT_lock_unset(&b->theaplock);
+               MT_sleep_ms(1);
+               MT_lock_set(&b->theaplock);
+       }
        if (b->tvheap) {
                assert((ATOMIC_GET(&b->tvheap->refs) & HEAPREFS) == 1);
                assert(b->tvheap->parentid == b->batCacheid);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to