Changeset: 5e9ccc4294c8 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/5e9ccc4294c8 Modified Files: gdk/gdk_bat.c Branch: Dec2023 Log Message:
Fixed a potential (never observed) deadlock: use BAT iterators instead of lock. Also add timeout handling to COLcopy. diffs (106 lines): diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -814,8 +814,7 @@ COLcopy(BAT *b, int tt, bool writable, r return NULL; } - MT_lock_set(&b->theaplock); - bi = bat_iterator_nolock(b); + bi = bat_iterator(b); /* first try case (1); create a view, possibly with different * atom-types */ @@ -823,12 +822,12 @@ COLcopy(BAT *b, int tt, bool writable, r role == TRANSIENT && bi.restricted == BAT_READ && ATOMstorage(b->ttype) != TYPE_msk && /* no view on TYPE_msk */ - (!VIEWtparent(b) || - BBP_desc(VIEWtparent(b))->batRestricted == BAT_READ)) { - MT_lock_unset(&b->theaplock); + (bi.h == NULL || + bi.h->parentid == b->batCacheid || + BBP_desc(bi.h->parentid)->batRestricted == BAT_READ)) { bn = VIEWcreate(b->hseqbase, b); if (bn == NULL) { - return NULL; + goto bunins_failed; } if (tt != bn->ttype) { bn->ttype = tt; @@ -840,6 +839,7 @@ COLcopy(BAT *b, int tt, bool writable, r } bn->tseqbase = ATOMtype(tt) == TYPE_oid ? bi.tseq : oid_nil; } + bat_iterator_end(&bi); return bn; } else { /* check whether we need case (4); BUN-by-BUN copy (by @@ -867,8 +867,7 @@ COLcopy(BAT *b, int tt, bool writable, r bn = COLnew2(b->hseqbase, tt, bi.count, role, bi.width); if (bn == NULL) { - MT_lock_unset(&b->theaplock); - return NULL; + goto bunins_failed; } if (bn->tvheap != NULL && bn->tvheap->base == NULL) { /* this combination can happen since the last @@ -906,15 +905,20 @@ COLcopy(BAT *b, int tt, bool writable, r bn->batCapacity = 0; } else if (BATatoms[tt].atomFix || tt != TYPE_void || ATOMextern(tt)) { /* case (4): one-by-one BUN insert (really slow) */ - BUN p, q; + lng timeoffset = 0; + QryCtx *qry_ctx = MT_thread_get_qry_ctx(); + if (qry_ctx != NULL) { + timeoffset = (qry_ctx->starttime && qry_ctx->querytimeout) ? (qry_ctx->starttime + qry_ctx->querytimeout) : 0; + } - BATloop(b, p, q) { + TIMEOUT_LOOP_IDX_DECL(p, bi.count, timeoffset) { const void *t = BUNtail(bi, p); if (bunfastapp_nocheck(bn, t) != GDK_SUCCEED) { goto bunins_failed; } } + TIMEOUT_CHECK(timeoffset, GOTO_LABEL_TIMEOUT_HANDLER(bunins_failed)); bn->theap->dirty |= bi.count > 0; } else if (tt != TYPE_void && bi.type == TYPE_void) { /* case (4): optimized for unary void @@ -951,7 +955,7 @@ COLcopy(BAT *b, int tt, bool writable, r } else { BATtseqbase(bn, oid_nil); } - BATkey(bn, BATtkey(b)); + BATkey(bn, bi.key); bn->tsorted = bi.sorted; bn->trevsorted = bi.revsorted; bn->tnorevsorted = bi.norevsorted; @@ -969,7 +973,7 @@ COLcopy(BAT *b, int tt, bool writable, r bn->tunique_est = bi.unique_est; } else if (ATOMstorage(tt) == ATOMstorage(b->ttype) && ATOMcompare(tt) == ATOMcompare(b->ttype)) { - BUN h = BATcount(b); + BUN h = bi.count; bn->tsorted = bi.sorted; bn->trevsorted = bi.revsorted; if (bi.key) @@ -1006,14 +1010,14 @@ COLcopy(BAT *b, int tt, bool writable, r bn->trevsorted = ATOMlinear(b->ttype); bn->tkey = true; } + bat_iterator_end(&bi); if (!writable) bn->batRestricted = BAT_READ; TRC_DEBUG(ALGO, ALGOBATFMT " -> " ALGOBATFMT "\n", ALGOBATPAR(b), ALGOBATPAR(bn)); - MT_lock_unset(&b->theaplock); return bn; bunins_failed: - MT_lock_unset(&b->theaplock); + bat_iterator_end(&bi); BBPreclaim(bn); return NULL; } _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org