#include #include #include #include #include "logstore.h" #include #include #include #include #include #include #define LOG_NAME "check_logTree.log" #define NUM_ENTRIES_A 10000 #define NUM_ENTRIES_B 10 #define NUM_ENTRIES_C 0 #define OFFSET (NUM_ENTRIES * 10) #undef begin #undef end bool mycmp(const std::string & k1,const std::string & k2) { //for char* ending with \0 return strcmp(k1.c_str(),k2.c_str()) < 0; //for int32_t //printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2))); //return (*((int32_t*)k1)) <= (*((int32_t*)k2)); } void preprandstr(int count, std::vector &arr) { for ( int j=0; jget_root_rec(); long oldpagenum = -1; std::vector arr; preprandstr(NUM_ENTRIES, arr); std::sort(arr.begin(), arr.end(), &mycmp); //for(int i = 0; i < NUM_ENTRIES; i++) //{ // printf("%s\t", arr[i].c_str()); // int keylen = arr[i].length()+1; // printf("%d\n", keylen); //} printf("Stage 1: Writing %d keys\n", NUM_ENTRIES); for(int i = 0; i < NUM_ENTRIES; i++) { int keylen = arr[i].length()+1; byte *currkey = (byte*)malloc(keylen); for(int j=0; jget_tree_state(); RegionAllocConf_t alloc_conf; Tread(xid,rid,&alloc_conf); logtree::appendPage(xid, tree, lt->lastLeaf, currkey, keylen, lt->alloc_region, &alloc_conf, i + OFFSET); //DEBUG("{%lld <- alloc region extend}\n", conf.regionList.page); // XXX get rid of Tset by storing next page in memory, and losing it // on crash. Tset(xid,rid,&alloc_conf); pagenum = logtree::findPage(xid, tree, currkey,keylen); oldpagenum = pagenum; //printf("pagenum:%d\n", pagenum); assert(pagenum == i + OFFSET); free(currkey); } printf("Writes complete."); tree = lt->get_root_rec(); Tcommit(xid); xid = Tbegin(); printf("\nTREE STRUCTURE\n"); lt->print_tree(xid); printf("Stage 2: Looking up %d keys\n", NUM_ENTRIES); for(int i = 0; i < NUM_ENTRIES; i++) { int keylen = arr[i].length()+1; byte *currkey = (byte*)malloc(keylen); for(int j=0; jget_root_rec(); long oldpagenum = -1; for(int32_t i = 0; i < NUM_ENTRIES; i++) { int keylen = sizeof(int32_t); byte *currkey = (byte*)malloc(keylen); memcpy(currkey, (byte*)(&i), keylen); //currkey[]='\0'; printf("\n#########\ni=%d\nkey:\t%d\nkeylen:%d\n",i,*((int32_t*)currkey),keylen); long pagenum = logtree::findPage(xid, tree, currkey, keylen); printf("pagenum:%d\n", pagenum); assert(pagenum == -1 || pagenum == oldpagenum || oldpagenum == -1); printf("TlsmAppendPage %d\n",i); recordid rid = lt->get_tree_state(); RegionAllocConf_t alloc_conf; Tread(xid,rid,&alloc_conf); logtree::appendPage(xid, tree, lt->lastLeaf, currkey, keylen, lt->alloc_region, &alloc_conf, i + OFFSET); //DEBUG("{%lld <- alloc region extend}\n", conf.regionList.page); // XXX get rid of Tset by storing next page in memory, and losing it // on crash. Tset(xid,rid,&alloc_conf); pagenum = logtree::findPage(xid, tree, currkey,keylen); oldpagenum = pagenum; printf("pagenum:%d\n", pagenum); assert(pagenum == i + OFFSET); free(currkey); } printf("Writes complete."); tree = lt->get_root_rec(); Tcommit(xid); xid = Tbegin(); printf("\nTREE STRUCTURE\n"); lt->print_tree(xid); for(int32_t i = 1; i < NUM_ENTRIES; i++) { int keylen = sizeof(int32_t); byte *currkey = (byte*)malloc(keylen); memcpy(currkey, (byte*)(&i), keylen); printf("\n#########\ni=%d\nkey:\t%d\nkeylen:%d\n",i,*((int32_t*)currkey),keylen); long pagenum = logtree::findPage(xid, tree, currkey, keylen); printf("pagenum:%d\n", pagenum); assert(pagenum == i + OFFSET); free(currkey); } /* int64_t count = 0; lladdIterator_t * it = lsmTreeIterator_open(xid, tree); while(lsmTreeIterator_next(xid, it)) { lsmkey_t * key; lsmkey_t **key_ptr = &key; int size = lsmTreeIterator_key(xid, it, (byte**)key_ptr); assert(size == sizeof(lsmkey_t)); long *value; long **value_ptr = &value; size = lsmTreeIterator_value(xid, it, (byte**)value_ptr); assert(size == sizeof(pageid_t)); assert(*key + OFFSET == *value); assert(*key == count); count++; } assert(count == NUM_ENTRIES); lsmTreeIterator_close(xid, it); */ Tcommit(xid); Tdeinit(); } /** @test */ int main() { insertProbeIter_str(NUM_ENTRIES_A); //insertProbeIter_int(NUM_ENTRIES_A); return 0; }