New cache subsystem
authorteodor <teodor>
Wed, 9 Feb 2005 09:43:41 +0000 (09:43 +0000)
committerteodor <teodor>
Wed, 9 Feb 2005 09:43:41 +0000 (09:43 +0000)
gendata.c
tbtree.c
tbtreetest.c

index c7f6a13..fc7f3c0 100644 (file)
--- a/gendata.c
+++ b/gendata.c
@@ -39,7 +39,7 @@ static void
 usage() {
         puts(
         "Usage:\n"
 usage() {
         puts(
         "Usage:\n"
-        "tbtreetest  -b [-r -c COUNT] | -s [ -c COUNT ]\n"
+        "tbtreetest  -b [-r -c COUNT -f] | -s [ -c COUNT ]\n"
         );
         exit(1);
 }
         );
         exit(1);
 }
@@ -57,14 +57,17 @@ static int symbolslen=0;
 int
 main(int argn, char *argv[]) {
         int mode=NO_MODE;
 int
 main(int argn, char *argv[]) {
         int mode=NO_MODE;
-       int isrnd=0, count=10,i; 
+       int isrnd=0, count=10,i, isfind=0
 
         opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
        symbolslen=strlen(symbols);
        
           
 
         opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
        symbolslen=strlen(symbols);
        
           
-        while((i=getopt(argn,argv,"sbrc:")) != EOF) {
+        while((i=getopt(argn,argv,"sbrc:f")) != EOF) {
                 switch(i) {
                 switch(i) {
+                        case 'f':
+                                isfind=1;
+                                break;
                         case 'r':
                                 isrnd=1;
                                 break;
                         case 'r':
                                 isrnd=1;
                                 break;
@@ -87,13 +90,17 @@ main(int argn, char *argv[]) {
 
        if ( mode==MODE_BTREE ) {
                int cnt;
 
        if ( mode==MODE_BTREE ) {
                int cnt;
-               for(i=0;i<count;i++) {
-                       printf("I\t%d\t", (int)( (isrnd) ? random()%count : i ));
-                       cnt=1+random()%512;
-                       while(cnt-->0)
-                               fputc( symbols[ random()%symbolslen ], stdout);
-                       fputc('\n', stdout);
-               }
+               if ( isfind ) 
+                       for(i=0;i<count;i++)
+                               printf("S\t%d\n", (int)( (isrnd) ? random()%count : i )); 
+               else    
+                       for(i=0;i<count;i++) {
+                               printf("I\t%d\t", (int)( (isrnd) ? random()%count : i ));
+                               cnt=1+random()%512;
+                               while(cnt-->0)
+                                       fputc( symbols[ random()%symbolslen ], stdout);
+                               fputc('\n', stdout);
+                       }
        } else if ( mode==MODE_SFX ) {
                int cnt;
                for(i=0;i<count;i++) {
        } else if ( mode==MODE_SFX ) {
                int cnt;
                for(i=0;i<count;i++) {
index becd120..f9eae19 100644 (file)
--- a/tbtree.c
+++ b/tbtree.c
@@ -673,21 +673,21 @@ findDelimiter(TBTree *db, TBTPage *page, TBTPointer *ptr, int size, u_int32_t st
        
        }
        
        
        }
        
-       if ( was==0 )
+       if ( was==0 ) {
                sizes[page->npointer]=size;
                sizes[page->npointer]=size;
+       }
 
 
-       for(i=0;i<page->npointer+1;i++) {
+       for(i=0;i<page->npointer+1;i++) 
                if ( i< start )
                        lfree-=sizes[i];
                else 
                        rfree-=sizes[i];
                if ( i< start )
                        lfree-=sizes[i];
                else 
                        rfree-=sizes[i];
-       }
 
        while( 1 ) {
                if ( lfree<0 ) {
 
        while( 1 ) {
                if ( lfree<0 ) {
+                       start--;
                        lfree+=sizes[start];
                        rfree-=sizes[start];
                        lfree+=sizes[start];
                        rfree-=sizes[start];
-                       start--;
                } else if ( rfree < 0 ) { 
                        lfree-=sizes[start];
                        rfree+=sizes[start];
                } else if ( rfree < 0 ) { 
                        lfree-=sizes[start];
                        rfree+=sizes[start];
@@ -778,7 +778,6 @@ splitPage(TBTree *db, TBTMemPage *srcpage, TBTMemPage** newpage, TBTPointer **pt
                packLeafKV(db, &(tmp->page), *ptr, key, value);
        else
                packInternalKV(db, &(tmp->page), *ptr, key, pagenumber);
                packLeafKV(db, &(tmp->page), *ptr, key, value);
        else
                packInternalKV(db, &(tmp->page), *ptr, key, pagenumber);
-
        return TBT_OK;
 }
 
        return TBT_OK;
 }
 
@@ -825,7 +824,9 @@ layerInsert(TBTree *db, u_int32_t pagenumber, TBTMemPage **left, TBTMemPage **ri
                }
 
                if ( size <= page->page.freespace ) {
                }
 
                if ( size <= page->page.freespace ) {
+                       u_int32_t       oldsize=page->page.freespace;
                        packLeafKV(db, &(page->page), ptr, key, value);
                        packLeafKV(db, &(page->page), ptr, key, value);
+                       tassert( oldsize == page->page.freespace + size );
                        page->issynced=0;
                } else {
                        rc = splitPage(db, page, &newright, &ptr, size, key, value, 0);
                        page->issynced=0;
                } else {
                        rc = splitPage(db, page, &newright, &ptr, size, key, value, 0);
index a6e96db..a3779ca 100644 (file)
@@ -41,7 +41,7 @@ static void
 usage() {
        puts(
        "Usage:\n"
 usage() {
        puts(
        "Usage:\n"
-       "tbtreetest [ -c CACHESIZE ] [-r] [-k] [-f FILE] [-D | -L | -b | -i KEY -v VALUE [ -S strategynumber ] | -d KEY | -s KEY ] [-V]\n"
+       "tbtreetest [ -c CACHESIZE ] [-r] [-k] [-f FILE] [-D | -L | -b | -i KEY -v VALUE [ -S strategynumber ] | -d KEY | -s KEY ] [-V] [-q]\n"
        );
        exit(1);
 }
        );
        exit(1);
 }
@@ -104,14 +104,17 @@ main(int argn, char *argv[]) {
        int rc=0;
        char *file="BTREE";
        char *key=NULL, *val=NULL;
        int rc=0;
        char *file="BTREE";
        char *key=NULL, *val=NULL;
-       int mode=0, verbose=0;
+       int mode=0, verbose=0, quietout=0;
 
        opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
 
        memset(&db, 0, sizeof(TBTree));
 
 
        opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
 
        memset(&db, 0, sizeof(TBTree));
 
-       while((i=getopt(argn,argv,"VbS:Dc:hrkf:i:v:d:s:L")) != EOF) {
+       while((i=getopt(argn,argv,"qVbS:Dc:hrkf:i:v:d:s:L")) != EOF) {
                switch(i) {
                switch(i) {
+                       case 'q':
+                               quietout=1;
+                               break;
                        case 'V':
                                verbose=1;
                                break;
                        case 'V':
                                verbose=1;
                                break;
@@ -251,7 +254,7 @@ main(int argn, char *argv[]) {
                                }
                                if ( *buf == 'D' ) {
                                        rc=TBTDelete(&db, &key);
                                }
                                if ( *buf == 'D' ) {
                                        rc=TBTDelete(&db, &key);
-                               } else if ( (rc=TBTFind(&db, &key, &value))==TBT_OK ) {
+                               } else if ( (rc=TBTFind(&db, &key, &value))==TBT_OK && quietout==0) {
                                        if ( db.keylen )
                                                printf("%d", *(int*)(key.value));
                                        else 
                                        if ( db.keylen )
                                                printf("%d", *(int*)(key.value));
                                        else