Changeset: 3d55f64b5d3b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3d55f64b5d3b
Modified Files:
        MonetDB/src/gdk/gdk.mx
        MonetDB/src/gdk/gdk_logger.mx
        MonetDB/src/gdk/gdk_tm.mx
        MonetDB4/src/monet/monet_interpreter.mx
        MonetDB5/src/mal/mal_authorize.mx
        MonetDB5/src/modules/mal/bpm.mx
        MonetDB5/src/modules/mal/statistics.mx
        MonetDB5/src/optimizer/opt_dictionary.mx
        MonetDB5/src/optimizer/opt_statistics.mx
Branch: default
Log Message:

More efficient internal TMsubcommit.

Internally, TMsubcommit is usually called between creating and filling
a new BAT and destroying that BAT.  That BAT is filled with names
which are looked up given a BAT ID, and then TMsubcommit converts
those names back to the selfsame BAT IDs.  This can be done more
efficiently.

We introduce a new function TMsubcommit_list with two parameters: an
array of BAT IDs, and a count.  Because of BBP-internal reasons, the
first element of the array is unused (and must be 0).  The count is
the number of BAT IDs, including the unused 0.

TMsubcommit now does the same as before, looking up BAT IDs and
putting them into an array.  Except now, TMsubcommit calls the new
function to do the "real" work.  This function can also be called from
other parts of the code.

By calling TMsubcommit_list, we now save on the creation and
destruction of temporary string BATs and concomitant locking, and we
save on the lookup of BAT names to find BAT IDs.

Note that this change only affects C code.  The MIL and MAL interfaces
remain identical.


diffs (truncated from 387 to 300 lines):

diff -r d9b987956b70 -r 3d55f64b5d3b MonetDB/src/gdk/gdk.mx
--- a/MonetDB/src/gdk/gdk.mx    Fri Jul 02 13:23:44 2010 +0200
+++ b/MonetDB/src/gdk/gdk.mx    Fri Jul 02 14:17:05 2010 +0200
@@ -2875,6 +2875,7 @@
 gdk_export int TMcommit(void);
 gdk_export int TMabort(void);
 gdk_export int TMsubcommit(BAT *bl);
+gdk_export int TMsubcommit_list(bat *subcommit, int cnt);
 
 @
 @}
diff -r d9b987956b70 -r 3d55f64b5d3b MonetDB/src/gdk/gdk_logger.mx
--- a/MonetDB/src/gdk/gdk_logger.mx     Fri Jul 02 13:23:44 2010 +0200
+++ b/MonetDB/src/gdk/gdk_logger.mx     Fri Jul 02 14:17:05 2010 +0200
@@ -1006,33 +1006,34 @@
 bm_subcommit(BAT *list, BAT *catalog, BAT *extra, int debug)
 {
        BUN p, q;
-       BAT *n = logbat_new(TYPE_void, TYPE_str, BATcount(list) * 2 + (extra ? 
BATcount(extra) : 0));
+       /* using alloca, since the old TMsubcommit interface also uses
+          alloca */
+       bat *n = alloca(sizeof(bat) * (1 + BATcount(list) * 2 + (extra ? 
BATcount(extra) : 0)));
+       int i = 0;
        BAT *b = list;
        BATiter bi = bat_iterator(b);
        int res;
 
-       BATseqbase(n, 0);
+       n[i++] = 0;
 
        /* first loop over deleted then over current and new */
        for (p = b->batDeleted; p < b->batFirst; p++) {
                bat col = *(log_bid *) BUNhead(bi, p);
-               str name = BBPname(col);
 
                if (debug & 1)
                        fprintf(stderr, "commit deleted %s (%d) %s\n",
-                               name, col,
+                               BBPname(col), col,
                                (b == catalog) ? BUNtail(bi, p) : "snapshot");
-               BUNappend(n, name, FALSE);
+               n[i++] = ABS(col);
        }
        BATloop(b, p, q) {
                bat col = *(log_bid *) BUNhead(bi, p);
-               str name = BBPname(col);
 
                if (debug & 1)
                        fprintf(stderr, "commit new %s (%d) %s\n",
-                               name, col,
+                               BBPname(col), col,
                                (b == catalog) ? BUNtail(bi, p) : "snapshot");
-               BUNappend(n, name, FALSE);
+               n[i++] = ABS(col);
        }
        if (extra) {
                bi = bat_iterator(extra);
@@ -1043,14 +1044,13 @@
                                fprintf(stderr, "commit extra %s %s\n",
                                        name,
                                        (b == catalog) ? BUNtail(bi, p) : 
"snapshot");
-                       BUNappend(n, name, FALSE);
+                       n[i++] = ABS(BBPindex(name));
                }
        }
        /* now commit catalog, so it's also up to date on disk */
-       BUNappend(n, BBPname(catalog->batCacheid), FALSE);
+       n[i++] = ABS(catalog->batCacheid);
        BATcommit(catalog);
-       res = TMsubcommit(n);
-       BBPreclaim(n);
+       res = TMsubcommit_list(n, i);
        return res;
 }
 
diff -r d9b987956b70 -r 3d55f64b5d3b MonetDB/src/gdk/gdk_tm.mx
--- a/MonetDB/src/gdk/gdk_tm.mx Fri Jul 02 13:23:44 2010 +0200
+++ b/MonetDB/src/gdk/gdk_tm.mx Fri Jul 02 14:17:05 2010 +0200
@@ -168,25 +168,17 @@
 ongoing concurrent query and update facilities than a real global TMcommit.
 @c
 int
-TMsubcommit(BAT *b)
+TMsubcommit_list(bat *subcommit, int cnt)
 {
-       int xx, ret = -1, cnt = 1;      /* BBP artifact: slot 0 in the array 
will be ignored */
-       bat *subcommit = (bat *) alloca((BATcount(b) + 1) * sizeof(bat));
-       BUN p, q;
-       BATiter bi = bat_iterator(b);
+       int xx, ret = -1;
 
-       /* collect the list and save the new bats outside any locking */
-       BATloop(b, p, q) {
-               bat bid = BBPindex((str) BUNtail(bi, p));
+       assert(cnt > 0);
+       assert(subcommit[0] == 0); /* BBP artifact: slot 0 in the array will be 
ignored */
 
-               if (bid < 0)
-                       bid = -bid;
-               if (bid)
-                       subcommit[cnt++] = bid;
-       }
        /* sort the list on BAT id */
        GDKqsort(subcommit + 1, NULL, NULL, cnt - 1, sizeof(bat), 0, TYPE_bat);
 
+       assert(cnt == 1 || subcommit[1] > 0);  /* all values > 0 */
        if (prelude(cnt, subcommit) == 0) {     /* save the new bats outside 
the lock */
                /* lock just prevents BBPtrims, and other global (sub-)commits 
*/
                for (xx = 0; xx <= BBP_THREADMASK; xx++)
@@ -200,6 +192,28 @@
        return ret;
 }
 
+int
+TMsubcommit(BAT *b)
+{
+       int cnt = 1;
+       bat *subcommit = (bat *) alloca((BATcount(b) + 1) * sizeof(bat));
+       BUN p, q;
+       BATiter bi = bat_iterator(b);
+
+       subcommit[0] = 0;       /* BBP artifact: slot 0 in the array will be 
ignored */
+       /* collect the list and save the new bats outside any locking */
+       BATloop(b, p, q) {
+               bat bid = BBPindex((str) BUNtail(bi, p));
+
+               if (bid < 0)
+                       bid = -bid;
+               if (bid)
+                       subcommit[cnt++] = bid;
+       }
+
+       return TMsubcommit_list(subcommit, cnt);
+}
+
 @- TMabort
 Transaction abort is cheap. We use the delta statuses
 to go back to the previous version of each BAT. Also
diff -r d9b987956b70 -r 3d55f64b5d3b MonetDB4/src/monet/monet_interpreter.mx
--- a/MonetDB4/src/monet/monet_interpreter.mx   Fri Jul 02 13:23:44 2010 +0200
+++ b/MonetDB4/src/monet/monet_interpreter.mx   Fri Jul 02 14:17:05 2010 +0200
@@ -502,12 +502,12 @@
 static void 
 commitProfiler(void)
 {
-       BAT *b = BATnew(TYPE_void, TYPE_str, 3);
+       bat b[3];
 
-       BUNappend(b, BBPname(profilerCount->batCacheid), FALSE);
-       BUNappend(b, BBPname(profilerTicks->batCacheid), FALSE);
-       TMsubcommit(b);
-       BBPreclaim(b);
+       b[0] = 0;
+       b[1] = ABS(profilerCount->batCacheid);
+       b[2] = ABS(profilerTicks->batCacheid);
+       TMsubcommit_list(b, 3);
 }
 
 int
diff -r d9b987956b70 -r 3d55f64b5d3b MonetDB5/src/mal/mal_authorize.mx
--- a/MonetDB5/src/mal/mal_authorize.mx Fri Jul 02 13:23:44 2010 +0200
+++ b/MonetDB5/src/mal/mal_authorize.mx Fri Jul 02 14:17:05 2010 +0200
@@ -160,18 +160,19 @@
 }
 
 void
-AUTHcommit() {
-       BAT *b = BATnew(TYPE_oid, TYPE_str, 3);
-       assert(b);
+AUTHcommit()
+{
+       bat blist[4];
+
+       blist[0] = 0;
 
        assert(user);
-       BUNappend(b, BATgetId(user), FALSE);
+       blist[1] = ABS(user->batCacheid);
        assert(pass);
-       BUNappend(b, BATgetId(pass), FALSE);
+       blist[2] = ABS(pass->batCacheid);
        assert(pass);
-       BUNappend(b, BATgetId(scen), FALSE);
-       TMsubcommit(b);
-       BBPreclaim(b);
+       blist[3] = ABS(scen->batCacheid);
+       TMsubcommit_list(blist, 4);
 }
 
 @-
@@ -219,7 +220,7 @@
        bid = BBPindex("M5system_auth_passwd");
        if (bid) {
                BAT *n;
-               BAT *s;
+               bat s[3];
 
                b = BATdescriptor(bid);
                if (b == NULL)
@@ -271,12 +272,10 @@
                BBPreleaseref(b->batCacheid);
 
                /* commit the new situation */
-               s = BATnew(TYPE_oid, TYPE_str, 2);
-               assert(s);
-               BUNappend(s, BATgetId(n), FALSE);
-               BUNappend(s, BATgetId(b), FALSE);
-               TMsubcommit(s);
-               BBPreclaim(s);
+               s[0] = 0;
+               s[1] = ABS(n->batCacheid);
+               s[2] = ABS(b->batCacheid);
+               TMsubcommit_list(s, 3);
        }
 
        /* load/create password BAT */
diff -r d9b987956b70 -r 3d55f64b5d3b MonetDB5/src/modules/mal/bpm.mx
--- a/MonetDB5/src/modules/mal/bpm.mx   Fri Jul 02 13:23:44 2010 +0200
+++ b/MonetDB5/src/modules/mal/bpm.mx   Fri Jul 02 14:17:05 2010 +0200
@@ -3001,16 +3001,18 @@
 str
 BPMsaveCatalog(int *r)
 {      
-       int i;
+       int i, n;
        bat bt,idx;
-       BAT *tr;
+       bat *tr;
        str nm;
        str msg=MAL_SUCCEED;
 
 
-       /* store bat names to be committed */
-       tr = BATnew(TYPE_void, TYPE_str, bpmcatsize+10);
-       BATseqbase(tr,0);
+       /* using alloca, since the old TMsubcommit interface also uses
+          alloca */
+       tr = alloca((bpmcatsize+10) * sizeof(bat));
+       n = 0;
+       tr[n++] = 0;
 
        for(i=1; i< bpmcatsize; i++)
                if( bpmcat[i]){
@@ -3037,32 +3039,31 @@
        
                        msg= BKCsetPersistent(r, (int *)&bt);
                        if( msg != MAL_SUCCEED) return msg;
-                       BUNappend(tr, BBPname(bt), FALSE);
+                       tr[n++] = ABS(bt);
                }
        
        BPMmapname(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
+       tr[n++] = ABS(bt);
        BPMmapalias(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
+       tr[n++] = ABS(bt);
        BPMmapbid(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
+       tr[n++] = ABS(bt);
        BPMmapnxt(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
+       tr[n++] = ABS(bt);
        BPMmapprv(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
+       tr[n++] = ABS(bt);
        BPMmapcnt(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
+       tr[n++] = ABS(bt);
        BPMmaptlowlng(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
+       tr[n++] = ABS(bt);
        BPMmaptlowdbl(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
+       tr[n++] = ABS(bt);
        BPMmapthghlng(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
+       tr[n++] = ABS(bt);
        BPMmapthghdbl(&bt);
-       BUNappend(tr, BBPname(bt), FALSE);
-
-       TMsubcommit(tr);
-       BBPreclaim(tr);
+       tr[n++] = ABS(bt);
+
+       TMsubcommit_list(tr, n);
 
        return MAL_SUCCEED;
 }
diff -r d9b987956b70 -r 3d55f64b5d3b MonetDB5/src/modules/mal/statistics.mx
--- a/MonetDB5/src/modules/mal/statistics.mx    Fri Jul 02 13:23:44 2010 +0200
+++ b/MonetDB5/src/modules/mal/statistics.mx    Fri Jul 02 14:17:05 2010 +0200
@@ -272,19 +272,19 @@
 static void
 STATcommit()
 {
-       BAT *b = BATnew(TYPE_void, TYPE_str, 10);
-       BATseqbase(b,0);
-       BUNappend(b, BBPname(STAT_id_inuse->batCacheid), FALSE);
-       BUNappend(b, BBPname(STAT_id_nme->batCacheid), FALSE);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to