Changeset: e6303b941aa1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e6303b941aa1
Modified Files:
        gdk/gdk_bat.c
        gdk/gdk_bbp.c
        gdk/gdk_imprints.c
        gdk/gdk_private.h
        gdk/gdk_search.c
Branch: Jul2015
Log Message:

When unloading a BAT, only unload, not destroy, imprints and hashes.
This also means we need to recognize a previously created hash when we
need one, and that we need to explicitly remove the heap files when an
index does need to get destroyed.


diffs (202 lines):

diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -614,8 +614,8 @@ BATfree(BAT *b)
        if (b->T->props)
                PROPdestroy(b->T->props);
        b->T->props = NULL;
-       HASHdestroy(b);
-       IMPSdestroy(b);
+       HASHfree(b);
+       IMPSfree(b);
        if (b->htype)
                HEAPfree(&b->H->heap, 0);
        else
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -3872,8 +3872,12 @@ BBPdiskscan(const char *parent)
                        delete = (b == NULL || !b->T->vheap || 
b->batCopiedtodisk == 0);
                } else if (strncmp(p + 1, "hhash", 5) == 0 ||
                           strncmp(p + 1, "thash", 5) == 0) {
+#ifdef PERSISTENTHASH
                        BAT *b = getdesc(bid);
                        delete = b == NULL;
+#else
+                       delete = TRUE;
+#endif
                } else if (strncmp(p + 1, "himprints", 9) == 0 ||
                           strncmp(p + 1, "timprints", 9) == 0) {
                        BAT *b = getdesc(bid);
diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -988,18 +988,47 @@ void
 IMPSdestroy(BAT *b)
 {
        if (b) {
-               if (b->T->imprints != NULL && !VIEWtparent(b)) {
+               if (b->T->imprints != NULL && !VIEWtparent(b))
                        IMPSremove(b);
-               }
+               else
+                       GDKunlink(BBPselectfarm(b->batRole, b->ttype, 
imprintsheap),
+                                 BATDIR,
+                                 BBP_physical(b->batCacheid),
+                                 "timprints");
 
-               if (b->H->imprints != NULL && !VIEWhparent(b)) {
+               if (b->H->imprints != NULL && !VIEWhparent(b))
                        IMPSremove(BATmirror(b));
-               }
+               else
+                       GDKunlink(BBPselectfarm(b->batRole, b->htype, 
imprintsheap),
+                                 BATDIR,
+                                 BBP_physical(b->batCacheid),
+                                 "himprints");
        }
 
        return;
 }
 
+/* free the memory associated with the imprints, do not remove the
+ * heap files */
+void
+IMPSfree(BAT *b)
+{
+       Imprints *imprints;
+
+       if (b) {
+               MT_lock_set(&GDKimprintsLock(abs(b->batCacheid)), "IMPSdelete");
+               if ((imprints = b->T->imprints) != NULL) {
+                       b->T->imprints = NULL;
+                       if (!VIEWtparent(b)) {
+                               HEAPfree(imprints->imprints, 0);
+                               GDKfree(imprints->imprints);
+                               GDKfree(imprints);
+                       }
+               }
+               MT_lock_unset(&GDKimprintsLock(abs(b->batCacheid)), 
"IMPSdelete");
+       }
+}
+
 #ifndef NDEBUG
 /* never called, useful for debugging */
 
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -135,6 +135,8 @@ void BBPdump(void);         /* never called: fo
        __attribute__((__visibility__("hidden")));
 __hidden gdk_return GDKunlink(int farmid, const char *dir, const char *nme, 
const char *extension)
        __attribute__((__visibility__("hidden")));
+__hidden void HASHfree(BAT *b)
+       __attribute__((__visibility__("hidden")));
 __hidden int HASHgonebad(BAT *b, const void *v)
        __attribute__((__visibility__("hidden")));
 __hidden BUN HASHmask(BUN cnt)
@@ -161,6 +163,8 @@ void BBPdump(void);         /* never called: fo
        __attribute__((__visibility__("hidden")));
 __hidden void IMPSdestroy(BAT *b)
        __attribute__((__visibility__("hidden")));
+__hidden void IMPSfree(BAT *b)
+       __attribute__((__visibility__("hidden")));
 __hidden int IMPSgetbin(int tpe, bte bits, const char *restrict bins, const 
void *restrict v)
        __attribute__((__visibility__("hidden")));
 #ifndef NDEBUG
diff --git a/gdk/gdk_search.c b/gdk/gdk_search.c
--- a/gdk/gdk_search.c
+++ b/gdk/gdk_search.c
@@ -237,8 +237,6 @@ BATcheckhash(BAT *b)
        t = GDKusec();
        MT_lock_set(&GDKhashLock(abs(b->batCacheid)), "BATcheckhash");
        t = GDKusec() - t;
-// use or ignore a persistent hash
-#ifdef PERSISTENTHASH
        if (b->T->hash == NULL) {
                Hash *h;
                Heap *hp;
@@ -258,7 +256,11 @@ BATcheckhash(BAT *b)
 
                                if ((h = GDKmalloc(sizeof(*h))) != NULL &&
                                    read(fd, hdata, sizeof(hdata)) == 
sizeof(hdata) &&
-                                   hdata[0] == (((size_t) 1 << 24) | 
HASH_VERSION) &&
+                                   hdata[0] == (
+#ifdef PERSISTENTHASH
+                                           ((size_t) 1 << 24) |
+#endif
+                                           HASH_VERSION) &&
                                    hdata[4] == (size_t) BATcount(b) &&
                                    fstat(fd, &st) == 0 &&
                                    st.st_size >= (off_t) (hp->size = hp->free 
= (hdata[1] + hdata[2]) * hdata[3] + HASH_HEADER_SIZE * SIZEOF_SIZE_T) &&
@@ -300,7 +302,6 @@ BATcheckhash(BAT *b)
                }
                GDKfree(hp);
        }
-#endif
        ret = b->T->hash != NULL;
        MT_lock_unset(&GDKhashLock(abs(b->batCacheid)), "BATcheckhash");
        ALGODEBUG if (ret) fprintf(stderr, "#BATcheckhash: already has hash %d, 
waited " LLFMT " usec\n", b->batCacheid, t);
@@ -590,21 +591,28 @@ HASHlist(Hash *h, BUN i)
 void
 HASHremove(BAT *b)
 {
-       if (b && b->T->hash) {
-               bat p = -VIEWtparent(b);
-               BAT *hp = NULL;
+       if (b) {
+               if (b->T->hash) {
+                       bat p = -VIEWtparent(b);
+                       BAT *hp = NULL;
 
-               if (p)
-                       hp = BBP_cache(p);
+                       if (p)
+                               hp = BBP_cache(p);
 
-               if ((!hp || b->T->hash != hp->T->hash) && b->T->hash != (Hash 
*) -1) {
-                       ALGODEBUG if (*(size_t *) b->T->hash->heap->base & (1 
<< 24))
-                               fprintf(stderr, "#HASHremove: removing 
persisted hash %d\n", b->batCacheid);
-                       HEAPfree(b->T->hash->heap, 1);
-                       GDKfree(b->T->hash->heap);
-                       GDKfree(b->T->hash);
+                       if ((!hp || b->T->hash != hp->T->hash) && b->T->hash != 
(Hash *) -1) {
+                               ALGODEBUG if (*(size_t *) 
b->T->hash->heap->base & (1 << 24))
+                                       fprintf(stderr, "#HASHremove: removing 
persisted hash %d\n", b->batCacheid);
+                               HEAPfree(b->T->hash->heap, 1);
+                               GDKfree(b->T->hash->heap);
+                               GDKfree(b->T->hash);
+                       }
+                       b->T->hash = NULL;
+               } else {
+                       GDKunlink(BBPselectfarm(b->batRole, b->ttype, hashheap),
+                                 BATDIR,
+                                 BBP_physical(b->batCacheid),
+                                 b->batCacheid > 0 ? "thash" : "hhash");
                }
-               b->T->hash = NULL;
        }
 }
 
@@ -619,6 +627,21 @@ HASHdestroy(BAT *b)
        }
 }
 
+void
+HASHfree(BAT *b)
+{
+       if (b) {
+               MT_lock_set(&GDKhashLock(abs(b->batCacheid)), "HASHfree");
+               if (b->T->hash && b->T->hash != (Hash *) -1) {
+                       HEAPfree(b->T->hash->heap, 0);
+                       GDKfree(b->T->hash->heap);
+                       GDKfree(b->T->hash);
+               }
+               b->T->hash = NULL;
+               MT_lock_unset(&GDKhashLock(abs(b->batCacheid)), "HASHfree");
+       }
+}
+
 int
 HASHgonebad(BAT *b, const void *v)
 {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to