Commit 70d7c7a3 authored by Rich Prohaska's avatar Rich Prohaska

simplify the cachetable interface by removing all of the *_size

functions



git-svn-id: file:///svn/tokudb@498 c7de825b-a66e-492c-adef-691d508d4ae1
parent 2b08ea8e
......@@ -82,7 +82,7 @@ void fix_up_parent_pointers_of_children (BRT t, BRTNODE node) {
BRTNODE child = v;
//printf("%s:%d pin %p\n", __FILE__, __LINE__, v);
child->parent_brtnode = node;
r=cachetable_unpin_size(t->cf, node->u.n.children[i], child->dirty, brtnode_size(child));
r=cachetable_unpin(t->cf, node->u.n.children[i], child->dirty, brtnode_size(child));
}
}
}
......@@ -97,7 +97,7 @@ void fix_up_parent_pointers_of_children_now_that_parent_is_gone (CACHEFILE cf, B
BRTNODE child = v;
//printf("%s:%d pin %p\n", __FILE__, __LINE__, v);
child->parent_brtnode = 0;
r=cachetable_unpin_size(cf, node->u.n.children[i], child->dirty, brtnode_size(child));
r=cachetable_unpin(cf, node->u.n.children[i], child->dirty, brtnode_size(child));
}
}
}
......@@ -184,7 +184,7 @@ int brtheader_fetch_callback (CACHEFILE cachefile, diskoff nodename, void **head
int read_and_pin_brt_header (CACHEFILE cf, struct brt_header **header) {
void *header_p;
//fprintf(stderr, "%s:%d read_and_pin_brt_header(...)\n", __FILE__, __LINE__);
int r = cachetable_get_and_pin(cf, 0, &header_p,
int r = cachetable_get_and_pin(cf, 0, &header_p, NULL,
brtheader_flush_callback, brtheader_fetch_callback, 0);
if (r!=0) return r;
*header = header_p;
......@@ -192,7 +192,7 @@ int read_and_pin_brt_header (CACHEFILE cf, struct brt_header **header) {
}
int unpin_brt_header (BRT brt) {
int r = cachetable_unpin(brt->cf, 0, brt->h->dirty);
int r = cachetable_unpin(brt->cf, 0, brt->h->dirty, 0);
brt->h->dirty=0;
brt->h=0;
return r;
......@@ -280,7 +280,7 @@ static void create_new_brtnode (BRT t, BRTNODE *result, int height, BRTNODE pare
assert(n->nodesize>0);
n->parent_brtnode = parent_brtnode;
//printf("%s:%d putting %p (%lld) parent=%p\n", __FILE__, __LINE__, n, n->thisnodename, parent_brtnode);
r=cachetable_put_size(t->cf, n->thisnodename, n, brtnode_size(n),
r=cachetable_put(t->cf, n->thisnodename, n, brtnode_size(n),
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)t->h->nodesize);
assert(r==0);
}
......@@ -661,9 +661,9 @@ static int handle_split_of_child (BRT t, BRTNODE node, int childnum,
toku_hashtable_free(&old_h);
r=cachetable_unpin_size(t->cf, childa->thisnodename, childa->dirty, brtnode_size(childa));
r=cachetable_unpin(t->cf, childa->thisnodename, childa->dirty, brtnode_size(childa));
assert(r==0);
r=cachetable_unpin_size(t->cf, childb->thisnodename, childb->dirty, brtnode_size(childb));
r=cachetable_unpin(t->cf, childb->thisnodename, childb->dirty, brtnode_size(childb));
assert(r==0);
......@@ -705,7 +705,7 @@ static int push_some_brt_cmds_down (BRT t, BRTNODE node, int childnum,
assert(node->height>0);
diskoff targetchild = node->u.n.children[childnum];
assert(targetchild>=0 && targetchild<t->h->unused_memory); // This assertion could fail in a concurrent setting since another process might have bumped unused memory.
r = cachetable_get_and_pin(t->cf, targetchild, &childnode_v,
r = cachetable_get_and_pin(t->cf, targetchild, &childnode_v, NULL,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)t->h->nodesize);
if (r!=0) return r;
//printf("%s:%d pin %p\n", __FILE__, __LINE__, childnode_v);
......@@ -778,7 +778,7 @@ static int push_some_brt_cmds_down (BRT t, BRTNODE node, int childnum,
if (0) printf("%s:%d done random picking\n", __FILE__, __LINE__);
}
if (debug) printf("%s:%d %*sdone push_some_brt_cmds_down, unpinning %lld\n", __FILE__, __LINE__, debug, "", targetchild);
r=cachetable_unpin_size(t->cf, targetchild, child->dirty, brtnode_size(child));
r=cachetable_unpin(t->cf, targetchild, child->dirty, brtnode_size(child));
if (r!=0) return r;
*did_split=0;
assert(serialize_brtnode_size(node)<=node->nodesize);
......@@ -925,7 +925,7 @@ static int brt_nonleaf_put_cmd_child (BRT t, BRTNODE node, BRT_CMD *cmd,
if (maybe)
r = cachetable_maybe_get_and_pin(t->cf, node->u.n.children[childnum], &child_v);
else
r = cachetable_get_and_pin(t->cf, node->u.n.children[childnum], &child_v,
r = cachetable_get_and_pin(t->cf, node->u.n.children[childnum], &child_v, NULL,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)t->h->nodesize);
if (r != 0)
return r;
......@@ -938,7 +938,7 @@ static int brt_nonleaf_put_cmd_child (BRT t, BRTNODE node, BRT_CMD *cmd,
&child_did_split, &childa, &childb, &childsplitk, debug, txn);
if (r != 0) {
/* putting to the child failed for some reason, so unpin the child and return the error code */
int rr = cachetable_unpin_size(t->cf, child->thisnodename, child->dirty, brtnode_size(child));
int rr = cachetable_unpin(t->cf, child->thisnodename, child->dirty, brtnode_size(child));
assert(rr == 0);
return r;
}
......@@ -953,7 +953,7 @@ static int brt_nonleaf_put_cmd_child (BRT t, BRTNODE node, BRT_CMD *cmd,
k->app_private, db, txn);
assert(r == 0);
} else {
int rr = cachetable_unpin_size(t->cf, child->thisnodename, child->dirty, brtnode_size(child));
int rr = cachetable_unpin(t->cf, child->thisnodename, child->dirty, brtnode_size(child));
assert(rr == 0);
}
return r;
......@@ -1052,7 +1052,7 @@ static int brtnode_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
}
int brt_create_cachetable_size(CACHETABLE *ct, int hashsize, long cachesize) {
return create_cachetable_size(ct, hashsize, cachesize);
return create_cachetable(ct, hashsize, cachesize);
}
//enum {n_nodes_in_cache =64};
......@@ -1078,7 +1078,7 @@ static int setup_brt_root_node (BRT t, diskoff offset) {
printf("%s:%d put root at %lld\n", __FILE__, __LINE__, offset);
}
//printf("%s:%d putting %p (%lld)\n", __FILE__, __LINE__, node, node->thisnodename);
r=cachetable_put_size(t->cf, offset, node, brtnode_size(node),
r=cachetable_put(t->cf, offset, node, brtnode_size(node),
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)t->h->nodesize);
if (r!=0) {
toku_free(node);
......@@ -1086,7 +1086,7 @@ static int setup_brt_root_node (BRT t, diskoff offset) {
}
//printf("%s:%d created %lld\n", __FILE__, __LINE__, node->thisnodename);
verify_counts(node);
r=cachetable_unpin_size(t->cf, node->thisnodename, node->dirty, brtnode_size(node));
r=cachetable_unpin(t->cf, node->thisnodename, node->dirty, brtnode_size(node));
if (r!=0) {
toku_free(node);
return r;
......@@ -1162,7 +1162,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
t->h->roots=0;
}
if ((r=setup_brt_root_node(t, nodesize))!=0) { if (dbname) goto died5; else goto died2; }
if ((r=cachetable_put(t->cf, 0, t->h, brtheader_flush_callback, brtheader_fetch_callback, 0))) { if (dbname) goto died5; else goto died2; }
if ((r=cachetable_put(t->cf, 0, t->h, 0, brtheader_flush_callback, brtheader_fetch_callback, 0))) { if (dbname) goto died5; else goto died2; }
} else {
int i;
assert(r==0);
......@@ -1263,12 +1263,12 @@ int brt_init_new_root(BRT brt, BRTNODE nodea, BRTNODE nodeb, DBT splitk, CACHEKE
r=toku_hashtable_create(&newroot->u.n.htables[0]); if (r!=0) return r;
r=toku_hashtable_create(&newroot->u.n.htables[1]); if (r!=0) return r;
verify_counts(newroot);
r=cachetable_unpin_size(brt->cf, nodea->thisnodename, nodea->dirty, brtnode_size(nodea));
r=cachetable_unpin(brt->cf, nodea->thisnodename, nodea->dirty, brtnode_size(nodea));
if (r!=0) return r;
r=cachetable_unpin_size(brt->cf, nodeb->thisnodename, nodeb->dirty, brtnode_size(nodeb));
r=cachetable_unpin(brt->cf, nodeb->thisnodename, nodeb->dirty, brtnode_size(nodeb));
if (r!=0) return r;
//printf("%s:%d put %lld\n", __FILE__, __LINE__, brt->root);
cachetable_put_size(brt->cf, newroot_diskoff, newroot, brtnode_size(newroot),
cachetable_put(brt->cf, newroot_diskoff, newroot, brtnode_size(newroot),
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize);
brt_update_cursors_new_root(brt, newroot, nodea, nodeb);
return 0;
......@@ -1290,7 +1290,7 @@ int brt_root_put_cmd(BRT brt, BRT_CMD *cmd, TOKUTXN txn) {
}
rootp = calculate_root_offset_pointer(brt);
if (debug) printf("%s:%d Getting %lld\n", __FILE__, __LINE__, *rootp);
if ((r=cachetable_get_and_pin(brt->cf, *rootp, &node_v,
if ((r=cachetable_get_and_pin(brt->cf, *rootp, &node_v, NULL,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize))) {
goto died0;
}
......@@ -1323,7 +1323,7 @@ int brt_root_put_cmd(BRT brt, BRT_CMD *cmd, TOKUTXN txn) {
dirty = node->dirty;
size = brtnode_size(node);
}
cachetable_unpin_size(brt->cf, *rootp, dirty, size);
cachetable_unpin(brt->cf, *rootp, dirty, size);
r = unpin_brt_header(brt);
assert(r == 0);
//assert(0==cachetable_assert_all_unpinned(brt->cachetable));
......@@ -1345,7 +1345,7 @@ int brt_insert (BRT brt, DBT *key, DBT *val, DB* db, TOKUTXN txn) {
int brt_lookup_node (BRT brt, diskoff off, DBT *k, DBT *v, DB *db, BRTNODE parent_brtnode) {
int result;
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, NULL,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize);
if (r!=0)
return r;
......@@ -1361,7 +1361,7 @@ int brt_lookup_node (BRT brt, diskoff off, DBT *k, DBT *v, DB *db, BRTNODE paren
if (node->height==0) {
result = pma_lookup(node->u.l.buffer, k, v, db);
//printf("%s:%d looked up something, got answerlen=%d\n", __FILE__, __LINE__, answerlen);
r = cachetable_unpin_size(brt->cf, off, 0, 0);
r = cachetable_unpin(brt->cf, off, 0, 0);
assert(r == 0);
return result;
}
......@@ -1383,14 +1383,14 @@ int brt_lookup_node (BRT brt, diskoff off, DBT *k, DBT *v, DB *db, BRTNODE paren
assert(0);
result = -1; // some versions of gcc complain
}
r = cachetable_unpin_size(brt->cf, off, 0, 0);
r = cachetable_unpin(brt->cf, off, 0, 0);
assert(r == 0);
return result;
}
}
result = brt_lookup_node(brt, node->u.n.children[childnum], k, v, db, node);
r = cachetable_unpin_size(brt->cf, off, 0, 0);
r = cachetable_unpin(brt->cf, off, 0, 0);
assert(r == 0);
return result;
}
......@@ -1439,7 +1439,7 @@ int dump_brtnode (BRT brt, diskoff off, int depth, bytevec lorange, ITEMLEN lole
int result=0;
BRTNODE node;
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, NULL,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize);
assert(r==0);
printf("%s:%d pin %p\n", __FILE__, __LINE__, node_v);
......@@ -1483,7 +1483,7 @@ int dump_brtnode (BRT brt, diskoff off, int depth, bytevec lorange, ITEMLEN lole
( keylen=keylen, vallen=vallen, printf(" %s:%s", (char*)key, (char*)val)));
printf("\n");
}
r = cachetable_unpin_size(brt->cf, off, 0, 0);
r = cachetable_unpin(brt->cf, off, 0, 0);
assert(r==0);
return result;
}
......@@ -1507,9 +1507,9 @@ int show_brtnode_blocknumbers (BRT brt, diskoff off, BRTNODE parent_brtnode) {
void *node_v;
int i,r;
assert(off%brt->h->nodesize==0);
if ((r = cachetable_get_and_pin(brt->cf, off, &node_v,
if ((r = cachetable_get_and_pin(brt->cf, off, &node_v, NULL,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize))) {
if (0) { died0: cachetable_unpin_size(brt->cf, off, 0, 0); }
if (0) { died0: cachetable_unpin(brt->cf, off, 0, 0); }
return r;
}
printf("%s:%d pin %p\n", __FILE__, __LINE__, node_v);
......@@ -1521,7 +1521,7 @@ int show_brtnode_blocknumbers (BRT brt, diskoff off, BRTNODE parent_brtnode) {
if ((r=show_brtnode_blocknumbers(brt, node->u.n.children[i], node))) goto died0;
}
}
r = cachetable_unpin_size(brt->cf, off, 0, 0);
r = cachetable_unpin(brt->cf, off, 0, 0);
return r;
}
......@@ -1545,7 +1545,7 @@ int verify_brtnode (BRT brt, diskoff off, bytevec lorange, ITEMLEN lolen, byteve
BRTNODE node;
void *node_v;
int r;
if ((r = cachetable_get_and_pin(brt->cf, off, &node_v,
if ((r = cachetable_get_and_pin(brt->cf, off, &node_v, NULL,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize)))
return r;
//printf("%s:%d pin %p\n", __FILE__, __LINE__, node_v);
......@@ -1601,7 +1601,7 @@ int verify_brtnode (BRT brt, diskoff off, bytevec lorange, ITEMLEN lolen, byteve
}
}
}
if ((r = cachetable_unpin_size(brt->cf, off, 0, 0))) return r;
if ((r = cachetable_unpin(brt->cf, off, 0, 0))) return r;
return result;
}
......@@ -1661,7 +1661,7 @@ void brt_flush_child(BRT t, BRTNODE node, int childnum, BRT_CURSOR cursor, void
CACHEKEY *rootp = calculate_root_offset_pointer(t);
r = brt_init_new_root(t, childa, childb, child_splitk, rootp);
assert(r == 0);
r = cachetable_unpin_size(t->cf, *rootp, 1, 0);
r = cachetable_unpin(t->cf, *rootp, CACHETABLE_DIRTY, 0);
assert(r == 0);
} else {
BRTNODE upnode;
......@@ -1802,7 +1802,7 @@ void brt_cursor_leaf_split(BRT_CURSOR cursor, BRT t, BRTNODE oldnode, BRTNODE le
if (0) printf("brt_cursor_leaf_split %p oldnode %lld newnode %lld\n", cursor,
oldnode->thisnodename, newnode->thisnodename);
r = cachetable_unpin_size(t->cf, oldnode->thisnodename, oldnode->dirty, brtnode_size(oldnode));
r = cachetable_unpin(t->cf, oldnode->thisnodename, oldnode->dirty, brtnode_size(oldnode));
assert(r == 0);
r = cachetable_maybe_get_and_pin(t->cf, newnode->thisnodename, &v);
assert(r == 0 && v == newnode);
......@@ -1877,7 +1877,7 @@ void brt_cursor_nonleaf_split(BRT_CURSOR cursor, BRT t, BRTNODE oldnode, BRTNODE
if (0) printf("brt_cursor_nonleaf_split %p oldnode %lld newnode %lld\n",
cursor, oldnode->thisnodename, newnode->thisnodename);
r = cachetable_unpin_size(t->cf, oldnode->thisnodename, oldnode->dirty, brtnode_size(oldnode));
r = cachetable_unpin(t->cf, oldnode->thisnodename, oldnode->dirty, brtnode_size(oldnode));
assert(r == 0);
r = cachetable_maybe_get_and_pin(t->cf, newnode->thisnodename, &v);
assert(r == 0 && v == newnode);
......@@ -1953,10 +1953,10 @@ int brtcurs_set_position_last (BRT_CURSOR cursor, diskoff off, DBT *key, DB *db,
BRT brt=cursor->brt;
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, NULL,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize);
if (r!=0) {
if (0) { died0: cachetable_unpin_size(brt->cf, off, 1, 0); }
if (0) { died0: cachetable_unpin(brt->cf, off, 1, 0); }
return r;
}
BRTNODE node = node_v;
......@@ -2015,10 +2015,10 @@ int brtcurs_set_position_first (BRT_CURSOR cursor, diskoff off, DBT *key, DB *db
BRT brt=cursor->brt;
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, NULL,
brtnode_flush_callback, brtnode_fetch_callback, (void*)(long)brt->h->nodesize);
if (r!=0) {
if (0) { died0: cachetable_unpin_size(brt->cf, off, 1, 0); }
if (0) { died0: cachetable_unpin(brt->cf, off, 1, 0); }
return r;
}
BRTNODE node = node_v;
......@@ -2086,7 +2086,7 @@ int brtcurs_set_position_next2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn)
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
cursor->path_len -= 1;
cachetable_unpin_size(cursor->brt->cf, node->thisnodename, node->dirty, brtnode_size(node));
cachetable_unpin(cursor->brt->cf, node->thisnodename, node->dirty, brtnode_size(node));
if (brt_cursor_path_empty(cursor))
return DB_NOTFOUND;
......@@ -2146,7 +2146,7 @@ int brtcurs_set_position_prev2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn)
node = cursor->path[cursor->path_len-1];
childnum = cursor->pathcnum[cursor->path_len-1];
cursor->path_len -= 1;
cachetable_unpin_size(cursor->brt->cf, node->thisnodename, node->dirty, brtnode_size(node));
cachetable_unpin(cursor->brt->cf, node->thisnodename, node->dirty, brtnode_size(node));
if (brt_cursor_path_empty(cursor))
return DB_NOTFOUND;
......@@ -2196,7 +2196,7 @@ int brtcurs_set_key(BRT_CURSOR cursor, diskoff off, DBT *key, DBT *val, int flag
BRT brt = cursor->brt;
void *node_v;
int r;
r = cachetable_get_and_pin(brt->cf, off, &node_v, brtnode_flush_callback,
r = cachetable_get_and_pin(brt->cf, off, &node_v, NULL, brtnode_flush_callback,
brtnode_fetch_callback, (void*)(long)brt->h->nodesize);
if (r != 0)
return r;
......@@ -2248,7 +2248,7 @@ int brtcurs_set_key(BRT_CURSOR cursor, diskoff off, DBT *key, DBT *val, int flag
if (r != 0) {
cursor->path_len -= 1;
cachetable_unpin_size(brt->cf, off, node->dirty, brtnode_size(node));
cachetable_unpin(brt->cf, off, node->dirty, brtnode_size(node));
}
return r;
}
......@@ -2257,7 +2257,7 @@ int brtcurs_set_range(BRT_CURSOR cursor, diskoff off, DBT *key, DB *db, TOKUTXN
BRT brt = cursor->brt;
void *node_v;
int r;
r = cachetable_get_and_pin(brt->cf, off, &node_v, brtnode_flush_callback,
r = cachetable_get_and_pin(brt->cf, off, &node_v, NULL, brtnode_flush_callback,
brtnode_fetch_callback, (void*)(long)brt->h->nodesize);
if (r != 0)
return r;
......@@ -2311,7 +2311,7 @@ int brtcurs_set_range(BRT_CURSOR cursor, diskoff off, DBT *key, DB *db, TOKUTXN
if (r != 0) {
cursor->path_len -= 1;
cachetable_unpin_size(brt->cf, off, node->dirty, brtnode_size(node));
cachetable_unpin(brt->cf, off, node->dirty, brtnode_size(node));
}
return r;
}
......@@ -2323,7 +2323,7 @@ static int unpin_cursor (BRT_CURSOR cursor) {
for (i=0; i<cursor->path_len; i++) {
BRTNODE node = cursor->path[i];
brt_node_remove_cursor(node, cursor->pathcnum[i], cursor);
int r2 = cachetable_unpin_size(brt->cf, node->thisnodename, node->dirty, brtnode_size(node));
int r2 = cachetable_unpin(brt->cf, node->thisnodename, node->dirty, brtnode_size(node));
if (r==0) r=r2;
}
if (cursor->pmacurs) {
......
......@@ -8,6 +8,8 @@
#include "memory.h"
#include "cachetable.h"
const int test_object_size = 1;
struct item {
CACHEKEY key;
char *something;
......@@ -74,7 +76,7 @@ void test0 (void) {
CACHEFILE f;
int r;
char fname[] = "test.dat";
r=create_cachetable(&t, 5);
r=create_cachetable(&t, 5, 5);
assert(r==0);
unlink(fname);
r = cachetable_openf(&f, t, fname, O_RDWR|O_CREAT, 0777);
......@@ -82,52 +84,52 @@ void test0 (void) {
expect_f = f;
expect_n_flushes=0;
r=cachetable_put(f, 1, make_item(1), flush, fetch, t3); /* 1P */ /* this is the lru list. 1 is pinned. */
r=cachetable_put(f, 1, make_item(1), test_object_size, flush, fetch, t3); /* 1P */ /* this is the lru list. 1 is pinned. */
assert(r==0);
assert(expect_n_flushes==0);
expect_n_flushes=0;
r=cachetable_put(f, 2, make_item(2), flush, fetch, t3);
r=cachetable_put(f, 2, make_item(2), test_object_size, flush, fetch, t3);
assert(r==0);
r=cachetable_unpin(f, 2, 1); /* 2U 1P */
r=cachetable_unpin(f, 2, CACHETABLE_DIRTY, 1); /* 2U 1P */
assert(expect_n_flushes==0);
expect_n_flushes=0;
r=cachetable_put(f, 3, make_item(3), flush, fetch, t3);
r=cachetable_put(f, 3, make_item(3), test_object_size, flush, fetch, t3);
assert(r==0);
assert(expect_n_flushes==0); /* 3P 2U 1P */ /* 3 is most recently used (pinned), 2 is next (unpinned), 1 is least recent (pinned) */
expect_n_flushes=0;
r=cachetable_put(f, 4, make_item(4), flush, fetch, t3);
r=cachetable_put(f, 4, make_item(4), test_object_size, flush, fetch, t3);
assert(r==0);
assert(expect_n_flushes==0); /* 4P 3P 2U 1P */
expect_n_flushes=0;
r=cachetable_put(f, 5, make_item(5), flush, fetch, t3);
r=cachetable_put(f, 5, make_item(5), test_object_size, flush, fetch, t3);
assert(r==0);
r=cachetable_unpin(f, 5, 1);
r=cachetable_unpin(f, 5, CACHETABLE_DIRTY, test_object_size);
assert(r==0);
r=cachetable_unpin(f, 3, 1);
r=cachetable_unpin(f, 3, CACHETABLE_DIRTY, test_object_size);
assert(r==0);
assert(expect_n_flushes==0); /* 5U 4P 3U 2U 1P */
expect1(2); /* 2 is the oldest unpinned item. */
r=cachetable_put(f, 6, make_item(6), flush, fetch, t3); /* 6P 5U 4P 3U 1P */
r=cachetable_put(f, 6, make_item(6), test_object_size, flush, fetch, t3); /* 6P 5U 4P 3U 1P */
assert(r==0);
assert(expect_n_flushes==0);
expect1(3);
r=cachetable_put(f, 7, make_item(7), flush, fetch, t3);
r=cachetable_put(f, 7, make_item(7), test_object_size, flush, fetch, t3);
assert(r==0);
assert(expect_n_flushes==0);
r=cachetable_unpin(f, 7, 1); /* 7U 6P 5U 4P 1P */
r=cachetable_unpin(f, 7, CACHETABLE_DIRTY, test_object_size); /* 7U 6P 5U 4P 1P */
assert(r==0);
{
void *item_v=0;
expect_n_flushes=0;
r=cachetable_get_and_pin(f, 5, &item_v, flush, fetch, t3); /* 5P 7U 6P 4P 1P */
r=cachetable_get_and_pin(f, 5, &item_v, NULL, flush, fetch, t3); /* 5P 7U 6P 4P 1P */
assert(r==0);
assert(((struct item *)item_v)->key==5);
assert(strcmp(((struct item *)item_v)->something,"something")==0);
......@@ -136,11 +138,11 @@ void test0 (void) {
{
void *item_v=0;
r=cachetable_unpin(f, 4, 1);
r=cachetable_unpin(f, 4, CACHETABLE_DIRTY, test_object_size);
assert(r==0);
expect1(4);
did_fetch=-1;
r=cachetable_get_and_pin(f, 2, &item_v, flush, fetch, t3); /* 2p 5P 7U 6P 1P */
r=cachetable_get_and_pin(f, 2, &item_v, NULL, flush, fetch, t3); /* 2p 5P 7U 6P 1P */
assert(r==0);
assert(did_fetch==2); /* Expect that 2 is fetched in. */
assert(((struct item *)item_v)->key==2);
......@@ -148,13 +150,13 @@ void test0 (void) {
assert(expect_n_flushes==0);
}
r=cachetable_unpin(f, 2, 1);
r=cachetable_unpin(f, 2, CACHETABLE_DIRTY, test_object_size);
assert(r==0);
r=cachetable_unpin(f ,5, 1);
r=cachetable_unpin(f ,5, CACHETABLE_DIRTY, test_object_size);
assert(r==0);
r=cachetable_unpin(f, 6, 1);
r=cachetable_unpin(f, 6, CACHETABLE_DIRTY, test_object_size);
assert(r==0);
r=cachetable_unpin(f, 1, 1);
r=cachetable_unpin(f, 1, CACHETABLE_DIRTY, test_object_size);
assert(r==0);
r=cachetable_assert_all_unpinned(t);
assert(r==0);
......@@ -196,7 +198,7 @@ void test_nested_pin (void) {
int r;
void *vv;
char fname[] = "test_ct.dat";
r = create_cachetable(&t, 1);
r = create_cachetable(&t, 1, 1);
assert(r==0);
unlink(fname);
r = cachetable_openf(&f, t, fname, O_RDWR|O_CREAT, 0777);
......@@ -204,19 +206,19 @@ void test_nested_pin (void) {
expect_f = f;
i0=0; i1=0;
r = cachetable_put(f, 1, &i0, flush_n, fetch_n, f2);
r = cachetable_put(f, 1, &i0, 1, flush_n, fetch_n, f2);
assert(r==0);
r = cachetable_get_and_pin(f, 1, &vv, flush_n, fetch_n, f2);
r = cachetable_get_and_pin(f, 1, &vv, NULL, flush_n, fetch_n, f2);
assert(r==0);
assert(vv==&i0);
assert(i0==0);
r = cachetable_unpin(f, 1, 0);
r = cachetable_unpin(f, 1, 0, test_object_size);
assert(r==0);
r = cachetable_put(f, 2, &i1, flush_n, fetch_n, f2);
r = cachetable_put(f, 2, &i1, test_object_size, flush_n, fetch_n, f2);
assert(r!=0); // previously pinned, we shouldn't be able to put.
r = cachetable_unpin(f, 1, 0);
r = cachetable_unpin(f, 1, 0, test_object_size);
assert(r==0);
r = cachetable_put(f, 2, &i1, flush_n, fetch_n, f2);
r = cachetable_put(f, 2, &i1, test_object_size, flush_n, fetch_n, f2);
assert(r==0); // now it is unpinned, we can put it.
r = cachefile_close(&f); assert(r==0);
......@@ -255,7 +257,7 @@ void test_multi_filehandles (void) {
unlink(fname1);
unlink(fname2);
r = create_cachetable(&t, 4); assert(r==0);
r = create_cachetable(&t, 4, 4); assert(r==0);
r = cachetable_openf(&f1, t, fname1, O_RDWR|O_CREAT, 0777); assert(r==0);
r = link(fname1, fname2); assert(r==0);
r = cachetable_openf(&f2, t, fname2, O_RDWR|O_CREAT, 0777); assert(r==0);
......@@ -264,12 +266,12 @@ void test_multi_filehandles (void) {
assert(f1==f2);
assert(f1!=f3);
r = cachetable_put(f1, 1, (void*)124, null_flush, add123_fetch, (void*)123); assert(r==0);
r = cachetable_get_and_pin(f2, 1, &v, null_flush, add123_fetch, (void*)123); assert(r==0);
r = cachetable_put(f1, 1, (void*)124, test_object_size, null_flush, add123_fetch, (void*)123); assert(r==0);
r = cachetable_get_and_pin(f2, 1, &v, NULL, null_flush, add123_fetch, (void*)123); assert(r==0);
assert((unsigned long)v==124);
r = cachetable_get_and_pin(f2, 2, &v, null_flush, add123_fetch, (void*)123); assert(r==0);
r = cachetable_get_and_pin(f2, 2, &v, NULL, null_flush, add123_fetch, (void*)123); assert(r==0);
assert((unsigned long)v==125);
r = cachetable_get_and_pin(f3, 2, &v, null_flush, add222_fetch, (void*)222); assert(r==0);
r = cachetable_get_and_pin(f3, 2, &v, NULL, null_flush, add222_fetch, (void*)222); assert(r==0);
assert((unsigned long)v==224);
r = cachetable_maybe_get_and_pin(f1, 2, &v); assert(r==0);
assert((unsigned long)v==125);
......@@ -299,7 +301,7 @@ void test_dirty() {
int dirty; long long pinned; long entry_size;
int r;
r = create_cachetable(&t, 4);
r = create_cachetable(&t, 4, 4);
assert(r == 0);
char *fname = "test.dat";
......@@ -308,7 +310,7 @@ void test_dirty() {
assert(r == 0);
key = 1; value = (void*)1;
r = cachetable_put(f, key, value, test_dirty_flush, 0, 0);
r = cachetable_put(f, key, value, test_object_size, test_dirty_flush, 0, 0);
assert(r == 0);
// cachetable_print_state(t);
......@@ -317,14 +319,14 @@ void test_dirty() {
assert(dirty == 1);
assert(pinned == 1);
r = cachetable_unpin(f, key, 0);
r = cachetable_unpin(f, key, CACHETABLE_CLEAN, 0);
assert(r == 0);
r = cachetable_get_key_state(t, key, &value, &dirty, &pinned, &entry_size);
assert(r == 0);
assert(dirty == 1);
assert(pinned == 0);
r = cachetable_get_and_pin(f, key, &value, test_dirty_flush,
r = cachetable_get_and_pin(f, key, &value, NULL, test_dirty_flush,
test_dirty_fetch, 0);
assert(r == 0);
......@@ -334,7 +336,7 @@ void test_dirty() {
assert(dirty == 1);
assert(pinned == 1);
r = cachetable_unpin(f, key, 0);
r = cachetable_unpin(f, key, CACHETABLE_CLEAN, test_object_size);
assert(r == 0);
// cachetable_print_state(t);
......@@ -344,7 +346,7 @@ void test_dirty() {
assert(pinned == 0);
key = 2;
r = cachetable_get_and_pin(f, key, &value, test_dirty_flush,
r = cachetable_get_and_pin(f, key, &value, NULL, test_dirty_flush,
test_dirty_fetch, 0);
assert(r == 0);
......@@ -354,7 +356,7 @@ void test_dirty() {
assert(dirty == 0);
assert(pinned == 1);
r = cachetable_unpin(f, key, 0);
r = cachetable_unpin(f, key, CACHETABLE_CLEAN, test_object_size);
assert(r == 0);
// cachetable_print_state(t);
......@@ -363,7 +365,7 @@ void test_dirty() {
assert(dirty == 0);
assert(pinned == 0);
r = cachetable_get_and_pin(f, key, &value, test_dirty_flush,
r = cachetable_get_and_pin(f, key, &value, NULL, test_dirty_flush,
test_dirty_fetch, 0);
assert(r == 0);
......@@ -373,7 +375,7 @@ void test_dirty() {
assert(dirty == 0);
assert(pinned == 1);
r = cachetable_unpin(f, key, 1);
r = cachetable_unpin(f, key, CACHETABLE_DIRTY, test_object_size);
assert(r == 0);
// cachetable_print_state(t);
......@@ -407,7 +409,7 @@ void test_size_resize() {
int n = 3;
long size = 1;
r = create_cachetable_size(&t, n, n*size);
r = create_cachetable(&t, n, n*size);
assert(r == 0);
char *fname = "test.dat";
......@@ -418,7 +420,7 @@ void test_size_resize() {
CACHEKEY key = 42;
void *value = (void *) -42;
r = cachetable_put_size(f, key, value, size, test_size_flush_callback, 0, 0);
r = cachetable_put(f, key, value, size, test_size_flush_callback, 0, 0);
assert(r == 0);
void *entry_value; int dirty; long long pinned; long entry_size;
......@@ -430,17 +432,17 @@ void test_size_resize() {
assert(entry_size == size);
long long new_size = 2*size;
r = cachetable_unpin_size(f, key, 0, new_size);
r = cachetable_unpin(f, key, CACHETABLE_CLEAN, new_size);
assert(r == 0);
void *current_value;
long current_size;
r = cachetable_get_and_pin_size(f, key, &current_value, &current_size, test_size_flush_callback, 0, 0);
r = cachetable_get_and_pin(f, key, &current_value, &current_size, test_size_flush_callback, 0, 0);
assert(r == 0);
assert(current_value == value);
assert(current_size == new_size);
r = cachetable_unpin_size(f, key, 0, new_size);
r = cachetable_unpin(f, key, CACHETABLE_CLEAN, new_size);
assert(r == 0);
r = cachefile_close(&f);
......@@ -458,7 +460,7 @@ void test_size_flush() {
const int n = 8;
long long size = 1*1024*1024;
r = create_cachetable_size(&t, 3, n*size);
r = create_cachetable(&t, 3, n*size);
assert(r == 0);
char *fname = "test.dat";
......@@ -475,7 +477,7 @@ void test_size_flush() {
CACHEKEY key = i;
void *value = (void *)(long)-i;
// printf("test_size put %lld %p %lld\n", key, value, size);
r = cachetable_put_size(f, key, value, size, test_size_flush_callback, 0, 0);
r = cachetable_put(f, key, value, size, test_size_flush_callback, 0, 0);
assert(r == 0);
int n_entries;
......@@ -497,7 +499,7 @@ void test_size_flush() {
expect_flush_key += 1;
}
r = cachetable_unpin_size(f, key, 0, size);
r = cachetable_unpin(f, key, CACHETABLE_CLEAN, size);
assert(r == 0);
}
......
......@@ -6,6 +6,8 @@
#include <stdlib.h>
#include <unistd.h>
const int test_object_size = 1;
CACHETABLE ct;
enum { N_PRESENT_LIMIT = 4, TRIALS=200, N_FILES=2 };
......@@ -79,7 +81,7 @@ void verify_cachetable_against_present (void) {
assert(cachetable_maybe_get_and_pin(present_items[i].cf,
present_items[i].key,
&v)==0);
r = cachetable_unpin(present_items[i].cf, present_items[i].key, 0);
r = cachetable_unpin(present_items[i].cf, present_items[i].key, CACHETABLE_CLEAN, test_object_size);
}
}
......@@ -91,7 +93,7 @@ void test_chaining (void) {
char fname[N_FILES][FILENAME_LEN];
int r;
long i, trial;
r = create_cachetable(&ct, N_PRESENT_LIMIT); assert(r==0);
r = create_cachetable(&ct, N_PRESENT_LIMIT, N_PRESENT_LIMIT); assert(r==0);
for (i=0; i<N_FILES; i++) {
int r = snprintf(fname[i], FILENAME_LEN, "cachetabletest2.%ld.dat", i);
assert(r>0 && r<FILENAME_LEN);
......@@ -101,9 +103,9 @@ void test_chaining (void) {
for (i=0; i<N_PRESENT_LIMIT; i++) {
int fnum = i%N_FILES;
//printf("%s:%d Add %d\n", __FILE__, __LINE__, i);
r = cachetable_put(f[fnum], i, (void*)i, flush_forchain, fetch_forchain, (void*)i); assert(r==0);
r = cachetable_put(f[fnum], i, (void*)i, test_object_size, flush_forchain, fetch_forchain, (void*)i); assert(r==0);
item_becomes_present(f[fnum], i);
r = cachetable_unpin(f[fnum], i, 0); assert(r==0);
r = cachetable_unpin(f[fnum], i, CACHETABLE_CLEAN, test_object_size); assert(r==0);
//print_ints();
}
for (trial=0; trial<TRIALS; trial++) {
......@@ -115,6 +117,7 @@ void test_chaining (void) {
r = cachetable_get_and_pin(present_items[whichone].cf,
present_items[whichone].key,
&value,
NULL,
flush_forchain,
fetch_forchain,
(void*)(long)present_items[whichone].key
......@@ -122,7 +125,7 @@ void test_chaining (void) {
assert(r==0);
r = cachetable_unpin(present_items[whichone].cf,
present_items[whichone].key,
0);
CACHETABLE_CLEAN, test_object_size);
assert(r==0);
}
......@@ -130,11 +133,11 @@ void test_chaining (void) {
int fnum = i%N_FILES;
// i is always incrementing, so we need not worry about inserting a duplicate
//printf("%s:%d Add {%d,%p}\n", __FILE__, __LINE__, i, f[fnum]);
r = cachetable_put(f[fnum], i, (void*)i, flush_forchain, fetch_forchain, (void*)i); assert(r==0);
r = cachetable_put(f[fnum], i, (void*)i, test_object_size, flush_forchain, fetch_forchain, (void*)i); assert(r==0);
item_becomes_present(f[fnum], i);
//print_ints();
//cachetable_print_state(ct);
r = cachetable_unpin(f[fnum], i, 0); assert(r==0);
r = cachetable_unpin(f[fnum], i, CACHETABLE_CLEAN, test_object_size); assert(r==0);
verify_cachetable_against_present();
if (random()%10==0) {
......
......@@ -59,7 +59,7 @@ struct cachefile {
struct fileid fileid;
};
int create_cachetable_size(CACHETABLE *result, int table_size __attribute__((unused)), long size_limit) {
int create_cachetable(CACHETABLE *result, int table_size __attribute__((unused)), long size_limit) {
TAGMALLOC(CACHETABLE, t);
int i;
t->n_in_table = 0;
......@@ -334,7 +334,7 @@ static int cachetable_insert_at(CACHEFILE cachefile, int h, CACHEKEY key, void *
return 0;
}
int cachetable_put_size(CACHEFILE cachefile, CACHEKEY key, void*value, long size,
int cachetable_put(CACHEFILE cachefile, CACHEKEY key, void*value, long size,
cachetable_flush_func_t flush_callback, cachetable_fetch_func_t fetch_callback, void *extraargs) {
WHEN_TRACE_CT(printf("%s:%d CT cachetable_put(%lld)=%p\n", __FILE__, __LINE__, key, value));
{
......@@ -356,7 +356,7 @@ int cachetable_put_size(CACHEFILE cachefile, CACHEKEY key, void*value, long size
return r;
}
int cachetable_get_and_pin_size (CACHEFILE cachefile, CACHEKEY key, void**value, long *sizep,
int cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, void**value, long *sizep,
cachetable_flush_func_t flush_callback, cachetable_fetch_func_t fetch_callback, void *extraargs) {
CACHETABLE t = cachefile->cachetable;
int tsize __attribute__((__unused__)) = t->table_size;
......@@ -364,7 +364,7 @@ int cachetable_get_and_pin_size (CACHEFILE cachefile, CACHEKEY key, void**value,
for (p=t->table[hashit(t,key)]; p; p=p->hash_chain) {
if (p->key==key && p->cachefile==cachefile) {
*value = p->value;
*sizep = p->size;
if (sizep) *sizep = p->size;
p->pinned++;
lru_touch(t,p);
WHEN_TRACE_CT(printf("%s:%d cachtable_get_and_pin(%lld)--> %p\n", __FILE__, __LINE__, key, *value));
......@@ -406,7 +406,7 @@ int cachetable_maybe_get_and_pin (CACHEFILE cachefile, CACHEKEY key, void**value
}
int cachetable_unpin_size (CACHEFILE cachefile, CACHEKEY key, int dirty, long size) {
int cachetable_unpin(CACHEFILE cachefile, CACHEKEY key, int dirty, long size) {
CACHETABLE t = cachefile->cachetable;
PAIR p;
WHEN_TRACE_CT(printf("%s:%d unpin(%lld)", __FILE__, __LINE__, key));
......
......@@ -22,7 +22,7 @@ typedef struct cachefile *CACHEFILE;
* table_size is the initial size of the cache table hash table (in number of entries)
* size limit is the upper bound of the sum of size of the entries in the cache table (total number of bytes)
*/
int create_cachetable_size(CACHETABLE */*result*/, int table_size, long size_limit);
int create_cachetable(CACHETABLE */*result*/, int table_size, long size_limit);
int cachetable_openf (CACHEFILE *,CACHETABLE, const char */*fname*/, int flags, mode_t mode);
......@@ -32,16 +32,21 @@ typedef void (*cachetable_flush_func_t)(CACHEFILE, CACHEKEY key, void*value, lon
typedef int (*cachetable_fetch_func_t)(CACHEFILE, CACHEKEY key, void **value, long *sizep, void *extraargs);
/* Error if already present. On success, pin the value. */
int cachetable_put_size(CACHEFILE cf, CACHEKEY key, void* value, long size,
int cachetable_put(CACHEFILE cf, CACHEKEY key, void* value, long size,
cachetable_flush_func_t flush_callback, cachetable_fetch_func_t fetch_callback, void *extraargs);
int cachetable_get_and_pin_size(CACHEFILE, CACHEKEY, void**/*value*/, long *sizep,
int cachetable_get_and_pin(CACHEFILE, CACHEKEY, void**/*value*/, long *sizep,
cachetable_flush_func_t flush_callback, cachetable_fetch_func_t fetch_callback, void *extraargs);
/* If the the item is already in memory, then return 0 and store it in the void**.
* If the item is not in memory, then return nonzero. */
int cachetable_maybe_get_and_pin (CACHEFILE, CACHEKEY, void**);
int cachetable_unpin_size (CACHEFILE, CACHEKEY, int dirty, long size); /* Note whether it is dirty when we unpin it. */
/* cachetable object state wrt external memory */
#define CACHETABLE_CLEAN 0
#define CACHETABLE_DIRTY 1
int cachetable_unpin(CACHEFILE, CACHEKEY, int dirty, long size); /* Note whether it is dirty when we unpin it. */
int cachetable_remove (CACHEFILE, CACHEKEY, int /*write_me*/); /* Removing something already present is OK. */
int cachetable_assert_all_unpinned (CACHETABLE);
int cachefile_count_pinned (CACHEFILE, int /*printthem*/ );
......@@ -64,27 +69,6 @@ void cachetable_get_state(CACHETABLE ct, int *num_entries_ptr, int *hash_size_pt
int cachetable_get_key_state(CACHETABLE ct, CACHEKEY key, void **value_ptr,
int *dirty_ptr, long long *pin_ptr, long *size_ptr);
// Compat, will be removed
static inline int create_cachetable (CACHETABLE *result, int table_size) {
return create_cachetable_size(result, table_size, table_size);
}
static inline int cachetable_put(CACHEFILE cf, CACHEKEY key, void* value,
cachetable_flush_func_t flush_callback, cachetable_fetch_func_t fetch_callback, void *extraargs) {
return cachetable_put_size(cf, key, value, 1, flush_callback, fetch_callback, extraargs);
}
static inline int cachetable_get_and_pin (CACHEFILE cf, CACHEKEY key, void **valuep,
cachetable_flush_func_t flush_callback, cachetable_fetch_func_t fetch_callback,
void *extraargs) {
long size;
return cachetable_get_and_pin_size(cf, key, valuep, &size, flush_callback, fetch_callback, extraargs);
}
static inline int cachetable_unpin(CACHEFILE cf, CACHEKEY key, int dirty) {
return cachetable_unpin_size(cf, key, dirty, 1);
}
void cachefile_verify (CACHEFILE cf); // Verify the whole cachetable that the CF is in. Slow.
void cachetable_verify (CACHETABLE t); // Slow...
......
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