Changeset: e1cf355d2cfe for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e1cf355d2cfe
Modified Files:
        MonetDB5/src/modules/kernel/bat5.mx
        sql/src/backends/monet5/sql.mx
        sql/src/backends/monet5/sql_result.mx
Branch: default
Log Message:

fixes for vacuum (still we lose some tuples)


diffs (253 lines):

diff -r bb7fb0e98b41 -r e1cf355d2cfe MonetDB5/src/modules/kernel/bat5.mx
--- a/MonetDB5/src/modules/kernel/bat5.mx       Mon Dec 20 20:39:27 2010 +0100
+++ b/MonetDB5/src/modules/kernel/bat5.mx       Mon Dec 20 21:31:13 2010 +0100
@@ -3818,9 +3818,9 @@
 Shrinking a void-headed BAT using a list of oids to ignore. 
 @= shrinkloop
 {
-    @1 *p = (@1*)Tloc(b, BUNfirst(b));
-    @1 *q = (@1*)Tloc(b, BUNlast(b));
-    @1 *r = (@1*)Tloc(bn, BUNfirst(bn));
+       @1 *p = (@1*)Tloc(b, BUNfirst(b));
+       @1 *q = (@1*)Tloc(b, BUNlast(b));
+       @1 *r = (@1*)Tloc(bn, BUNfirst(bn));
 
        cnt=0;
        for (;p<q; oidx++, p++) {
@@ -3866,11 +3866,11 @@
                throw(MAL, "bat.shrink", MAL_MALLOC_FAIL );
        }
 
-    o = (oid*)Tloc(bs, BUNfirst(bs));
-    ol= (oid*)Tloc(bs, BUNlast(bs));
-
-    BATaccessBegin(d, USE_TAIL, MMAP_SEQUENTIAL);
-    BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL);
+       o = (oid*)Tloc(bs, BUNfirst(bs));
+       ol= (oid*)Tloc(bs, BUNlast(bs))-1;
+
+       BATaccessBegin(d, USE_TAIL, MMAP_SEQUENTIAL);
+       BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL);
        switch(ATOMstorage(b->ttype) ){
        case TYPE_chr: @:shrinkloop(chr)@ break;
        case TYPE_bte: @:shrinkloop(bte)@ break;
@@ -3890,17 +3890,17 @@
                        throw(MAL, "bat.shrink", "Illegal argument type");
                }
        }
-    BATaccessEnd(d, USE_TAIL, MMAP_SEQUENTIAL);
-    BATaccessEnd(b, USE_TAIL, MMAP_SEQUENTIAL);
-
-    BATsetcount(bn, cnt);
-    bn->tsorted = 0;
-    bn->tdense = 0;
+       BATaccessEnd(d, USE_TAIL, MMAP_SEQUENTIAL);
+       BATaccessEnd(b, USE_TAIL, MMAP_SEQUENTIAL);
+
+       BATsetcount(bn, cnt);
+       bn->tsorted = 0;
+       bn->tdense = 0;
        bn->tkey = b->tkey;
        bn->T->nonil = b->T->nonil;
        bn->T->nil = b->T->nil;
 
-    if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
+       if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
 
        BBPreleaseref(b->batCacheid);
        BBPreleaseref(d->batCacheid);
@@ -3946,9 +3946,10 @@
                throw(MAL, "bat.shrinkMap", MAL_MALLOC_FAIL );
        }
 
-    o = (oid*)Tloc(bs, BUNfirst(bs));
-    ol= (oid*)Tloc(bs, BUNlast(bs));
-    r = (oid*)Tloc(bn, BUNfirst(bn));
+       o = (oid*)Tloc(bs, BUNfirst(bs));
+       ol= (oid*)Tloc(bs, BUNlast(bs));
+       r = (oid*)Tloc(bn, BUNfirst(bn));
+
        lim = BATcount(b);
 
     BATaccessBegin(d, USE_TAIL, MMAP_SEQUENTIAL);
@@ -3976,9 +3977,9 @@
 Shrinking a void-headed BAT using a list of oids to ignore. 
 @= reuseloop
 {
-    @1 *p = (@1*)Tloc(b, BUNfirst(b));
-    @1 *q = (@1*)Tloc(b, BUNlast(b));
-    @1 *r = (@1*)Tloc(bn, BUNfirst(bn));
+       @1 *p = (@1*)Tloc(b, BUNfirst(b));
+       @1 *q = (@1*)Tloc(b, BUNlast(b));
+       @1 *r = (@1*)Tloc(bn, BUNfirst(bn));
 
        for (;p<q; oidx++, p++) {
                if ( *o == oidx ){
@@ -4027,8 +4028,8 @@
        }
 
        bidx= BUNlast(b)-1;
-    o = (oid*)Tloc(bs, BUNfirst(bs));
-    ol= (oid*)Tloc(bs, BUNlast(bs))-1;
+       o = (oid*)Tloc(bs, BUNfirst(bs));
+       ol= (oid*)Tloc(bs, BUNlast(bs))-1;
 
     BATaccessBegin(d, USE_TAIL, MMAP_SEQUENTIAL);
     BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL);
diff -r bb7fb0e98b41 -r e1cf355d2cfe sql/src/backends/monet5/sql.mx
--- a/sql/src/backends/monet5/sql.mx    Mon Dec 20 20:39:27 2010 +0100
+++ b/sql/src/backends/monet5/sql.mx    Mon Dec 20 21:31:13 2010 +0100
@@ -5118,7 +5118,8 @@
 Shrinking and re-using space to vacuum clean the holes in the relations.
 @= vacuum
 str
-...@1(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){
+...@1(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
        str *sch = (str *) getArgReference(stk,pci,1);
        str *tbl = (str *) getArgReference(stk,pci,2);
        sql_trans       *tr;
@@ -5140,6 +5141,27 @@
        t = mvc_bind_table(m, s, *tbl);
        if ( t == NULL)
                throw(MAL,"s...@1","Table missing");
+
+       if (m->user_id != USER_MONETDB)
+               throw(MAL,"s...@1","insufficient privileges");
+       if ((!list_empty(t->idxs.set) || !list_empty(t->keys.set)))
+               throw(MAL,"s...@1","vacuum not allowed on tables with indices");
+       if (has_snapshots(m->session->tr)) 
+               throw(MAL,"s...@1","vacuum not allowed on snapshots");
+
+       /* lock the store, for single user/transaction */
+       store_lock();
+       while (store_nr_active > 1) {
+               store_unlock();
+               MT_sleep_ms(100);
+               store_lock();
+
+               /* flush old changes to disk */
+               sql_trans_end(m->session);
+               store_apply_deltas();
+               sql_trans_begin(m->session);
+       }
+
        tr = m->session->tr;
        t->base.wtime = s->base.wtime = tr->wtime = tr->stime;
        t->base.rtime = s->base.rtime = tr->rtime = tr->stime;
@@ -5148,37 +5170,43 @@
        del = mvc_bind_dbat(m, *sch, *tbl, RD_INS);
 
        /* this code is insecure, because something may 
-       go wrong while we compress the columns.
-       A two-phase action reduces the risks, but not all.
+          go wrong while we compress the columns.
+          A two-phase action reduces the risks, but not all.
           e.g. a crash during update of the catalog. */
        i=0;
        bids[i]=0;
        for (o = t->columns.set->h; o; o = o->next,i++) {
                c = o->data;
                b = store_funcs.bind_col(tr, c, 0);
-               if (b == NULL)
-                       throw(MAL,"s...@1","Can not access descriptor");
-               msg = b...@1bat(&bid, &(b->batCacheid), &(del->batCacheid));
-               BBPreleaseref(b->batCacheid);
-               if (msg){
+               if (b == NULL || 
+                  (msg = b...@1bat(&bid, &(b->batCacheid), 
&(del->batCacheid))) != NULL) {
                        for( i--; i>=0; i--)
                                BBPreleaseref(bids[i]);
+                       store_unlock();
+                       if (!msg)
+                               throw(MAL,"s...@1","Can not access descriptor");
                        return msg;
                }
-               if ( i <2048){
-                       bids[i++]= bid;
-                       bids[i]=0;
+               BBPreleaseref(b->batCacheid);
+               if (i < 2048){
+                       bids[i]= bid;
+                       bids[i+1]=0;
                }
        }
-       if ( i == 2048 )
+       if ( i == 2048 ) {
+               for( i--; i>=0; i--)
+                       BBPreleaseref(bids[i]);
+               store_unlock();
                throw(MAL,"s...@1","Too many columns to handle, use copy 
instead");
+       }
+
        i=0;
        for (o = t->columns.set->h; o; o = o->next, i++) {
                sql_delta *d;
                c = o->data;
                b = store_funcs.bind_col(tr, c, 0);
                /* based on previous loop, BAT should be accessible */
-               if (b )
+               if (b)
                        BBPdecref(b->batCacheid, TRUE);
                d = c->data;
                d->bid = 0;
@@ -5189,6 +5217,14 @@
        BBPreleaseref(del->batCacheid);
        /* bat was cleared */
        t->cleared = 1;
+
+       sql_trans_commit(m->session->tr);
+       /* write changes to disk */
+       sql_trans_end(m->session);
+       store_apply_deltas();
+       sql_trans_begin(m->session);
+       store_unlock();
+
        return MAL_SUCCEED;
 }
 @c
@@ -5200,7 +5236,8 @@
 To avoid expensive shuffles, the reorganisation is balanced by the number of 
outstanding deletions.
 @c
 str
-SQLvacuum(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){
+SQLvacuum(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
        str *sch = (str *) getArgReference(stk,pci,1);
        str *tbl = (str *) getArgReference(stk,pci,2);
        sql_trans       *tr;
@@ -5222,6 +5259,14 @@
        t = mvc_bind_table(m, s, *tbl);
        if ( t == NULL)
                throw(MAL,"s...@1","Table missing");
+
+       if (m->user_id != USER_MONETDB)
+               throw(MAL,"s...@1","insufficient privileges");
+       if ((!list_empty(t->idxs.set) || !list_empty(t->keys.set)))
+               throw(MAL,"s...@1","vacuum not allowed on tables with indices");
+       if (has_snapshots(m->session->tr)) 
+               throw(MAL,"s...@1","vacuum not allowed on snapshots");
+
        tr = m->session->tr;
 
        /* get the deletions BAT*/
@@ -5230,7 +5275,7 @@
        for (o = t->columns.set->h; o && ordered == 0; o = o->next) {
                c = o->data;
                b = store_funcs.bind_col(tr, c, 0);
-               if (b == NULL)
+               if (b == NULL) 
                        throw(MAL,"s...@1","Can not access descriptor");
                ordered |= BATtordered(b);
                cnt = BATcount(b);
diff -r bb7fb0e98b41 -r e1cf355d2cfe sql/src/backends/monet5/sql_result.mx
--- a/sql/src/backends/monet5/sql_result.mx     Mon Dec 20 20:39:27 2010 +0100
+++ b/sql/src/backends/monet5/sql_result.mx     Mon Dec 20 21:31:13 2010 +0100
@@ -466,6 +466,7 @@
        }
 
        if (locked) {
+               /* flush old changes to disk */
                sql_trans_end(m->session);
                store_apply_deltas();
                sql_trans_begin(m->session);
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to