Changeset: a3af2f13d0cb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a3af2f13d0cb
Modified Files:
        gdk/gdk.h
        gdk/gdk_mosaic.c
        monetdb5/modules/mosaic/mosaic.c
        monetdb5/modules/mosaic/mosaic.h
        monetdb5/modules/mosaic/mosaic_calendar.c
        monetdb5/modules/mosaic/mosaic_calendar.h
        monetdb5/modules/mosaic/mosaic_delta.c
        monetdb5/modules/mosaic/mosaic_delta.h
        monetdb5/modules/mosaic/mosaic_dictionary.c
        monetdb5/modules/mosaic/mosaic_dictionary.h
        monetdb5/modules/mosaic/mosaic_frame.c
        monetdb5/modules/mosaic/mosaic_frame.h
        monetdb5/modules/mosaic/mosaic_hdr.c
        monetdb5/modules/mosaic/mosaic_hdr.h
        monetdb5/modules/mosaic/mosaic_linear.c
        monetdb5/modules/mosaic/mosaic_linear.h
        monetdb5/modules/mosaic/mosaic_prefix.c
        monetdb5/modules/mosaic/mosaic_prefix.h
        monetdb5/modules/mosaic/mosaic_raw.c
        monetdb5/modules/mosaic/mosaic_raw.h
        monetdb5/modules/mosaic/mosaic_runlength.c
        monetdb5/modules/mosaic/mosaic_runlength.h
        sql/backends/monet5/sql_cat.c
        sql/backends/monet5/sql_mosaic.c
        sql/test/mosaic/Tests/All
Branch: mosaic
Log Message:

Major clean up:
Use a gdk like signature for MOS(de)compressInternal functions.
Remove the Client object dependency for non pattern-like mal exported functions.
Remove the global maintenance lock and use GDK heap style lock when appropriate.
Remove various debug code.


diffs (truncated from 3529 to 300 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1828,6 +1828,8 @@ gdk_export gdk_return BAThash(BAT *b);
 gdk_export gdk_return BATmosaic(BAT *b, BUN cap);
 gdk_export void MOSdestroy(BAT *b);
 gdk_export int BATcheckmosaic(BAT *b);
+gdk_export void MOSsetLock(BAT* b);
+gdk_export void MOSunsetLock(BAT* b);
 
 /*
  * @- Column Imprints Functions
diff --git a/gdk/gdk_mosaic.c b/gdk/gdk_mosaic.c
--- a/gdk/gdk_mosaic.c
+++ b/gdk/gdk_mosaic.c
@@ -14,6 +14,14 @@
 #include "gdk.h"
 #include "gdk_private.h"
 
+void MOSsetLock(BAT* b) {
+       MT_lock_set(&GDKmosaicLock(b->batCacheid));
+}
+
+void MOSunsetLock(BAT* b) {
+       MT_lock_unset(&GDKmosaicLock(b->batCacheid));
+}
+
 #ifdef PERSISTENTMOSAIC
 struct mosaicsync {
     Heap *hp;
@@ -61,9 +69,7 @@ BATmosaic(BAT *bn, BUN cap)
        Heap *m;
        char *fname = 0;
 
-    MT_lock_set(&GDKmosaicLock(bn->batCacheid));
        if( bn->tmosaic){
-               MT_lock_unset(&GDKmosaicLock(bn->batCacheid));
                return GDK_SUCCEED;
        }
 
@@ -74,13 +80,11 @@ BATmosaic(BAT *bn, BUN cap)
                        if( fname)
                                GDKfree(fname);
                        GDKfree(m);
-                       MT_lock_unset(&GDKmosaicLock(bn->batCacheid));
                        return GDK_FAIL;
                }
        strncpy(m->filename, fname, sizeof(m->filename));
        
     if( HEAPalloc(m, cap, Tsize(bn)) != GDK_SUCCEED){
-               MT_lock_unset(&GDKmosaicLock(bn->batCacheid));
         return GDK_FAIL;
        }
     m->parentid = bn->batCacheid;
@@ -101,7 +105,6 @@ BATmosaic(BAT *bn, BUN cap)
 #endif
        bn->batDirtydesc = TRUE;
        bn->tmosaic = m;
-       MT_lock_unset(&GDKmosaicLock(bn->batCacheid));
     return GDK_SUCCEED;
 }
 
@@ -134,7 +137,6 @@ BATcheckmosaic(BAT *b)
 
        assert(b->batCacheid > 0);
        t = GDKusec();
-       MT_lock_set(&GDKmosaicLock(b->batCacheid));
        t = GDKusec() - t;
        if (b->tmosaic == (Heap *) 1) {
                Heap *hp;
@@ -161,7 +163,6 @@ BATcheckmosaic(BAT *b)
                                        close(fd);
                                        b->tmosaic = hp;
                                        ALGODEBUG fprintf(stderr, 
"#BATcheckmosaic: reusing persisted mosaic %d\n", b->batCacheid);
-                                       
MT_lock_unset(&GDKmosaicLock(b->batCacheid));
                                        return 1;
                                }
                                close(fd);
@@ -174,7 +175,6 @@ BATcheckmosaic(BAT *b)
                GDKclrerr();    /* we're not currently interested in errors */
        }
        ret = b->tmosaic != NULL;
-       MT_lock_unset(&GDKmosaicLock(b->batCacheid));
        ALGODEBUG if (ret) fprintf(stderr, "#BATcheckmosaic: already has mosaic 
%d, waited " LLFMT " usec\n", b->batCacheid, t);
        return ret;
 }
diff --git a/monetdb5/modules/mosaic/mosaic.c b/monetdb5/modules/mosaic/mosaic.c
--- a/monetdb5/modules/mosaic/mosaic.c
+++ b/monetdb5/modules/mosaic/mosaic.c
@@ -52,7 +52,7 @@ MOSinitializeFilter(MOStask task, const 
        }
        else {
                for(int i = 0; i< MOSAIC_METHODS-1; i++) {
-                               task->filter[i] = 1;
+                               task->filter[i] = type_allowed(i, task->bsrc);
                                task->hdr->elms[i] = task->hdr->blks[i] = 0;
                }
        }
@@ -81,7 +81,7 @@ void MOSblk(MosaicBlk blk)
 }
 
 str
-MOSlayout(Client cntxt, BAT *b, BAT *btech, BAT *bcount, BAT *binput, BAT 
*boutput, BAT *bproperties)
+MOSlayout(BAT *b, BAT *btech, BAT *bcount, BAT *binput, BAT *boutput, BAT 
*bproperties)
 {
        MOStask task=0;
        int i;
@@ -96,7 +96,7 @@ MOSlayout(Client cntxt, BAT *b, BAT *bte
                        throw(MAL,"mosaic.layout","Compression heap missing");
 
        MOSinit(task,b);
-       MOSinitializeScan(cntxt,task,0,task->hdr->top);
+       MOSinitializeScan(task,0,task->hdr->top);
        // safe the general properties
 
                snprintf(buf,BUFSIZ,"%g", task->hdr->ratio);
@@ -117,11 +117,11 @@ MOSlayout(Client cntxt, BAT *b, BAT *bte
                                throw(MAL,"mosaic.layout", MAL_MALLOC_FAIL);
        }
        if( task->hdr->blks[MOSAIC_FRAME])
-               
MOSlayout_frame_hdr(cntxt,task,btech,bcount,binput,boutput,bproperties);
+               
MOSlayout_frame_hdr(task,btech,bcount,binput,boutput,bproperties);
        if( task->hdr->blks[MOSAIC_DICT])
-               
MOSlayout_dictionary_hdr(cntxt,task,btech,bcount,binput,boutput,bproperties);
+               
MOSlayout_dictionary_hdr(task,btech,bcount,binput,boutput,bproperties);
        if( task->hdr->blks[MOSAIC_CALENDAR])
-               
MOSlayout_calendar(cntxt,task,btech,bcount,binput,boutput,bproperties);
+               
MOSlayout_calendar(task,btech,bcount,binput,boutput,bproperties);
 
        if( BUNappend(btech, "========", false) != GDK_SUCCEED ||
                BUNappend(bcount, &zero, false) != GDK_SUCCEED ||
@@ -133,36 +133,36 @@ MOSlayout(Client cntxt, BAT *b, BAT *bte
        while(task->start< task->stop){
                switch(MOSgetTag(task->blk)){
                case MOSAIC_RAW:
-                       
MOSlayout_raw(cntxt,task,btech,bcount,binput,boutput,bproperties);
-                       MOSadvance_raw(cntxt,task);
+                       
MOSlayout_raw(task,btech,bcount,binput,boutput,bproperties);
+                       MOSadvance_raw(task);
                        break;
                case MOSAIC_RLE:
-                       
MOSlayout_runlength(cntxt,task,btech,bcount,binput,boutput,bproperties);
-                       MOSadvance_runlength(cntxt,task);
+                       
MOSlayout_runlength(task,btech,bcount,binput,boutput,bproperties);
+                       MOSadvance_runlength(task);
                        break;
                case MOSAIC_DICT:
-                       
MOSlayout_dictionary(cntxt,task,btech,bcount,binput,boutput,bproperties);
-                       MOSadvance_dictionary(cntxt,task);
+                       
MOSlayout_dictionary(task,btech,bcount,binput,boutput,bproperties);
+                       MOSadvance_dictionary(task);
                        break;
                case MOSAIC_DELTA:
-                       
MOSlayout_delta(cntxt,task,btech,bcount,binput,boutput,bproperties);
-                       MOSadvance_delta(cntxt,task);
+                       
MOSlayout_delta(task,btech,bcount,binput,boutput,bproperties);
+                       MOSadvance_delta(task);
                        break;
                case MOSAIC_LINEAR:
-                       
MOSlayout_linear(cntxt,task,btech,bcount,binput,boutput,bproperties);
-                       MOSadvance_linear(cntxt,task);
+                       
MOSlayout_linear(task,btech,bcount,binput,boutput,bproperties);
+                       MOSadvance_linear(task);
                        break;
                case MOSAIC_FRAME:
-                       
MOSlayout_frame(cntxt,task,btech,bcount,binput,boutput,bproperties);
-                       MOSadvance_frame(cntxt,task);
+                       
MOSlayout_frame(task,btech,bcount,binput,boutput,bproperties);
+                       MOSadvance_frame(task);
                        break;
                case MOSAIC_PREFIX:
-                       
MOSlayout_prefix(cntxt,task,btech,bcount,binput,boutput,bproperties);
-                       MOSadvance_prefix(cntxt,task);
+                       
MOSlayout_prefix(task,btech,bcount,binput,boutput,bproperties);
+                       MOSadvance_prefix(task);
                        break;
                case MOSAIC_CALENDAR:
-                       
MOSlayout_calendar(cntxt,task,btech,bcount,binput,boutput,bproperties);
-                       MOSadvance_calendar(cntxt,task);
+                       
MOSlayout_calendar(task,btech,bcount,binput,boutput,bproperties);
+                       MOSadvance_calendar(task);
                        break;
                default:
                        assert(0);
@@ -189,68 +189,67 @@ MOSlayout(Client cntxt, BAT *b, BAT *bte
  * sequence is found with high compression factor.
  */
 static int
-MOSoptimizerCost(Client cntxt, MOStask task, int typewidth)
+MOSoptimizerCost(MOStask task, int typewidth)
 {
        int cand = MOSAIC_RAW;
        float ratio = 1.0, fac = 1.0;
 
        // select candidate amongst those
        if ( task->filter[MOSAIC_RLE]){
-               fac = MOSestimate_runlength(cntxt,task);
+               fac = MOSestimate_runlength(task);
                if (fac > ratio){
                        cand = MOSAIC_RLE;
                        ratio = fac;
                }
        }
        if ( task->filter[MOSAIC_LINEAR]){
-               fac = MOSestimate_linear(cntxt,task);
+               fac = MOSestimate_linear(task);
                if ( fac >ratio){
                        cand = MOSAIC_LINEAR;
                        ratio = fac;
                }
        }
        if (ratio < typewidth && task->filter[MOSAIC_PREFIX]){
-               fac = MOSestimate_prefix(cntxt,task);
+               fac = MOSestimate_prefix(task);
                if ( fac > ratio ){
                        cand = MOSAIC_PREFIX;
                        ratio = fac;
                }
        }
        if (ratio < 64 && task->filter[MOSAIC_DICT]){
-               fac = MOSestimate_dictionary(cntxt,task);
+               fac = MOSestimate_dictionary(task);
                if (fac > ratio){
                        cand = MOSAIC_DICT;
                        ratio = fac;
                }
        }
        if (ratio < 64 && task->filter[MOSAIC_FRAME]){
-               fac = MOSestimate_frame(cntxt,task);
+               fac = MOSestimate_frame(task);
                if (fac > ratio){
                        cand = MOSAIC_FRAME;
                        ratio = fac;
                }
        }
        if (ratio < 64 && task->filter[MOSAIC_DELTA]){
-               fac = MOSestimate_delta(cntxt,task);
+               fac = MOSestimate_delta(task);
                if ( fac > ratio ){
                        cand = MOSAIC_DELTA;
                        ratio = fac;
                }
        }
        if (ratio < 64 && task->filter[MOSAIC_CALENDAR]){
-               fac = MOSestimate_calendar(cntxt,task);
+               fac = MOSestimate_calendar(task);
                if (fac > ratio){
                        cand = MOSAIC_CALENDAR;
                        ratio = fac;
                }
        }
-       //mnstr_printf(cntxt->fdout,"#cand %d factor %f\n",cand,ratio);
        return cand;
 }
 
 /* the source is extended with a BAT mosaic heap */
 str
-MOScompressInternal(Client cntxt, BAT* bsrc, const char* compressions)
+MOScompressInternal(BAT* bsrc, const char* compressions)
 {
        MOStask task;
        BAT *o = NULL;          // the BAT to be augmented with a compressed 
heap
@@ -279,21 +278,23 @@ MOScompressInternal(Client cntxt, BAT* b
                return MAL_SUCCEED;
        }
 
-    if (BATcheckmosaic(bsrc)){
+       MOSsetLock(bsrc);
+
+  if (BATcheckmosaic(bsrc)){
                /* already compressed */
+
+               MOSunsetLock(bsrc);
                return MAL_SUCCEED;
        }
     assert(bsrc->tmosaic == NULL);
 
-       if ( BATcount(bsrc) < MOSAIC_THRESHOLD  ){
+       if ( BATcount(bsrc) < MOSAIC_THRESHOLD ){
                /* no need to compress */
+               MOSunsetLock(bsrc);
                return MAL_SUCCEED;
        }
 
-#ifdef _DEBUG_MOSAIC_
-       mnstr_printf(cntxt->fdout,"#compress bat %d \n",bsrc->batCacheid);
-#endif
-    t0 = GDKusec();
+  t0 = GDKusec();
 
        if(BATmosaic(bsrc,  BATcapacity(bsrc) + (MosaicHdrSize + 2 * 
MosaicBlkSize)/Tsize(bsrc)+ BATTINY) == GDK_FAIL){
                // create the mosaic heap if not available.
@@ -302,12 +303,14 @@ MOScompressInternal(Client cntxt, BAT* b
                // Then we total size may go beyond the original size and we 
should terminate the process.
                // This should be detected before we compress a block, in the 
estimate functions
                // or when we extend the non-compressed collector block
+               MOSunsetLock(bsrc);
                throw(MAL,"mosaic.compress", "heap construction failes");
        }
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to