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
This diff is collapsed.
This diff is collapsed.
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
const int test_object_size = 1;
CACHETABLE ct; CACHETABLE ct;
enum { N_PRESENT_LIMIT = 4, TRIALS=200, N_FILES=2 }; enum { N_PRESENT_LIMIT = 4, TRIALS=200, N_FILES=2 };
...@@ -79,7 +81,7 @@ void verify_cachetable_against_present (void) { ...@@ -79,7 +81,7 @@ void verify_cachetable_against_present (void) {
assert(cachetable_maybe_get_and_pin(present_items[i].cf, assert(cachetable_maybe_get_and_pin(present_items[i].cf,
present_items[i].key, present_items[i].key,
&v)==0); &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) { ...@@ -91,7 +93,7 @@ void test_chaining (void) {
char fname[N_FILES][FILENAME_LEN]; char fname[N_FILES][FILENAME_LEN];
int r; int r;
long i, trial; 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++) { for (i=0; i<N_FILES; i++) {
int r = snprintf(fname[i], FILENAME_LEN, "cachetabletest2.%ld.dat", i); int r = snprintf(fname[i], FILENAME_LEN, "cachetabletest2.%ld.dat", i);
assert(r>0 && r<FILENAME_LEN); assert(r>0 && r<FILENAME_LEN);
...@@ -101,9 +103,9 @@ void test_chaining (void) { ...@@ -101,9 +103,9 @@ void test_chaining (void) {
for (i=0; i<N_PRESENT_LIMIT; i++) { for (i=0; i<N_PRESENT_LIMIT; i++) {
int fnum = i%N_FILES; int fnum = i%N_FILES;
//printf("%s:%d Add %d\n", __FILE__, __LINE__, i); //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); 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(); //print_ints();
} }
for (trial=0; trial<TRIALS; trial++) { for (trial=0; trial<TRIALS; trial++) {
...@@ -115,6 +117,7 @@ void test_chaining (void) { ...@@ -115,6 +117,7 @@ void test_chaining (void) {
r = cachetable_get_and_pin(present_items[whichone].cf, r = cachetable_get_and_pin(present_items[whichone].cf,
present_items[whichone].key, present_items[whichone].key,
&value, &value,
NULL,
flush_forchain, flush_forchain,
fetch_forchain, fetch_forchain,
(void*)(long)present_items[whichone].key (void*)(long)present_items[whichone].key
...@@ -122,7 +125,7 @@ void test_chaining (void) { ...@@ -122,7 +125,7 @@ void test_chaining (void) {
assert(r==0); assert(r==0);
r = cachetable_unpin(present_items[whichone].cf, r = cachetable_unpin(present_items[whichone].cf,
present_items[whichone].key, present_items[whichone].key,
0); CACHETABLE_CLEAN, test_object_size);
assert(r==0); assert(r==0);
} }
...@@ -130,11 +133,11 @@ void test_chaining (void) { ...@@ -130,11 +133,11 @@ void test_chaining (void) {
int fnum = i%N_FILES; int fnum = i%N_FILES;
// i is always incrementing, so we need not worry about inserting a duplicate // 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]); //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); item_becomes_present(f[fnum], i);
//print_ints(); //print_ints();
//cachetable_print_state(ct); //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(); verify_cachetable_against_present();
if (random()%10==0) { if (random()%10==0) {
......
...@@ -59,7 +59,7 @@ struct cachefile { ...@@ -59,7 +59,7 @@ struct cachefile {
struct fileid fileid; 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); TAGMALLOC(CACHETABLE, t);
int i; int i;
t->n_in_table = 0; t->n_in_table = 0;
...@@ -334,8 +334,8 @@ static int cachetable_insert_at(CACHEFILE cachefile, int h, CACHEKEY key, void * ...@@ -334,8 +334,8 @@ static int cachetable_insert_at(CACHEFILE cachefile, int h, CACHEKEY key, void *
return 0; 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) { 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)); WHEN_TRACE_CT(printf("%s:%d CT cachetable_put(%lld)=%p\n", __FILE__, __LINE__, key, value));
{ {
PAIR p; PAIR p;
...@@ -356,15 +356,15 @@ int cachetable_put_size(CACHEFILE cachefile, CACHEKEY key, void*value, long size ...@@ -356,15 +356,15 @@ int cachetable_put_size(CACHEFILE cachefile, CACHEKEY key, void*value, long size
return r; 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_flush_func_t flush_callback, cachetable_fetch_func_t fetch_callback, void *extraargs) {
CACHETABLE t = cachefile->cachetable; CACHETABLE t = cachefile->cachetable;
int tsize __attribute__((__unused__)) = t->table_size; int tsize __attribute__((__unused__)) = t->table_size;
PAIR p; PAIR p;
for (p=t->table[hashit(t,key)]; p; p=p->hash_chain) { for (p=t->table[hashit(t,key)]; p; p=p->hash_chain) {
if (p->key==key && p->cachefile==cachefile) { if (p->key==key && p->cachefile==cachefile) {
*value = p->value; *value = p->value;
*sizep = p->size; if (sizep) *sizep = p->size;
p->pinned++; p->pinned++;
lru_touch(t,p); lru_touch(t,p);
WHEN_TRACE_CT(printf("%s:%d cachtable_get_and_pin(%lld)--> %p\n", __FILE__, __LINE__, key, *value)); 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 ...@@ -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; CACHETABLE t = cachefile->cachetable;
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));
......
...@@ -22,7 +22,7 @@ typedef struct cachefile *CACHEFILE; ...@@ -22,7 +22,7 @@ typedef struct cachefile *CACHEFILE;
* table_size is the initial size of the cache table hash table (in number of entries) * 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) * 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); 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 ...@@ -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); typedef int (*cachetable_fetch_func_t)(CACHEFILE, CACHEKEY key, void **value, long *sizep, void *extraargs);
/* Error if already present. On success, pin the value. */ /* 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); 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); 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 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. */ * If the item is not in memory, then return nonzero. */
int cachetable_maybe_get_and_pin (CACHEFILE, CACHEKEY, void**); 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_remove (CACHEFILE, CACHEKEY, int /*write_me*/); /* Removing something already present is OK. */
int cachetable_assert_all_unpinned (CACHETABLE); int cachetable_assert_all_unpinned (CACHETABLE);
int cachefile_count_pinned (CACHEFILE, int /*printthem*/ ); 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 ...@@ -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 cachetable_get_key_state(CACHETABLE ct, CACHEKEY key, void **value_ptr,
int *dirty_ptr, long long *pin_ptr, long *size_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 cachefile_verify (CACHEFILE cf); // Verify the whole cachetable that the CF is in. Slow.
void cachetable_verify (CACHETABLE t); // 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