Commit e8438d51 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Valgrind caught an error (uninitialized dirty bit)

git-svn-id: file:///svn/tokudb@80 c7de825b-a66e-492c-adef-691d508d4ae1
parent 7c3c5307
...@@ -1006,6 +1006,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt, ...@@ -1006,6 +1006,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
if (0) { died2: toku_free(t->h); } if (0) { died2: toku_free(t->h); }
goto died1; goto died1;
} }
t->h->dirty=1;
t->h->nodesize=nodesize; t->h->nodesize=nodesize;
t->h->freelist=-1; t->h->freelist=-1;
t->h->unused_memory=2*nodesize; t->h->unused_memory=2*nodesize;
...@@ -1077,7 +1078,7 @@ int close_brt (BRT brt) { ...@@ -1077,7 +1078,7 @@ int close_brt (BRT brt) {
if (r!=0) return r; if (r!=0) return r;
} }
assert(0==cachefile_count_pinned(brt->cf, 1)); assert(0==cachefile_count_pinned(brt->cf, 1));
printf("%s:%d closing cachetable\n", __FILE__, __LINE__); //printf("%s:%d closing cachetable\n", __FILE__, __LINE__);
if ((r = cachefile_close(&brt->cf))!=0) return r; if ((r = cachefile_close(&brt->cf))!=0) return r;
if (brt->database_name) toku_free(brt->database_name); if (brt->database_name) toku_free(brt->database_name);
if (brt->skey) { toku_free(brt->skey); } if (brt->skey) { toku_free(brt->skey); }
...@@ -1171,7 +1172,6 @@ int brt_lookup_node (BRT brt, diskoff off, DBT *k, DBT *v, DB *db) { ...@@ -1171,7 +1172,6 @@ int brt_lookup_node (BRT brt, diskoff off, DBT *k, DBT *v, DB *db) {
void *node_v; void *node_v;
int r = cachetable_get_and_pin(brt->cf, off, &node_v, int r = cachetable_get_and_pin(brt->cf, off, &node_v,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize); brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize);
DBT answer;
BRTNODE node; BRTNODE node;
int childnum; int childnum;
if (r!=0) { if (r!=0) {
...@@ -1183,12 +1183,9 @@ int brt_lookup_node (BRT brt, diskoff off, DBT *k, DBT *v, DB *db) { ...@@ -1183,12 +1183,9 @@ int brt_lookup_node (BRT brt, diskoff off, DBT *k, DBT *v, DB *db) {
} }
node=node_v; node=node_v;
if (node->height==0) { if (node->height==0) {
r = pma_lookup(node->u.l.buffer, k, &answer, db); r = pma_lookup(node->u.l.buffer, k, v, db);
//printf("%s:%d looked up something, got answerlen=%d\n", __FILE__, __LINE__, answerlen); //printf("%s:%d looked up something, got answerlen=%d\n", __FILE__, __LINE__, answerlen);
if (r!=0) goto died0; if (r!=0) goto died0;
if (r==0) {
*v = answer;
}
r = cachetable_unpin(brt->cf, off, 0); r = cachetable_unpin(brt->cf, off, 0);
return r; return r;
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
typedef struct ctpair *PAIR; typedef struct ctpair *PAIR;
struct ctpair { struct ctpair {
enum typ_tag tag;
long long pinned; long long pinned;
char dirty; char dirty;
CACHEKEY key; CACHEKEY key;
...@@ -233,6 +234,8 @@ static void flush_and_remove (CACHETABLE t, PAIR remove_me, int write_me) { ...@@ -233,6 +234,8 @@ static void flush_and_remove (CACHETABLE t, PAIR remove_me, int write_me) {
lru_remove(t, remove_me); lru_remove(t, remove_me);
//printf("flush_callback(%lld,%p)\n", remove_me->key, remove_me->value); //printf("flush_callback(%lld,%p)\n", remove_me->key, remove_me->value);
WHEN_TRACE_CT(printf("%s:%d CT flush_callback(%lld, %p, dirty=%d, 0)\n", __FILE__, __LINE__, remove_me->key, remove_me->value, remove_me->dirty && write_me)); WHEN_TRACE_CT(printf("%s:%d CT flush_callback(%lld, %p, dirty=%d, 0)\n", __FILE__, __LINE__, remove_me->key, remove_me->value, remove_me->dirty && write_me));
//printf("%s:%d TAG=%x p=%p\n", __FILE__, __LINE__, remove_me->tag, remove_me);
//printf("%s:%d dirty=%d\n", __FILE__, __LINE__, remove_me->dirty);
remove_me->flush_callback(remove_me->cachefile, remove_me->key, remove_me->value, remove_me->dirty && write_me, 0); remove_me->flush_callback(remove_me->cachefile, remove_me->key, remove_me->value, remove_me->dirty && write_me, 0);
t->n_in_table--; t->n_in_table--;
// Remove it from the hash chain. // Remove it from the hash chain.
...@@ -272,34 +275,39 @@ int cachetable_put (CACHEFILE cachefile, CACHEKEY key, void*value, ...@@ -272,34 +275,39 @@ int cachetable_put (CACHEFILE cachefile, CACHEKEY key, void*value,
void*extraargs void*extraargs
) { ) {
int h = hashit(cachefile->cachetable, key); int h = hashit(cachefile->cachetable, key);
PAIR p;
WHEN_TRACE_CT(printf("%s:%d CT cachetable_put(%lld)=%p\n", __FILE__, __LINE__, key, value)); WHEN_TRACE_CT(printf("%s:%d CT cachetable_put(%lld)=%p\n", __FILE__, __LINE__, key, value));
for (p=cachefile->cachetable->table[h]; p; p=p->hash_chain) { {
if (p->key==key && p->cachefile==cachefile) { PAIR p;
// Semantically, these two asserts are not strictly right. After all, when are two functions eq? for (p=cachefile->cachetable->table[h]; p; p=p->hash_chain) {
// In practice, the functions better be the same. if (p->key==key && p->cachefile==cachefile) {
assert(p->flush_callback==flush_callback); // Semantically, these two asserts are not strictly right. After all, when are two functions eq?
assert(p->fetch_callback==fetch_callback); // In practice, the functions better be the same.
return -1; /* Already present. */ assert(p->flush_callback==flush_callback);
assert(p->fetch_callback==fetch_callback);
return -1; /* Already present. */
}
} }
} }
if (maybe_flush_some(cachefile->cachetable)) return -2; if (maybe_flush_some(cachefile->cachetable)) return -2;
MALLOC(p); {
p->pinned=1; TAGMALLOC(PAIR, p);
p->dirty =1; p->pinned=1;
p->key = key; p->dirty =1;
p->value = value; //printf("%s:%d p=%p dirty=%d\n", __FILE__, __LINE__, p, p->dirty);
p->next = p->prev = 0; p->key = key;
p->cachefile = cachefile; p->value = value;
p->flush_callback = flush_callback; p->next = p->prev = 0;
p->fetch_callback = fetch_callback; p->cachefile = cachefile;
p->extraargs = extraargs; p->flush_callback = flush_callback;
lru_add_to_list(cachefile->cachetable, p); p->fetch_callback = fetch_callback;
p->hash_chain = cachefile->cachetable->table[h]; p->extraargs = extraargs;
cachefile->cachetable->table[h] = p; lru_add_to_list(cachefile->cachetable, p);
cachefile->cachetable->n_in_table++; p->hash_chain = cachefile->cachetable->table[h];
return 0; cachefile->cachetable->table[h] = p;
cachefile->cachetable->n_in_table++;
return 0;
}
} }
int cachetable_get_and_pin (CACHEFILE cachefile, CACHEKEY key, void**value, int cachetable_get_and_pin (CACHEFILE cachefile, CACHEKEY key, void**value,
...@@ -354,6 +362,7 @@ int cachetable_unpin (CACHEFILE cachefile, CACHEKEY key, int dirty) { ...@@ -354,6 +362,7 @@ int cachetable_unpin (CACHEFILE cachefile, CACHEKEY key, int dirty) {
int h = hashit(t,key); int h = hashit(t,key);
PAIR p; PAIR p;
WHEN_TRACE_CT(printf("%s:%d unpin(%lld)", __FILE__, __LINE__, key)); WHEN_TRACE_CT(printf("%s:%d unpin(%lld)", __FILE__, __LINE__, key));
//printf("%s:%d is dirty now=%d\n", __FILE__, __LINE__, dirty);
for (p=t->table[h]; p; p=p->hash_chain) { for (p=t->table[h]; p; p=p->hash_chain) {
if (p->key==key && p->cachefile==cachefile) { if (p->key==key && p->cachefile==cachefile) {
assert(p->pinned>0); assert(p->pinned>0);
......
enum pma_errors { BRT_OK=0, BRT_ALREADY_THERE = -2, BRT_KEYEMPTY=-3 }; enum pma_errors { BRT_OK=0, BRT_ALREADY_THERE = -2, BRT_KEYEMPTY=-3 };
enum typ_tag { TYP_BRTNODE = 0xdead0001, TYP_CACHETABLE, TYP_PMA }; enum typ_tag { TYP_BRTNODE = 0xdead0001,
TYP_CACHETABLE, TYP_PAIR, /* for cachetables */
TYP_PMA };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment