Changeset: dca8019a0284 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/dca8019a0284
Modified Files:
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_hash.c
gdk/gdk_logger.c
gdk/gdk_private.h
gdk/gdk_storage.c
gdk/gdk_system.c
sql/storage/store.c
Branch: default
Log Message:
Merge with Dec2025 branch.
diffs (truncated from 466 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
@@ -1064,6 +1064,7 @@ BUNappendmulti(BAT *b, const void *value
if (bi.maxpos != BUN_NONE)
maxvalp = BUNtvar(&bi, bi.maxpos);
const void *vbase = b->tvheap->base;
+ Heap *oldheap = b->theap;
for (BUN i = 0; i < count; i++) {
t = ((void **) values)[i];
bool isnil = atomeq(t, atomnil);
@@ -1095,12 +1096,11 @@ BUNappendmulti(BAT *b, const void *value
VALclear(&maxprop);
return rc;
}
- if (vbase != b->tvheap->base) {
- /* tvheap changed location, so
+ if (vbase != b->tvheap->base ||
+ oldheap != b->theap) {
+ /* a heap changed location, so
* pointers may need to be
- * updated (not if they were
- * initialized from t below, but
- * we don't know) */
+ * updated */
BUN minpos = bi.minpos;
BUN maxpos = bi.maxpos;
MT_lock_set(&b->theaplock);
@@ -1109,6 +1109,7 @@ BUNappendmulti(BAT *b, const void *value
bi.minpos = minpos;
bi.maxpos = maxpos;
vbase = b->tvheap->base;
+ oldheap = b->theap;
if (bi.minpos != BUN_NONE)
minvalp = BUNtvar(&bi,
bi.minpos);
if (bi.maxpos != BUN_NONE)
@@ -1140,10 +1141,11 @@ BUNappendmulti(BAT *b, const void *value
if (maxbound)
VALclear(&maxprop);
if (b->thash) {
+ bi.vh = b->tvheap;
p -= count;
for (BUN i = 0; i < count; i++) {
t = ((void **) values)[i];
- HASHappend_locked(b, p, t);
+ HASHappend_locked(&bi, p, t);
p++;
}
nunique = b->thash ? b->thash->nunique : 0;
@@ -1170,7 +1172,7 @@ BUNappendmulti(BAT *b, const void *value
return rc;
}
if (b->thash) {
- HASHappend_locked(b, p, t);
+ HASHappend_locked(&bi, p, t);
}
if (!atomeq(t, atomnil)) {
if (p == 0) {
@@ -1204,7 +1206,8 @@ BUNappendmulti(BAT *b, const void *value
return rc;
}
if (b->thash) {
- HASHappend_locked(b, p, t);
+ bi.vh = b->tvheap;
+ HASHappend_locked(&bi, p, t);
}
p++;
}
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -386,10 +386,11 @@ insert_string_bat(BAT *b, BATiter *ni, s
MT_lock_set(&b->theaplock);
BATsetcount(b, oldcnt + ci->ncand);
assert(b->batCapacity >= b->batCount);
+ BATiter bi = bat_iterator_nolock(b);
MT_lock_unset(&b->theaplock);
/* maintain hash */
for (r = oldcnt, cnt = BATcount(b); b->thash && r < cnt; r++) {
- HASHappend_locked(b, r, b->tvheap->base + VarHeapVal(Tloc(b,
0), r, b->twidth));
+ HASHappend_locked(&bi, r, b->tvheap->base + VarHeapVal(Tloc(b,
0), r, b->twidth));
}
BUN nunique = b->thash ? b->thash->nunique : 0;
MT_rwlock_wrunlock(&b->thashlock);
@@ -464,12 +465,13 @@ append_varsized_bat(BAT *b, BATiter *ni,
MT_rwlock_wrlock(&b->thashlock);
MT_lock_set(&b->theaplock);
BATsetcount(b, BATcount(b) + ci->ncand);
+ BATiter bi = bat_iterator_nolock(b);
MT_lock_unset(&b->theaplock);
/* maintain hash table */
for (BUN i = BATcount(b) - ci->ncand;
b->thash && i < BATcount(b);
i++) {
- HASHappend_locked(b, i, b->tvheap->base + *(var_t *)
Tloc(b, i));
+ HASHappend_locked(&bi, i, b->tvheap->base + *(var_t *)
Tloc(b, i));
}
BUN nunique = b->thash ? b->thash->nunique : 0;
MT_rwlock_wrunlock(&b->thashlock);
@@ -553,7 +555,7 @@ append_varsized_bat(BAT *b, BATiter *ni,
BATiter bi = bat_iterator_nolock(b);
for (BUN i = 0; i < cnt; i++) {
const void *t = BUNtvar(&bi, r);
- HASHappend_locked(b, r, t);
+ HASHappend_locked(&bi, r, t);
r++;
}
}
@@ -1021,6 +1023,9 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool
goto bailout;
}
}
+ MT_lock_set(&b->theaplock);
+ BATiter bi = bat_iterator_nolock(b);
+ MT_lock_unset(&b->theaplock);
MT_rwlock_wrlock(&b->thashlock);
hlocked = true;
if (b->ttype != TYPE_void &&
@@ -1031,7 +1036,7 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool
(const char *) ni.base + ((ci.seq - hseq) <<
ni.shift),
ci.ncand << ni.shift);
for (BUN i = 0; b->thash && i < ci.ncand; i++) {
- HASHappend_locked(b, r, Tloc(b, r));
+ HASHappend_locked(&bi, r, Tloc(b, r));
r++;
}
} else {
@@ -1059,8 +1064,10 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool
} else if (tfastins_nocheck(b, r, t) !=
GDK_SUCCEED) {
goto bailout;
}
- if (b->thash)
- HASHappend_locked(b, r, t);
+ if (b->thash) {
+ bi.vh = b->tvheap;
+ HASHappend_locked(&bi, r, t);
+ }
r++;
}
TIMEOUT_CHECK(qry_ctx,
GOTO_LABEL_TIMEOUT_HANDLER(bailout, qry_ctx));
diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -1100,8 +1100,9 @@ HASHprobe(const Hash *h, const void *v)
}
void
-HASHappend_locked(BAT *b, BUN i, const void *v)
+HASHappend_locked(BATiter *bi, BUN i, const void *v)
{
+ BAT *b = bi->b;
Hash *h = b->thash;
if (h == NULL) {
return;
@@ -1148,12 +1149,11 @@ HASHappend_locked(BAT *b, BUN i, const v
h->heaplink.free += h->width;
BUN hb = HASHget(h, c);
BUN hb2;
- BATiter bi = bat_iterator_nolock(b);
bool (*atomeq)(const void *, const void *) = ATOMequal(h->type);
for (hb2 = hb;
hb2 != BUN_NONE;
hb2 = HASHgetlink(h, hb2)) {
- if (atomeq(v, BUNtail(&bi, hb2)))
+ if (atomeq(v, BUNtail(bi, hb2)))
break;
}
h->nheads += hb == BUN_NONE;
@@ -1168,8 +1168,11 @@ BUN
HASHappend(BAT *b, BUN i, const void *v)
{
BUN nunique;
+ MT_lock_set(&b->theaplock);
+ BATiter bi = bat_iterator_nolock(b);
+ MT_lock_unset(&b->theaplock);
MT_rwlock_wrlock(&b->thashlock);
- HASHappend_locked(b, i, v);
+ HASHappend_locked(&bi, i, v);
nunique = b->thash ? b->thash->nunique : 0;
MT_rwlock_wrunlock(&b->thashlock);
return nunique;
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1106,8 +1106,8 @@ tr_grow(trans *tr)
tr->sz <<= 1;
changes = ma_realloc(MT_thread_getallocator(),
tr->changes,
- sz * sizeof(logaction),
- tr->sz * sizeof(logaction));
+ tr->sz * sizeof(logaction),
+ sz * sizeof(logaction));
if (changes == NULL)
return GDK_FAIL;
tr->changes = changes;
@@ -2045,7 +2045,7 @@ bm_subcommit(logger *lg, logged_range *p
return GDK_FAIL;
}
}
- if (updated && p < maxupdated && (updated[p / 32] & (1U << (p %
32))) == 0) {
+ if (updated && (p >= maxupdated || (updated[p / 32] & (1U << (p
% 32))) == 0)) {
continue;
}
bat col = bids[p];
@@ -2988,13 +2988,13 @@ log_flush(logger *lg, ulng ts)
BUN n = BATcount(lg->catalog_id);
size_t a = ((n + 31) & ~31) / 8;
if (a > allocated) {
- updated = ma_realloc(ta, updated, allocated, a);
+ updated = ma_realloc(ta, updated, a, allocated);
if (updated == NULL) {
ma_close(&ta_state);
log_unlock(lg);
return GDK_FAIL;
}
- memset(updated + allocated / 4, 0, a -
allocated);
+ memset((char *) updated + allocated, 0, a -
allocated);
allocated = a;
}
nupdated = n;
@@ -3108,6 +3108,36 @@ log_constant_bulk(logger *lg, int type,
return ok;
}
+static gdk_return
+lg_updated_set_bit(logger *lg, log_id id, BUN p)
+{
+ assert(p != BUN_NONE);
+ if (lg->updated != NULL) {
+ if (id > 0) {
+ p = log_find(lg->catalog_id, lg->dcatalog, id);
+ if (p == BUN_NONE) {
+ GDKerror("%d not found in catalog_id BAT", id);
+ return GDK_FAIL;
+ }
+ }
+ if (p >= lg->maxupdated) {
+ BUN cnt = BATcount(lg->catalog_id);
+ assert(p < cnt);
+ size_t allocated = ((cnt + 31) & ~31) / 8;
+ assert(allocated > 0);
+ uint32_t *u = GDKrealloc(lg->updated, allocated);
+ if (u == NULL)
+ return GDK_FAIL;
+ memset((char *) u + lg->maxupdated / 8, 0,
+ allocated - lg->maxupdated / 8);
+ lg->maxupdated = allocated * 8;
+ lg->updated = u;
+ }
+ lg->updated[p / 32] |= 1U << (p % 32);
+ }
+ return GDK_SUCCEED;
+}
+
gdk_return
log_constant(logger *lg, int type, const void *val, log_id id, lng offset, lng
cnt, lng total_cnt)
{
@@ -3116,15 +3146,8 @@ log_constant(logger *lg, int type, const
if (LOG_DISABLED(lg) || !nr) {
/* logging is switched off */
- if (lg->updated != NULL) {
- BUN p = log_find(lg->catalog_id, lg->dcatalog, id);
- if (p == BUN_NONE) {
- GDKerror("%d not found in catalog_id BAT", id);
- return GDK_FAIL;
- }
- if (p < lg->maxupdated)
- lg->updated[p / 32] |= 1U << (p % 32);
- }
+ if (lg_updated_set_bit(lg, id, 0) != GDK_SUCCEED)
+ return GDK_FAIL;
if (nr) {
log_lock(lg);
ok = la_bat_update_count(lg, id, offset + cnt, lg->tid);
@@ -3231,15 +3254,8 @@ internal_log_bat(logger *lg, BAT *b, log
if (LOG_DISABLED(lg) || !nr) {
/* logging is switched off */
- if (lg->updated != NULL) {
- BUN p = log_find(lg->catalog_id, lg->dcatalog, id);
- if (p == BUN_NONE) {
- GDKerror("%d not found in catalog_id BAT", id);
- return GDK_FAIL;
- }
- if (p < lg->maxupdated)
- lg->updated[p / 32] |= 1U << (p % 32);
- }
+ if (lg_updated_set_bit(lg, id, 0) != GDK_SUCCEED)
+ return GDK_FAIL;
if (nr)
return la_bat_update_count(lg, id, offset + cnt,
lg->tid);
return GDK_SUCCEED;
@@ -3464,15 +3480,8 @@ log_delta(logger *lg, BAT *uid, BAT *uva
if (LOG_DISABLED(lg)) {
/* logging is switched off */
- if (lg->updated != NULL) {
- BUN p = log_find(lg->catalog_id, lg->dcatalog, id);
- if (p == BUN_NONE) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]