Permalink
Browse files

fixed Level-LRU supports

  • Loading branch information...
1 parent cb5e131 commit c71d1c3d60405c20cceea0a044f847d47d793e86 BohuTANG committed Sep 27, 2011
Showing with 50 additions and 32 deletions.
  1. +12 −3 README
  2. +10 −11 src/db.c
  3. +9 −5 src/llru.c
  4. +1 −1 src/llru.h
  5. +18 −12 src/nessdb_bench.c
View
@@ -1,6 +1,15 @@
-
- How to do
- =========
+nessDB v1.7
+
+ Levle-LRU
+ ========
+ * Level-LRU pool size is configurable(unit is byte),as with InnoDB's bufferpool
+ * Inlcude new-level and old-level two levels
+ * If one's hits >MAX,it will be moved to new-level,
+ and if new-level is FULL,move the last items to the head of old-level
+ * It's a real non-dirty shit,and likely atomic energy level transition
+
+ How to do
+ =========
a, $cd src
b, $make
c, $./nessdb_bench add
View
@@ -5,13 +5,11 @@
#include <assert.h>
#include "bitwise.h"
#include "storage.h"
-#include "idx.h"
#include "db.h"
#include "llru.h"
#define IDX_PRIME (16785407)
-static struct idx _idx;
static struct btree _btree;
static struct bloom _bloom;
@@ -60,29 +58,30 @@ int db_add(char* key,char* value)
void *db_get(char* key)
{
+ int b=bloom_get(&_bloom,(const char*)key);
+ if(b!=0)
+ return NULL;
+
void *v=llru_get((const char*)key);
if(v==NULL){
v=btree_get(&_btree,key);
char *k_tmp=strdup(key);
char *v_tmp=strdup((char*)v);
- int ret=llru_set(k_tmp,v_tmp,strlen(k_tmp),strlen(v_tmp));
- if(ret==0){
- free(k_tmp);
- free(v_tmp);
- }
+ llru_set(k_tmp,v_tmp,strlen(k_tmp),strlen(v_tmp));
+ return v;
+ }else{
+ return strdup((char*)v);
}
-
- return v;
}
void db_remove(char* key)
{
btree_delete(&_btree,key);
- idx_remove(&_idx,key);
+ llru_remove(key);
}
void db_destroy()
{
- idx_free(&_idx);
+ llru_free();
btree_close(&_btree);
}
View
@@ -54,6 +54,7 @@ static void llru_set_node(struct level_node *n)
level_remove_link(_level_new,n);
level_set_head(_level_new,n);
}else{
+
if(_level_old->used_size>_level_old->allow_size)
level_free_last(_level_old);
@@ -69,11 +70,10 @@ static void llru_set_node(struct level_node *n)
}
-int llru_set(const char *k,void *v,int k_len,int v_len)
+void llru_set(const char *k,void *v,int k_len,int v_len)
{
if(_buffer==0)
- return 0;
- int ret=0;
+ return;
struct level_node *n=ht_get(&_ht,k);
if(n==NULL){
_level_old->used_size+=(k_len+v_len);
@@ -86,10 +86,9 @@ int llru_set(const char *k,void *v,int k_len,int v_len)
n->hits=1;
n->pre=NULL;
n->nxt=NULL;
- ret=1;
}
llru_set_node(n);
- return ret;
+ ht_set(&_ht,k,n);
}
@@ -121,3 +120,8 @@ void llru_remove(const char* k)
level_free_node(_level_old,n);
}
}
+
+void llru_free()
+{
+ ht_free(&_ht);
+}
View
@@ -3,7 +3,7 @@
#include "level.h"
void llru_init(size_t buffer_size);
-int llru_set(const char *k,void *v,int k_len,int v_len);
+void llru_set(const char *k,void *v,int k_len,int v_len);
void* llru_get(const char *k);
void llru_remove(const char *k);
void llru_free();
View
@@ -21,10 +21,11 @@
#define KEYSIZE 20
#define VALSIZE 100
-#define NUM 5000000
+#define NUM 10000000
#define R_NUM 10000
#define REMOVE_NUM 10000
-#define V "1.6"
+#define BUFFERPOOL (1024*1024*1024)
+#define V "1.7"
#define LINE "+-----------------------+---------------------------+----------------------------------+---------------------+\n"
#define LINE1 "--------------------------------------------------------------------------------------------------------------\n"
@@ -73,7 +74,7 @@ void print_header()
void print_environment()
{
- printf("nessDB: version %s(B+ Tree)\n",V);
+ printf("nessDB: version %s(B+Tree and Level-LRU)\n",V);
time_t now=time(NULL);
printf("Date: %s",(char*)ctime(&now));
@@ -114,9 +115,9 @@ void db_init_test(int show)
double cost;
start_timer();
cost=get_timer();
- fprintf(stderr,"loading index......%30s\r","");
+ fprintf(stderr,"loading bloom filter......%30s\r","");
- db_init();
+ db_init(BUFFERPOOL);
fflush(stderr);
@@ -169,13 +170,18 @@ void db_read_random_test()
for(i=r_start;i<r_end;i++){
memset(key,0,sizeof(key));
- sprintf(key,"%ldkey",rand()%i);
+ long long rid=rand()%5;
+ if(rid==0)
+ sprintf(key,"%ldkey",500000UL);
+ else
+ sprintf(key,"%ldkey",rand()%i);
+
void* data=db_get(key);
- if(data)
+ if(data){
count++;
- else
+ free(data);
+ }else
printf("nofound!%s\n",key);
- free(data);
if((count%100)==0){
fprintf(stderr,"readrandom finished %ld ops%30s\r",count,"");
@@ -206,11 +212,11 @@ void db_read_seq_test()
memset(key,0,sizeof(key));
sprintf(key,"%ldkey",i);
void* data=db_get(key);
- if(data)
+ if(data){
count++;
- else
+ free(data);
+ }else
printf("nofound!%s\n",key);
- free(data);
if((count%1000)==0){
fprintf(stderr,"readseq finished %ld ops %30s\r",count,"");

0 comments on commit c71d1c3

Please sign in to comment.