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,
if (0) { died2: toku_free(t->h); }
goto died1;
}
t->h->dirty=1;
t->h->nodesize=nodesize;
t->h->freelist=-1;
t->h->unused_memory=2*nodesize;
......@@ -1077,7 +1078,7 @@ int close_brt (BRT brt) {
if (r!=0) return r;
}
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 (brt->database_name) toku_free(brt->database_name);
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) {
void *node_v;
int r = cachetable_get_and_pin(brt->cf, off, &node_v,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize);
DBT answer;
BRTNODE node;
int childnum;
if (r!=0) {
......@@ -1183,12 +1183,9 @@ int brt_lookup_node (BRT brt, diskoff off, DBT *k, DBT *v, DB *db) {
}
node=node_v;
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);
if (r!=0) goto died0;
if (r==0) {
*v = answer;
}
r = cachetable_unpin(brt->cf, off, 0);
return r;
}
......
......@@ -17,6 +17,7 @@
typedef struct ctpair *PAIR;
struct ctpair {
enum typ_tag tag;
long long pinned;
char dirty;
CACHEKEY key;
......@@ -233,6 +234,8 @@ static void flush_and_remove (CACHETABLE t, PAIR remove_me, int write_me) {
lru_remove(t, remove_me);
//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));
//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);
t->n_in_table--;
// Remove it from the hash chain.
......@@ -272,34 +275,39 @@ int cachetable_put (CACHEFILE cachefile, CACHEKEY key, void*value,
void*extraargs
) {
int h = hashit(cachefile->cachetable, key);
PAIR p;
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) {
// Semantically, these two asserts are not strictly right. After all, when are two functions eq?
// In practice, the functions better be the same.
assert(p->flush_callback==flush_callback);
assert(p->fetch_callback==fetch_callback);
return -1; /* Already present. */
{
PAIR p;
for (p=cachefile->cachetable->table[h]; p; p=p->hash_chain) {
if (p->key==key && p->cachefile==cachefile) {
// Semantically, these two asserts are not strictly right. After all, when are two functions eq?
// In practice, the functions better be the same.
assert(p->flush_callback==flush_callback);
assert(p->fetch_callback==fetch_callback);
return -1; /* Already present. */
}
}
}
if (maybe_flush_some(cachefile->cachetable)) return -2;
MALLOC(p);
p->pinned=1;
p->dirty =1;
p->key = key;
p->value = value;
p->next = p->prev = 0;
p->cachefile = cachefile;
p->flush_callback = flush_callback;
p->fetch_callback = fetch_callback;
p->extraargs = extraargs;
lru_add_to_list(cachefile->cachetable, p);
p->hash_chain = cachefile->cachetable->table[h];
cachefile->cachetable->table[h] = p;
cachefile->cachetable->n_in_table++;
return 0;
{
TAGMALLOC(PAIR, p);
p->pinned=1;
p->dirty =1;
//printf("%s:%d p=%p dirty=%d\n", __FILE__, __LINE__, p, p->dirty);
p->key = key;
p->value = value;
p->next = p->prev = 0;
p->cachefile = cachefile;
p->flush_callback = flush_callback;
p->fetch_callback = fetch_callback;
p->extraargs = extraargs;
lru_add_to_list(cachefile->cachetable, p);
p->hash_chain = cachefile->cachetable->table[h];
cachefile->cachetable->table[h] = p;
cachefile->cachetable->n_in_table++;
return 0;
}
}
int cachetable_get_and_pin (CACHEFILE cachefile, CACHEKEY key, void**value,
......@@ -354,6 +362,7 @@ int cachetable_unpin (CACHEFILE cachefile, CACHEKEY key, int dirty) {
int h = hashit(t,key);
PAIR p;
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) {
if (p->key==key && p->cachefile==cachefile) {
assert(p->pinned>0);
......
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