Changeset: fbfa13791072 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fbfa13791072
Modified Files:
        clients/Tests/exports.stable.out
        gdk/gdk_hash.c
        gdk/gdk_hash.h
        sql/backends/monet5/sql.c
Branch: default
Log Message:

In sys.storage(), report hash size even if hash not loaded.


diffs (87 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -351,6 +351,7 @@ void *GDKzalloc(size_t size) __attribute
 void HASHdestroy(BAT *b);
 BUN HASHlist(Hash *h, BUN i);
 BUN HASHprobe(const Hash *h, const void *v);
+size_t HASHsize(BAT *b);
 void HEAP_free(Heap *heap, var_t block);
 gdk_return HEAP_initialize(Heap *heap, size_t nbytes, size_t nprivate, int 
alignment);
 var_t HEAP_malloc(BAT *b, size_t nbytes);
diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -562,6 +562,40 @@ BATcheckhash(BAT *b)
        return h != NULL;
 }
 
+/* figure out size of the hash (sum of the sizes of the two hash files)
+ * without loading them */
+size_t
+HASHsize(BAT *b)
+{
+       size_t sz = 0;
+       MT_rwlock_rdlock(&b->thashlock);
+       if (b->thash == NULL) {
+               sz = 0;
+       } else if (b->thash != (Hash *) 1) {
+               sz = b->thash->heaplink.size + b->thash->heapbckt.size;
+       } else {
+               int farmid = BBPselectfarm(b->batRole, b->ttype, hashheap);
+               if (farmid >= 0) {
+                       const char *nme = BBP_physical(b->batCacheid);
+                       char *fname = GDKfilepath(farmid, BATDIR, nme, 
"thashb");
+                       if (fname != NULL) {
+                               struct stat st;
+                               if (stat(fname, &st) == 0) {
+                                       sz = (size_t) st.st_size;
+                                       fname[strlen(fname) - 1] = 'l';
+                                       if (stat(fname, &st) == 0)
+                                               sz += (size_t) st.st_size;
+                                       else
+                                               sz = 0;
+                               }
+                               GDKfree(fname);
+                       }
+               }
+       }
+       MT_rwlock_rdunlock(&b->thashlock);
+       return sz;
+}
+
 static void
 BAThashsave_intern(BAT *b, bool dosync)
 {
diff --git a/gdk/gdk_hash.h b/gdk/gdk_hash.h
--- a/gdk/gdk_hash.h
+++ b/gdk/gdk_hash.h
@@ -37,6 +37,7 @@ gdk_export gdk_return BAThash(BAT *b);
 gdk_export void HASHdestroy(BAT *b);
 gdk_export BUN HASHprobe(const Hash *h, const void *v);
 gdk_export BUN HASHlist(Hash *h, BUN i);
+gdk_export size_t HASHsize(BAT *b);
 
 #define BUN2 2
 #define BUN4 4
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -4188,15 +4188,11 @@ sql_storage_appendrow(BAT *bs, const cha
        if (BUNappend(heap, &sz, false) != GDK_SUCCEED)
                goto bailout1;
 
-       MT_rwlock_rdlock(&bs->thashlock);
-       /* one lock, two values: hash size, and
-        * whether we (may) have a hash */
-       sz = hashinfo(bs->thash, bs->batCacheid);
-       bitval = bs->thash != NULL;
-       MT_rwlock_rdunlock(&bs->thashlock);
+       sz = (lng) HASHsize(bs);
        if (BUNappend(indices, &sz, false) != GDK_SUCCEED)
                goto bailout1;
 
+       bitval = sz > 0;
        if (BUNappend(phash, &bitval, false) != GDK_SUCCEED)
                goto bailout1;
 
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to