Changeset: 4169935afd3a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4169935afd3a
Modified Files:
gdk/gdk_align.c
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_hash.c
gdk/gdk_heap.c
gdk/gdk_imprints.c
gdk/gdk_orderidx.c
gdk/gdk_strimps.c
gdk/gdk_string.c
Branch: Aug2024
Log Message:
Set dirty flag after changing, clear before saving.
So if saving and changing overlap, the end result should be that the
dirty flag is set.
diffs (truncated from 337 to 300 lines):
diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -317,7 +317,6 @@ BATmaterialize(BAT *b, BUN cap)
h = b->theap;
b->theap = tail;
b->tbaseoff = 0;
- b->theap->dirty = true;
b->tunique_est = is_oid_nil(t) ? 1.0 : (double) b->batCount;
b->ttype = TYPE_oid;
BATsetdims(b, 0);
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -945,24 +945,24 @@ COLcopy(BAT *b, int tt, bool writable, r
oid cur = bi.tseq, *dst = (oid *) Tloc(bn, 0);
const oid inc = !is_oid_nil(cur);
- bn->theap->free = bi.count * sizeof(oid);
- bn->theap->dirty |= bi.count > 0;
for (BUN p = 0; p < bi.count; p++) {
dst[p] = cur;
cur += inc;
}
+ bn->theap->free = bi.count * sizeof(oid);
+ bn->theap->dirty |= bi.count > 0;
} else if (ATOMstorage(bi.type) == TYPE_msk) {
/* convert number of bits to number of bytes,
* and round the latter up to a multiple of
* 4 (copy in units of 4 bytes) */
bn->theap->free = ((bi.count + 31) / 32) * 4;
+ memcpy(Tloc(bn, 0), bi.base, bn->theap->free);
bn->theap->dirty |= bi.count > 0;
- memcpy(Tloc(bn, 0), bi.base, bn->theap->free);
} else {
/* case (4): optimized for simple array copy */
bn->theap->free = bi.count << bn->tshift;
+ memcpy(Tloc(bn, 0), bi.base, bn->theap->free);
bn->theap->dirty |= bi.count > 0;
- memcpy(Tloc(bn, 0), bi.base, bn->theap->free);
}
/* copy all properties (size+other) from the source bat */
BATsetcount(bn, bi.count);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -507,7 +507,6 @@ append_msk_bat(BAT *b, BATiter *ni, stru
uint32_t boff = b->batCount % 32;
uint32_t *bp = (uint32_t *) b->theap->base + b->batCount / 32;
b->batCount += ci->ncand;
- b->theap->dirty = true;
b->theap->free = ((b->batCount + 31) / 32) * 4;
if (ci->tpe == cand_dense) {
const uint32_t *np;
@@ -660,6 +659,7 @@ append_msk_bat(BAT *b, BATiter *ni, stru
boff = 0;
} while (!is_oid_nil(o));
}
+ b->theap->dirty = true;
MT_lock_unset(&b->theaplock);
return GDK_SUCCEED;
}
diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -350,8 +350,6 @@ HASHgrowbucket(BAT *b)
HASHupgradehashheap(b) != GDK_SUCCEED)
return GDK_FAIL;
- h->heapbckt.dirty = true;
- h->heaplink.dirty = true;
while (h->nunique >= (nbucket = h->nbucket) * 7 / 8) {
BUN new = h->nbucket;
BUN old = new & h->mask1;
@@ -418,6 +416,8 @@ HASHgrowbucket(BAT *b)
else
HASHputlink(h, lold, BUN_NONE);
}
+ h->heapbckt.dirty = true;
+ h->heaplink.dirty = true;
TRC_DEBUG_IF(ACCELERATOR) if (h->nbucket > onbucket) {
TRC_DEBUG_ENDIF(ACCELERATOR, ALGOBATFMT " " BUNFMT
" -> " BUNFMT " buckets (" LLFMT " usec)\n",
@@ -553,8 +553,6 @@ BATcheckhash(BAT *b)
h->Bckt =
h->heapbckt.base + HASH_HEADER_SIZE * SIZEOF_SIZE_T;
h->heaplink.parentid = b->batCacheid;
h->heapbckt.parentid = b->batCacheid;
-
h->heaplink.dirty = false;
-
h->heapbckt.dirty = false;
b->thash = h;
h->heapbckt.hasfile = true;
h->heaplink.hasfile = true;
@@ -625,16 +623,20 @@ BAThashsave_intern(BAT *b, bool dosync)
* mean time */
if (!b->theap->dirty &&
((size_t *) h->heapbckt.base)[1] == BATcount(b) &&
- ((size_t *) h->heapbckt.base)[4] == BATcount(b) &&
- HEAPsave(&h->heaplink, h->heaplink.filename, NULL, dosync,
h->heaplink.free, NULL) == GDK_SUCCEED &&
- HEAPsave(&h->heapbckt, h->heapbckt.filename, NULL, dosync,
h->heapbckt.free, NULL) == GDK_SUCCEED) {
+ ((size_t *) h->heapbckt.base)[4] == BATcount(b)) {
h->heaplink.dirty = false;
h->heapbckt.dirty = false;
- h->heaplink.hasfile = true;
- h->heapbckt.hasfile = true;
- gdk_return rc = HASHfix(h, true, dosync);
- TRC_DEBUG(ACCELERATOR,
- ALGOBATFMT ": persisting hash %s%s (" LLFMT "
usec)%s\n", ALGOBATPAR(b), h->heapbckt.filename, dosync ? "" : " no sync",
GDKusec() - t0, rc == GDK_SUCCEED ? "" : " failed");
+ if (HEAPsave(&h->heaplink, h->heaplink.filename, NULL,
dosync, h->heaplink.free, NULL) == GDK_SUCCEED &&
+ HEAPsave(&h->heapbckt, h->heapbckt.filename, NULL,
dosync, h->heapbckt.free, NULL) == GDK_SUCCEED) {
+ h->heaplink.hasfile = true;
+ h->heapbckt.hasfile = true;
+ gdk_return rc = HASHfix(h, true, dosync);
+ TRC_DEBUG(ACCELERATOR,
+ ALGOBATFMT ": persisting hash %s%s ("
LLFMT " usec)%s\n", ALGOBATPAR(b), h->heapbckt.filename, dosync ? "" : " no
sync", GDKusec() - t0, rc == GDK_SUCCEED ? "" : " failed");
+ } else {
+ h->heaplink.dirty = true;
+ h->heapbckt.dirty = true;
+ }
}
GDKclrerr();
}
@@ -1195,10 +1197,10 @@ HASHinsert_locked(BATiter *bi, BUN p, co
if (hb == BUN_NONE || hb < p) {
/* bucket is empty, or bucket is used by lower numbered
* position */
+ HASHputlink(h, p, hb);
+ HASHput(h, c, p);
h->heaplink.dirty = true;
h->heapbckt.dirty = true;
- HASHputlink(h, p, hb);
- HASHput(h, c, p);
if (hb == BUN_NONE) {
h->nheads++;
} else {
@@ -1222,9 +1224,9 @@ HASHinsert_locked(BATiter *bi, BUN p, co
seen = atomcmp(v, BUNtail(*bi, hb)) == 0;
BUN hb2 = HASHgetlink(h, hb);
if (hb2 == BUN_NONE || hb2 < p) {
- h->heaplink.dirty = true;
HASHputlink(h, p, hb2);
HASHputlink(h, hb, p);
+ h->heaplink.dirty = true;
while (!seen && hb2 != BUN_NONE) {
seen = atomcmp(v, BUNtail(*bi, hb2)) == 0;
hb2 = HASHgetlink(h, hb2);
@@ -1281,10 +1283,10 @@ HASHdelete_locked(BATiter *bi, BUN p, co
int (*atomcmp)(const void *, const void *) = ATOMcompare(h->type);
if (hb == p) {
BUN hb2 = HASHgetlink(h, p);
+ HASHput(h, c, hb2);
+ HASHputlink(h, p, BUN_NONE);
h->heaplink.dirty = true;
h->heapbckt.dirty = true;
- HASHput(h, c, hb2);
- HASHputlink(h, p, BUN_NONE);
if (hb2 == BUN_NONE) {
h->nheads--;
} else {
@@ -1326,9 +1328,9 @@ HASHdelete_locked(BATiter *bi, BUN p, co
return;
}
}
- h->heaplink.dirty = true;
HASHputlink(h, hb, HASHgetlink(h, p));
HASHputlink(h, p, BUN_NONE);
+ h->heaplink.dirty = true;
if (!seen)
h->nunique--;
}
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -819,6 +819,7 @@ HEAPload(Heap *h, const char *nme, const
return GDK_FAIL;
}
}
+ h->dirty = false; /* we're about to read it, so it's clean */
if (h->storage == STORE_MEM && h->free == 0) {
h->base = GDKmalloc(h->size);
h->wasempty = true;
@@ -837,7 +838,6 @@ HEAPload(Heap *h, const char *nme, const
return GDK_FAIL; /* file could not be read satisfactorily */
}
- h->dirty = false; /* we just read it, so it's clean */
return GDK_SUCCEED;
}
@@ -1119,7 +1119,6 @@ HEAP_malloc(BAT *b, size_t nbytes)
}
heap = b->tvheap;
heap->free = newsize;
- heap->dirty = true;
hheader = HEAP_index(heap, 0, HEADER);
blockp = HEAP_index(heap, block, CHUNK);
@@ -1167,6 +1166,8 @@ HEAP_malloc(BAT *b, size_t nbytes)
trailp->next = blockp->next;
}
+ heap->dirty = true;
+
block += hheader->alignment;
return (var_t) block;
}
diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -408,7 +408,7 @@ BATimpsync(void *arg)
((size_t *) hp->base)[0] |= (size_t)
IMPRINTS_VERSION << 8;
/* sync-on-disk checked bit */
((size_t *) hp->base)[0] |= (size_t) 1
<< 16;
- if (write(fd, hp->base, SIZEOF_SIZE_T)
>= 0) {
+ if (write(fd, hp->base, SIZEOF_SIZE_T)
== SIZEOF_SIZE_T) {
failed = ""; /* not failed */
if (!(ATOMIC_GET(&GDKdebug) &
NOSYNCMASK)) {
#if defined(NATIVE_WIN32)
@@ -419,8 +419,8 @@ BATimpsync(void *arg)
fsync(fd);
#endif
}
- hp->dirty = false;
} else {
+ hp->dirty = true;
failed = " write failed";
perror("write hash");
}
@@ -433,10 +433,10 @@ BATimpsync(void *arg)
((size_t *) hp->base)[0] |= (size_t) 1 << 16;
if (!(ATOMIC_GET(&GDKdebug) & NOSYNCMASK) &&
MT_msync(hp->base, SIZEOF_SIZE_T) < 0) {
+ hp->dirty = true;
failed = " sync failed";
((size_t *) hp->base)[0] &= ~((size_t)
IMPRINTS_VERSION << 8);
} else {
- hp->dirty = false;
failed = ""; /* not failed */
}
}
diff --git a/gdk/gdk_orderidx.c b/gdk/gdk_orderidx.c
--- a/gdk/gdk_orderidx.c
+++ b/gdk/gdk_orderidx.c
@@ -44,8 +44,8 @@ BATidxsync(void *arg)
fsync(fd);
#endif
}
- hp->dirty = false;
} else {
+ hp->dirty = true;
perror("write hash");
}
close(fd);
@@ -54,9 +54,9 @@ BATidxsync(void *arg)
((oid *) hp->base)[0] |= (oid) 1 << 24;
if (!(ATOMIC_GET(&GDKdebug) & NOSYNCMASK) &&
MT_msync(hp->base, SIZEOF_OID) < 0) {
+ hp->dirty = true;
((oid *) hp->base)[0] &= ~((oid) 1 <<
24);
} else {
- hp->dirty = false;
failed = ""; /* not failed */
}
}
diff --git a/gdk/gdk_strimps.c b/gdk/gdk_strimps.c
--- a/gdk/gdk_strimps.c
+++ b/gdk/gdk_strimps.c
@@ -646,8 +646,8 @@ BATstrimpsync(BAT *b)
fsync(fd);
#endif
}
- hp->dirty = false;
} else {
+ hp->dirty = true;
perror("write strimps");
}
close(fd);
@@ -656,9 +656,9 @@ BATstrimpsync(BAT *b)
((uint64_t *)hp->base)[0] |= (uint64_t) 1 << 32;
if (!(ATOMIC_GET(&GDKdebug) & NOSYNCMASK) &&
MT_msync(hp->base, sizeof(uint64_t)) < 0) {
+ hp->dirty = true;
((uint64_t *)hp->base)[0] &=
~((uint64_t) 1 << 32);
} else {
- hp->dirty = false;
failed = "";
}
}
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -126,11 +126,11 @@ strCleanHash(Heap *h, bool rebuild)
/* only set dirty flag if the hash table actually changed */
if (memcmp(newhash, h->base, sizeof(newhash)) != 0) {
memcpy(h->base, newhash, sizeof(newhash));
- if (h->storage == STORE_MMAP) {
- if (!(ATOMIC_GET(&GDKdebug) & NOSYNCMASK))
- (void) MT_msync(h->base, GDK_STRHASHSIZE);
- } else
+ if (h->storage != STORE_MMAP ||
+ ATOMIC_GET(&GDKdebug) & NOSYNCMASK ||
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]