Changeset: c84b4bb52fee for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/c84b4bb52fee Modified Files: sql/backends/monet5/rel_bin.c Branch: pushcands Log Message:
Merged with default diffs (truncated from 395 to 300 lines): diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -517,6 +517,7 @@ gdk_return BATextend(BAT *b, BUN newcap) { size_t theap_size; + gdk_return rc = GDK_SUCCEED; assert(newcap <= BUN_MAX); BATcheck(b, GDK_FAIL); @@ -544,17 +545,21 @@ BATextend(BAT *b, BUN newcap) if (b->theap->base) { TRC_DEBUG(HEAP, "HEAPgrow in BATextend %s %zu %zu\n", b->theap->filename, b->theap->size, theap_size); - if (b->ttype == TYPE_str) - return GDKupgradevarheap(b, GDK_VAROFFSET, newcap, false); - Heap *h = HEAPgrow(b->theap, theap_size); - if (h == NULL) - return GDK_FAIL; MT_lock_set(&b->theaplock); - HEAPdecref(b->theap, false); - b->theap = h; + if (ATOMIC_GET(&b->theap->refs) == 1) { + rc = HEAPextend(b->theap, theap_size, true); + } else { + MT_lock_unset(&b->theaplock); + Heap *h = HEAPgrow(b->theap, theap_size); + if (h == NULL) + return GDK_FAIL; + MT_lock_set(&b->theaplock); + HEAPdecref(b->theap, false); + b->theap = h; + } MT_lock_unset(&b->theaplock); } - return GDK_SUCCEED; + return rc; } diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c --- a/gdk/gdk_batop.c +++ b/gdk/gdk_batop.c @@ -27,6 +27,7 @@ unshare_varsized_heap(BAT *b) Heap *h = GDKzalloc(sizeof(Heap)); if (h == NULL) return GDK_FAIL; + MT_thread_setalgorithm("unshare vheap"); h->parentid = b->batCacheid; h->farmid = BBPselectfarm(b->batRole, TYPE_str, varheap); strconcat_len(h->filename, sizeof(h->filename), @@ -111,6 +112,7 @@ insert_string_bat(BAT *b, BAT *n, struct /* make sure locking happens in a * predictable order: lowest id * first */ + MT_thread_setalgorithm("share vheap, copy heap"); if (b->batCacheid < n->batCacheid) { MT_lock_set(&b->theaplock); MT_lock_set(&n->theaplock); @@ -136,6 +138,7 @@ insert_string_bat(BAT *b, BAT *n, struct (var_t) 1 << 17; } else if (b->tvheap->parentid == n->tvheap->parentid && ci->tpe == cand_dense) { + MT_thread_setalgorithm("copy heap"); toff = 0; } else if (b->tvheap->parentid != bid && unshare_varsized_heap(b) != GDK_SUCCEED) { @@ -148,6 +151,7 @@ insert_string_bat(BAT *b, BAT *n, struct n->twidth != 4 ? (var_t) 1 << 33 : #endif (var_t) 1 << 17; + MT_thread_setalgorithm("copy vheap, copy heap"); if (b->tvheap->size < n->tvheap->free) { Heap *h = HEAPgrow(b->tvheap, n->tvheap->free); if (h == NULL) @@ -207,6 +211,7 @@ insert_string_bat(BAT *b, BAT *n, struct HEAPdecref(b->tvheap, false); b->tvheap = h; MT_lock_unset(&b->theaplock); + MT_thread_setalgorithm("append vheap"); memcpy(b->tvheap->base + toff, n->tvheap->base, n->tvheap->free); b->tvheap->free = toff + n->tvheap->free; if (toff > 0) { @@ -217,7 +222,8 @@ insert_string_bat(BAT *b, BAT *n, struct } } } - } else if (unshare_varsized_heap(b) != GDK_SUCCEED) + } else if (b->tvheap != n->tvheap && + unshare_varsized_heap(b) != GDK_SUCCEED) return GDK_FAIL; /* make sure there is (vertical) space in the offset heap, we @@ -250,32 +256,27 @@ insert_string_bat(BAT *b, BAT *n, struct switch (b->twidth) { case 1: - b->ttype = TYPE_bte; tp = &tbv; break; case 2: - b->ttype = TYPE_sht; tp = &tsv; break; #if SIZEOF_VAR_T == 8 case 4: - b->ttype = TYPE_int; tp = &tiv; break; case 8: - b->ttype = TYPE_lng; tp = &v; break; #else case 4: - b->ttype = TYPE_int; tp = &v; break; #endif default: assert(0); } - b->tvarsized = false; + MT_thread_setalgorithm("copy offset values"); while (cnt > 0) { cnt--; p = canditer_next(ci) - n->hseqbase; @@ -322,8 +323,6 @@ insert_string_bat(BAT *b, BAT *n, struct break; } } - b->tvarsized = true; - b->ttype = TYPE_str; } else if (b->tvheap->free < n->tvheap->free / 2 || GDK_ELIMDOUBLES(b->tvheap)) { /* if b's string heap is much smaller than n's string @@ -333,6 +332,7 @@ insert_string_bat(BAT *b, BAT *n, struct * to use the double elimination mechanism */ r = BUNlast(b); oid hseq = n->hseqbase; + MT_thread_setalgorithm("insert string values"); while (cnt > 0) { cnt--; p = canditer_next(ci) - hseq; @@ -349,6 +349,7 @@ insert_string_bat(BAT *b, BAT *n, struct * n's). If this is the case, we just copy the * offset, otherwise we insert normally. */ r = BUNlast(b); + MT_thread_setalgorithm("insert string values with check"); while (cnt > 0) { cnt--; p = canditer_next(ci) - n->hseqbase; diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -2398,6 +2398,7 @@ BBPkeepref(bat i) BAT *b; if ((b = BBPdescriptor(i)) != NULL) { + BATsetaccess(b, BAT_READ); BATsettrivprop(b); if (GDKdebug & (CHECKMASK | PROPMASK)) BATassertProps(b); diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c --- a/gdk/gdk_heap.c +++ b/gdk/gdk_heap.c @@ -432,9 +432,12 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c newsize = cap << shift; else newsize = (old->size >> b->tshift) << shift; - if (b->twidth == width && newsize <= old->size) { - /* nothing to do */ - return GDK_SUCCEED; + if (b->twidth == width) { + if (newsize <= old->size) { + /* nothing to do */ + return GDK_SUCCEED; + } + return BATextend(b, newsize >> shift); } /* if copyall is set, we need to convert the whole heap, since @@ -443,6 +446,8 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c * indicated by the "free" pointer */ n = (copyall ? old->size : old->free) >> b->tshift; + if (width > b->twidth) + MT_thread_setalgorithm(n ? "widen offset heap" : "widen empty offset heap"); /* Create a backup copy before widening. * * If the file is memory-mapped, this solves a problem that we @@ -460,7 +465,7 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c else filename++; int exists = 0; - if (BBP_status(bid) & (BBPEXISTING|BBPDELETED)) { + if (BBP_status(bid) & (BBPEXISTING|BBPDELETED) && width > b->twidth) { char fname[sizeof(old->filename)]; char *p = strrchr(old->filename, DIR_SEP); strcpy_len(fname, p ? p + 1 : old->filename, sizeof(fname)); diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c --- a/monetdb5/modules/kernel/bat5.c +++ b/monetdb5/modules/kernel/bat5.c @@ -75,7 +75,9 @@ BKCnewBAT(bat *res, const int *tt, const if (bn == NULL) throw(MAL, "bat.new", GDK_EXCEPTION); *res = bn->batCacheid; - BBPkeepref(*res); + BATsettrivprop(bn); + BBPretain(bn->batCacheid); + BBPunfix(bn->batCacheid); return MAL_SUCCEED; } @@ -138,13 +140,14 @@ BKCdelete(bat *r, const bat *bid, const if ((b = BATdescriptor(*bid)) == NULL) throw(MAL, "bat.delete", SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); - if ((b = setaccess(b, BAT_WRITE)) == NULL) - throw(MAL, "bat.delete", OPERATION_FAILED); if (BUNdelete(b, *h) != GDK_SUCCEED) { BBPunfix(b->batCacheid); throw(MAL, "bat.delete", GDK_EXCEPTION); } - BBPkeepref(*r = b->batCacheid); + *r = b->batCacheid; + BATsettrivprop(b); + BBPretain(b->batCacheid); + BBPunfix(b->batCacheid); return MAL_SUCCEED; } @@ -166,7 +169,10 @@ BKCdelete_multi(bat *r, const bat *bid, BBPunfix(b->batCacheid); throw(MAL, "bat.delete", GDK_EXCEPTION); } - BBPkeepref(*r = b->batCacheid); + *r = b->batCacheid; + BATsettrivprop(b); + BBPretain(b->batCacheid); + BBPunfix(b->batCacheid); return MAL_SUCCEED; } @@ -183,7 +189,10 @@ BKCdelete_all(bat *r, const bat *bid) } if( !b->batTransient) BATmsync(b); - BBPkeepref(*r = b->batCacheid); + *r = b->batCacheid; + BATsettrivprop(b); + BBPretain(b->batCacheid); + BBPunfix(b->batCacheid); return MAL_SUCCEED; } @@ -216,7 +225,10 @@ BKCappend_cand_force_wrap(bat *r, const } if( !b->batTransient) BATmsync(b); - BBPkeepref(*r = b->batCacheid); + *r = b->batCacheid; + BATsettrivprop(b); + BBPretain(b->batCacheid); + BBPunfix(b->batCacheid); return MAL_SUCCEED; } @@ -257,7 +269,10 @@ BKCappend_val_force_wrap(bat *r, const b BBPunfix(b->batCacheid); throw(MAL, "bat.append", GDK_EXCEPTION); } - BBPkeepref(*r = b->batCacheid); + *r = b->batCacheid; + BATsettrivprop(b); + BBPretain(b->batCacheid); + BBPunfix(b->batCacheid); return MAL_SUCCEED; } @@ -278,7 +293,10 @@ BKCbun_inplace(bat *r, const bat *bid, c BBPunfix(b->batCacheid); throw(MAL, "bat.inplace", GDK_EXCEPTION); } - BBPkeepref(*r = b->batCacheid); + *r = b->batCacheid; + BATsettrivprop(b); + BBPretain(b->batCacheid); + BBPunfix(b->batCacheid); return MAL_SUCCEED; } @@ -293,7 +311,10 @@ BKCbun_inplace_force(bat *r, const bat * BBPunfix(b->batCacheid); throw(MAL, "bat.inplace", GDK_EXCEPTION); } - BBPkeepref(*r = b->batCacheid); + *r = b->batCacheid; + BATsettrivprop(b); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list