Changeset: a874bfc947cd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a874bfc947cd
Modified Files:
        gdk/gdk_align.c
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        gdk/gdk_heap.c
Branch: default
Log Message:

Initialize heap filename once when heap is created, then leave it alone.


diffs (truncated from 508 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
@@ -338,11 +338,9 @@ VIEWreset(BAT *b)
                assert(tp || tvp || !b->ttype);
 
                tail.farmid = BBPselectfarm(b->batRole, b->ttype, offheap);
-               if (b->ttype) {
-                       snprintf(tail.filename, sizeof(tail.filename), 
"%s.tail", nme);
-                       if (b->ttype && HEAPalloc(&tail, cnt, Tsize(b)) != 
GDK_SUCCEED)
-                               goto bailout;
-               }
+               snprintf(tail.filename, sizeof(tail.filename), "%s.tail", nme);
+               if (b->ttype && HEAPalloc(&tail, cnt, Tsize(b)) != GDK_SUCCEED)
+                       goto bailout;
                if (b->tvheap) {
                        th = GDKzalloc(sizeof(Heap));
                        if (th == NULL)
@@ -488,7 +486,6 @@ VIEWdestroy(BAT *b)
                HEAPfree(&b->theap, 0);
        } else {
                b->theap.base = NULL;
-               b->theap.filename[0] = 0;
        }
        b->tvheap = NULL;
        BATfree(b);
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -114,22 +114,18 @@ BATcreatedesc(oid hseq, int tt, int heap
         * very large writes.
         */
        assert(bn->batCacheid > 0);
-       bn->theap.filename[0] = 0;
+
+       const char *nme = BBP_physical(bn->batCacheid);
+       snprintf(bn->theap.filename, sizeof(bn->theap.filename),
+                "%s.tail", nme);
        bn->theap.farmid = BBPselectfarm(role, bn->ttype, offheap);
-       if (heapnames) {
-               const char *nme = BBP_physical(bn->batCacheid);
-
-               if (tt) {
-                       snprintf(bn->theap.filename, 
sizeof(bn->theap.filename), "%s.tail", nme);
-               }
-
-               if (ATOMneedheap(tt)) {
-                       if ((bn->tvheap = (Heap *) GDKzalloc(sizeof(Heap))) == 
NULL)
-                               goto bailout;
-                       snprintf(bn->tvheap->filename, 
sizeof(bn->tvheap->filename), "%s.theap", nme);
-                       bn->tvheap->parentid = bn->batCacheid;
-                       bn->tvheap->farmid = BBPselectfarm(role, bn->ttype, 
varheap);
-               }
+       if (heapnames && ATOMneedheap(tt)) {
+               if ((bn->tvheap = (Heap *) GDKzalloc(sizeof(Heap))) == NULL)
+                       goto bailout;
+               snprintf(bn->tvheap->filename, sizeof(bn->tvheap->filename),
+                        "%s.theap", nme);
+               bn->tvheap->parentid = bn->batCacheid;
+               bn->tvheap->farmid = BBPselectfarm(role, bn->ttype, varheap);
        }
        bn->batDirty = TRUE;
        return bn;
@@ -201,7 +197,7 @@ BATnewstorage(oid hseq, int tt, BUN cap,
                goto bailout;
        }
 
-       if (ATOMheap(tt, bn->tvheap, cap) != GDK_SUCCEED) {
+       if (bn->tvheap && ATOMheap(tt, bn->tvheap, cap) != GDK_SUCCEED) {
                GDKfree(bn->tvheap);
                goto bailout;
        }
@@ -519,6 +515,7 @@ BATclear(BAT *b, int force)
 
                        memset(&th, 0, sizeof(th));
                        th.farmid = b->tvheap->farmid;
+                       strncpy(th.filename, b->tvheap->filename, 
sizeof(th.filename));
                        if (ATOMheap(b->ttype, &th, 0) != GDK_SUCCEED)
                                return GDK_FAIL;
                        th.parentid = b->tvheap->parentid;
@@ -626,22 +623,9 @@ BATdestroy(BAT *b)
  * which ensures that the original cannot be modified or destroyed
  * (which could affect the shared heaps).
  */
-static gdk_return
-heapcopy(BAT *bn, char *ext, Heap *dst, Heap *src)
-{
-       if (src->filename[0] && src->newstorage != STORE_MEM) {
-               snprintf(dst->filename, sizeof(dst->filename), "%s.%s",
-                        BBP_physical(bn->batCacheid), ext);
-       }
-       return HEAPcopy(dst, src);
-}
-
 static void
 heapmove(Heap *dst, Heap *src)
 {
-       if (src->filename[0] == 0) {
-               strncpy(src->filename, dst->filename, sizeof(src->filename));
-       }
        HEAPfree(dst, 0);
        *dst = *src;
 }
@@ -754,8 +738,12 @@ COLcopy(BAT *b, int tt, int writable, in
 
                        bthp.farmid = BBPselectfarm(role, b->ttype, offheap);
                        thp.farmid = BBPselectfarm(role, b->ttype, varheap);
-                       if ((b->ttype && heapcopy(bn, "tail", &bthp, &b->theap) 
!= GDK_SUCCEED) ||
-                           (bn->tvheap && heapcopy(bn, "theap", &thp, 
b->tvheap) != GDK_SUCCEED)) {
+                       snprintf(bthp.filename, sizeof(bthp.filename),
+                                "%s.tail", BBP_physical(bn->batCacheid));
+                       snprintf(thp.filename, sizeof(thp.filename), "%s.theap",
+                                BBP_physical(bn->batCacheid));
+                       if ((b->ttype && HEAPcopy(&bthp, &b->theap) != 
GDK_SUCCEED) ||
+                           (bn->tvheap && HEAPcopy(&thp, b->tvheap) != 
GDK_SUCCEED)) {
                                HEAPfree(&thp, 1);
                                HEAPfree(&bthp, 1);
                                BBPreclaim(bn);
@@ -2186,8 +2174,6 @@ BATassertProps(BAT *b)
                        BUN mask;
 
                        if ((hp = GDKzalloc(sizeof(Heap))) == NULL) {
-                               if (hp)
-                                       GDKfree(hp);
                                fprintf(stderr,
                                        "#BATassertProps: cannot allocate "
                                        "hash table\n");
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -30,7 +30,8 @@ unshare_string_heap(BAT *b)
                        return GDK_FAIL;
                h->parentid = b->batCacheid;
                h->farmid = BBPselectfarm(b->batRole, TYPE_str, varheap);
-               snprintf(h->filename, sizeof(h->filename), "%s.theap", 
BBP_physical(b->batCacheid));
+               snprintf(h->filename, sizeof(h->filename),
+                        "%s.theap", BBP_physical(b->batCacheid));
                if (HEAPcopy(h, b->tvheap) != GDK_SUCCEED) {
                        HEAPfree(h, 1);
                        GDKfree(h);
@@ -462,7 +463,8 @@ append_varsized_bat(BAT *b, BAT *n, BAT 
                        return GDK_FAIL;
                h->parentid = b->batCacheid;
                h->farmid = BBPselectfarm(b->batRole, b->ttype, varheap);
-               snprintf(h->filename, sizeof(h->filename), "%s.theap", 
BBP_physical(b->batCacheid));
+               snprintf(h->filename, sizeof(h->filename),
+                        "%s.theap", BBP_physical(b->batCacheid));
                if (HEAPcopy(h, b->tvheap) != GDK_SUCCEED) {
                        HEAPfree(h, 1);
                        GDKfree(h);
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -551,7 +551,8 @@ fixwkbheap(void)
                        bnme = nme;
                else
                        bnme++;
-               snprintf(filename, sizeof(filename), "BACKUP%c%s", DIR_SEP, 
bnme);
+               snprintf(filename, sizeof(filename),
+                        "BACKUP%c%s", DIR_SEP, bnme);
                if ((oldname = GDKfilepath(b->theap.farmid, BATDIR, nme, 
"tail")) == NULL ||
                    (newname = GDKfilepath(b->theap.farmid, BAKDIR, bnme, 
"tail")) == NULL ||
                    GDKcreatedir(newname) != GDK_SUCCEED ||
@@ -569,19 +570,17 @@ fixwkbheap(void)
                h1 = b->theap;
                h1.base = NULL;
                h1.dirty = 0;
-               h1.filename[0] = 0;
+               snprintf(h1.filename, sizeof(h1.filename), "%s.tail", filename);
                h2 = *b->tvheap;
                h2.base = NULL;
                h2.dirty = 0;
-               h2.filename[0] = 0;
+               snprintf(h2.filename, sizeof(h2.filename), "%s.theap", 
filename);
 
                /* load old heaps */
                if (HEAPload(&h1, filename, "tail", 0) != GDK_SUCCEED ||
                    HEAPload(&h2, filename, "theap", 0) != GDK_SUCCEED)
                        GDKfatal("fixwkbheap: cannot load old heaps for BAT 
%d\n", bid);
                /* create new heaps */
-               snprintf(b->theap.filename, sizeof(b->theap.filename), 
"%s.tail", nme);
-               snprintf(b->tvheap->filename, sizeof(b->tvheap->filename), 
"%s.theap", nme);
                if (HEAPalloc(&b->theap, b->batCapacity, SIZEOF_VAR_T) != 
GDK_SUCCEED)
                        GDKfatal("fixwkbheap: cannot allocate heap\n");
                b->theap.dirty = TRUE;
@@ -718,7 +717,7 @@ fixstroffheap(BAT *b, int *restrict offs
                h2.free = b->tvheap->free;
                /* load old offset heap and copy contents to new heap */
                h1 = *b->tvheap;
-               h1.filename[0] = 0;
+               snprintf(h1.filename, sizeof(h1.filename), "%s.theap", 
filename);
                h1.base = NULL;
                h1.dirty = 0;
                if (HEAPload(&h1, filename, "theap", 0) != GDK_SUCCEED)
@@ -745,7 +744,7 @@ fixstroffheap(BAT *b, int *restrict offs
                GDKfatal("fixstroffheap: cannot make backup of %s.tail\n", nme);
        /* load old offset heap */
        h1 = b->theap;
-       h1.filename[0] = 0;
+       snprintf(h1.filename, sizeof(h1.filename), "%s.tail", filename);
        h1.base = NULL;
        h1.dirty = 0;
        if (HEAPload(&h1, filename, "tail", 0) != GDK_SUCCEED)
@@ -928,7 +927,7 @@ fixfltheap(BAT *b)
                GDKfatal("fixfltheap: cannot make backup of %s.tail\n", nme);
        /* load old heap */
        h1 = b->theap;
-       h1.filename[0] = 0;
+       snprintf(h1.filename, sizeof(h1.filename), "%s.tail", filename);
        h1.base = NULL;
        h1.dirty = 0;
        if (HEAPload(&h1, filename, "tail", 0) != GDK_SUCCEED)
@@ -1115,7 +1114,7 @@ headheapinit(oid *hseq, const char *buf,
 }
 
 static int
-heapinit(BAT *b, const char *buf, int *hashash, const char *HT, int 
bbpversion, bat bid)
+heapinit(BAT *b, const char *buf, int *hashash, const char *HT, int 
bbpversion, bat bid, const char *filename)
 {
        int t;
        char type[11];
@@ -1194,7 +1193,8 @@ heapinit(BAT *b, const char *buf, int *h
        b->theap.free = (size_t) free;
        b->theap.size = (size_t) size;
        b->theap.base = NULL;
-       b->theap.filename[0] = 0;
+       snprintf(b->theap.filename, sizeof(b->theap.filename),
+                "%s.tail", filename);
        b->theap.storage = (storage_t) storage;
        b->theap.copied = 0;
        b->theap.newstorage = (storage_t) storage;
@@ -1206,7 +1206,7 @@ heapinit(BAT *b, const char *buf, int *h
 }
 
 static int
-vheapinit(BAT *b, const char *buf, int hashash, bat bid)
+vheapinit(BAT *b, const char *buf, int hashash, bat bid, const char *filename)
 {
        int n = 0;
        lng free, size;
@@ -1224,7 +1224,8 @@ vheapinit(BAT *b, const char *buf, int h
                b->tvheap->free = (size_t) free;
                b->tvheap->size = (size_t) size;
                b->tvheap->base = NULL;
-               b->tvheap->filename[0] = 0;
+               snprintf(b->tvheap->filename, sizeof(b->tvheap->filename),
+                        "%s.theap", filename);
                b->tvheap->storage = (storage_t) storage;
                b->tvheap->copied = 0;
                b->tvheap->hashash = hashash != 0;
@@ -1349,8 +1350,8 @@ BBPreadEntries(FILE *fp, int bbpversion)
                                GDKfatal("BBPinit: head seqbase out of range 
(ID = "LLFMT", seq = "LLFMT").", batid, base);
                        bn->hseqbase = (oid) base;
                }
-               nread += heapinit(bn, buf + nread, &Thashash, "T", bbpversion, 
bid);
-               nread += vheapinit(bn, buf + nread, Thashash, bid);
+               nread += heapinit(bn, buf + nread, &Thashash, "T", bbpversion, 
bid, filename);
+               nread += vheapinit(bn, buf + nread, Thashash, bid, filename);
 
                if (bbpversion <= GDKLIBRARY_NOKEY &&
                    (bn->tnokey[0] != 0 || bn->tnokey[1] != 0)) {
@@ -3168,8 +3169,7 @@ heap_move(Heap *hp, const char *srcdir, 
                /* dont overwrite heap with the committed state
                 * already in dstdir */
                return GDK_SUCCEED;
-       } else if (hp->filename[0] &&
-                  hp->newstorage == STORE_PRIV &&
+       } else if (hp->newstorage == STORE_PRIV &&
                   !file_exists(hp->farmid, srcdir, nme, ext)) {
 
                /* In order to prevent half-saved X.new files
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -109,15 +109,14 @@ HEAPalloc(Heap *h, size_t nitems, size_t
                GDKerror("HEAPalloc: allocating more than heap can 
accomodate\n");
                return GDK_FAIL;
        }
-       if (h->filename[0] == 0 ||
-           h->size < 4 * GDK_mmap_pagesize ||
+       if (h->size < 4 * GDK_mmap_pagesize ||
            (GDKmem_cursize() + h->size < GDK_mem_maxsize &&
             h->size < (h->farmid == 0 ? GDK_mmap_minsize_persistent : 
GDK_mmap_minsize_transient))) {
                h->storage = STORE_MEM;
                h->base = (char *) GDKmalloc(h->size);
                HEAPDEBUG fprintf(stderr, "#HEAPalloc " SZFMT " " PTRFMT "\n", 
h->size, PTRFMTCAST h->base);
        }
-       if (h->filename[0] && h->base == NULL) {
+       if (h->base == NULL) {
                char *nme;
                struct stat st;
 
@@ -213,7 +212,7 @@ HEAPextend(Heap *h, size_t size, int may
                 * file-mapped storage */
                Heap bak = *h;
                int exceeds_swap = size >= 4 * GDK_mmap_pagesize && size + 
GDKmem_cursize() >= GDK_mem_maxsize;
-               int must_mmap = h->filename[0] != 0 && (exceeds_swap || 
h->newstorage != STORE_MEM || size >= (h->farmid == 0 ? 
GDK_mmap_minsize_persistent : GDK_mmap_minsize_transient));
+               int must_mmap = exceeds_swap || h->newstorage != STORE_MEM || 
size >= (h->farmid == 0 ? GDK_mmap_minsize_persistent : 
GDK_mmap_minsize_transient);
 
                h->size = size;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to