]> pd.if.org Git - btree/commitdiff
fixes for file I/O version that only deletes leaf pages
authorunknown <karl@E04.petzent.com>
Thu, 13 Feb 2014 20:47:58 +0000 (12:47 -0800)
committerunknown <karl@E04.petzent.com>
Thu, 13 Feb 2014 20:47:58 +0000 (12:47 -0800)
btree2s.c

index ac7673e75cca8a0c1a9debe608f938163dfa99d0..e2f1ae177e9c8cdc3b66753a2472cb9279af1901 100644 (file)
--- a/btree2s.c
+++ b/btree2s.c
@@ -119,7 +119,8 @@ typedef struct {
        uint cnt;                                       // count of keys in page
        uint act;                                       // count of active keys
        uint min;                                       // next key offset
-       unsigned char bits;                     // page size in bits
+       unsigned char bits:7;           // page size in bits
+       unsigned char free:1;           // page is on free list
        unsigned char lvl:7;            // level of page
        unsigned char dirty:1;          // page is dirty
        unsigned char right[BtId];      // page number to right
@@ -166,7 +167,6 @@ typedef struct _BtDb {
        int nodemax;            // highest page cache segment allocated
        int hashmask;           // number of pages in segments - 1
        int hashsize;           // size of hash table
-       int posted;                     // last loadpage found posted key
        int found;                      // last deletekey found key
        int fence;                      // last load page used fence position
        BtHash *lrufirst;       // lru list head
@@ -917,6 +917,7 @@ BTERR bt_freepage(BtDb *bt, uid page_no)
        //      store chain in second right
        bt_putid(bt->temp->right, bt_getid(bt->alloc[1].right));
        bt_putid(bt->alloc[1].right, page_no);
+       bt->temp->free = 1;
 
        if( bt_update(bt, bt->alloc, ALLOC_page) )
                return bt->err;
@@ -1024,16 +1025,6 @@ int bt_findslot (BtDb *bt, unsigned char *key, uint len)
 uint diff, higher = bt->page->cnt, low = 1, slot;
 uint good = 0;
 
-       //      if page is being deleted, send to right
-
-       if( !bt->page->cnt )
-               return 0;
-
-       //      if page is an empty fence holder
-
-       if( !bt->page->act )
-               return bt->page->cnt;
-
        //      make stopper key an infinite fence value
 
        if( bt_getid (bt->page->right) )
@@ -1068,8 +1059,6 @@ uint mode, prevmode;
 
   //  start at root of btree and drill down
 
-  bt->posted = 1;
-
   do {
        // determine lock mode of drill level
        mode = (lock == BtLockWrite) && (drill == lvl) ? BtLockWrite : BtLockRead; 
@@ -1115,6 +1104,9 @@ uint mode, prevmode;
                        continue;
        }
 
+       prevpage = bt->page_no;
+       prevmode = mode;
+
        //  find key on page at this level
        //  and descend to requested level
 
@@ -1126,27 +1118,23 @@ uint mode, prevmode;
                if( slot++ < bt->page->cnt )
                        continue;
                else
-                       return bt->err = BTERR_struct, 0;
+                       break;
+
+         //  if the page has no active slots,
+         //  move right otherwise drill down
 
-         page_no = bt_getid(slotptr(bt->page, slot)->id);
-         bt->fence = slot == bt->page->cnt;
-         bt->posted = 1;
-         drill--;
+         if( slot <= bt->page->cnt ) {
+               page_no = bt_getid(slotptr(bt->page, slot)->id);
+               bt->fence = slot == bt->page->cnt;
+               drill--;
+               continue;
+         }
        }
 
        //  or slide right into next page
-       //  (slide left from deleted page)
 
-       else {
-               page_no = bt_getid(bt->page->right);
-               bt->posted = 0;
-       }
-
-       //  continue down / right using overlapping locks
-       //  to protect pages being killed or split.
+       page_no = bt_getid(bt->page->right);
 
-       prevpage = bt->page_no;
-       prevmode = mode;
   } while( page_no );
 
   // return error on end of right chain