Commit 7a972d5d authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

refs #5171, remove tabs from cachetable-test2

git-svn-id: file:///svn/toku/tokudb@45098 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8834ba63
...@@ -47,8 +47,8 @@ static void print_ints(void) __attribute__((__unused__)); ...@@ -47,8 +47,8 @@ static void print_ints(void) __attribute__((__unused__));
static void print_ints(void) { static void print_ints(void) {
int i; int i;
for (i=0; i<n_present; i++) { for (i=0; i<n_present; i++) {
if (i==0) printf("{"); else printf(","); if (i==0) printf("{"); else printf(",");
printf("{%" PRId64 ",%p}", present_items[i].key.b, present_items[i].cf); printf("{%" PRId64 ",%p}", present_items[i].key.b, present_items[i].cf);
} }
printf("}\n"); printf("}\n");
} }
...@@ -71,13 +71,13 @@ static void item_becomes_not_present(CACHEFILE cf, CACHEKEY key) { ...@@ -71,13 +71,13 @@ static void item_becomes_not_present(CACHEFILE cf, CACHEKEY key) {
test_mutex_lock(); test_mutex_lock();
assert(n_present<=N_PRESENT_LIMIT); assert(n_present<=N_PRESENT_LIMIT);
for (i=0; i<n_present; i++) { for (i=0; i<n_present; i++) {
if (present_items[i].cf==cf && present_items[i].key.b==key.b) { if (present_items[i].cf==cf && present_items[i].key.b==key.b) {
present_items[i]=present_items[n_present-1]; present_items[i]=present_items[n_present-1];
n_present--; n_present--;
test_mutex_unlock(); test_mutex_unlock();
//printf(" Finally: "); print_ints(); //printf(" Finally: "); print_ints();
return; return;
} }
} }
printf("Whoops, %p,%" PRId64 " was already not present\n", cf ,key.b); printf("Whoops, %p,%" PRId64 " was already not present\n", cf ,key.b);
abort(); abort();
...@@ -88,7 +88,7 @@ static void file_is_not_present(CACHEFILE cf) { ...@@ -88,7 +88,7 @@ static void file_is_not_present(CACHEFILE cf) {
int i; int i;
test_mutex_lock(); test_mutex_lock();
for (i=0; i<n_present; i++) { for (i=0; i<n_present; i++) {
assert(present_items[i].cf!=cf); assert(present_items[i].cf!=cf);
} }
test_mutex_unlock(); test_mutex_unlock();
} }
...@@ -96,17 +96,17 @@ static void file_is_not_present(CACHEFILE cf) { ...@@ -96,17 +96,17 @@ static void file_is_not_present(CACHEFILE cf) {
static void flush_forchain (CACHEFILE f __attribute__((__unused__)), static void flush_forchain (CACHEFILE f __attribute__((__unused__)),
int UU(fd), int UU(fd),
CACHEKEY key, CACHEKEY key,
void *value, void *value,
void** UU(dd), void** UU(dd),
void *extra __attribute__((__unused__)), void *extra __attribute__((__unused__)),
PAIR_ATTR size __attribute__((__unused__)), PAIR_ATTR size __attribute__((__unused__)),
PAIR_ATTR* new_size __attribute__((__unused__)), PAIR_ATTR* new_size __attribute__((__unused__)),
BOOL write_me __attribute__((__unused__)), BOOL write_me __attribute__((__unused__)),
BOOL keep_me __attribute__((__unused__)), BOOL keep_me __attribute__((__unused__)),
BOOL for_checkpoint __attribute__((__unused__)), BOOL for_checkpoint __attribute__((__unused__)),
BOOL UU(is_clone) BOOL UU(is_clone)
) { ) {
if (keep_me) return; if (keep_me) return;
int *v = value; int *v = value;
//toku_cachetable_print_state(ct); //toku_cachetable_print_state(ct);
...@@ -117,7 +117,7 @@ static void flush_forchain (CACHEFILE f __attribute__((__unused__)), ...@@ -117,7 +117,7 @@ static void flush_forchain (CACHEFILE f __attribute__((__unused__)),
} }
static int fetch_forchain (CACHEFILE f, int UU(fd), CACHEKEY key, u_int32_t fullhash, void**value, static int fetch_forchain (CACHEFILE f, int UU(fd), CACHEKEY key, u_int32_t fullhash, void**value,
void** UU(dd), void** UU(dd),
PAIR_ATTR *sizep __attribute__((__unused__)), int * dirtyp, void*extraargs) { PAIR_ATTR *sizep __attribute__((__unused__)), int * dirtyp, void*extraargs) {
assert(toku_cachetable_hash(f, key)==fullhash); assert(toku_cachetable_hash(f, key)==fullhash);
assert((long)extraargs==(long)key.b); assert((long)extraargs==(long)key.b);
...@@ -138,15 +138,15 @@ again: ...@@ -138,15 +138,15 @@ again:
test_mutex_unlock(); test_mutex_unlock();
for (i=0; i<my_n_present; i++) { for (i=0; i<my_n_present; i++) {
void *v; void *v;
u_int32_t fullhash = toku_cachetable_hash(my_present_items[i].cf, my_present_items[i].key); u_int32_t fullhash = toku_cachetable_hash(my_present_items[i].cf, my_present_items[i].key);
int r=toku_cachetable_maybe_get_and_pin_clean(my_present_items[i].cf, int r=toku_cachetable_maybe_get_and_pin_clean(my_present_items[i].cf,
my_present_items[i].key, my_present_items[i].key,
toku_cachetable_hash(my_present_items[i].cf, my_present_items[i].key), toku_cachetable_hash(my_present_items[i].cf, my_present_items[i].key),
&v); &v);
if (r == -1) goto again; if (r == -1) goto again;
assert(r==0); assert(r==0);
r = toku_cachetable_unpin(my_present_items[i].cf, my_present_items[i].key, fullhash, CACHETABLE_CLEAN, make_pair_attr(test_object_size)); r = toku_cachetable_unpin(my_present_items[i].cf, my_present_items[i].key, fullhash, CACHETABLE_CLEAN, make_pair_attr(test_object_size));
} }
} }
...@@ -160,69 +160,69 @@ static void test_chaining (void) { ...@@ -160,69 +160,69 @@ static void test_chaining (void) {
long i, trial; long i, trial;
r = toku_create_cachetable(&ct, N_PRESENT_LIMIT, ZERO_LSN, NULL_LOGGER); assert(r==0); r = toku_create_cachetable(&ct, N_PRESENT_LIMIT, ZERO_LSN, NULL_LOGGER); assert(r==0);
for (i=0; i<N_FILES; i++) { for (i=0; i<N_FILES; i++) {
r = snprintf(fname[i], FILENAME_LEN, __SRCFILE__ ".%ld.dat", i); r = snprintf(fname[i], FILENAME_LEN, __SRCFILE__ ".%ld.dat", i);
assert(r>0 && r<FILENAME_LEN); assert(r>0 && r<FILENAME_LEN);
unlink(fname[i]); unlink(fname[i]);
r = toku_cachetable_openf(&f[i], ct, fname[i], O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(r==0); r = toku_cachetable_openf(&f[i], ct, fname[i], O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(r==0);
} }
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", __SRCFILE__, __LINE__, i); //printf("%s:%d Add %d\n", __SRCFILE__, __LINE__, i);
u_int32_t fhash = toku_cachetable_hash(f[fnum], make_blocknum(i)); u_int32_t fhash = toku_cachetable_hash(f[fnum], make_blocknum(i));
CACHETABLE_WRITE_CALLBACK wc = def_write_callback((void *)i); CACHETABLE_WRITE_CALLBACK wc = def_write_callback((void *)i);
wc.flush_callback = flush_forchain; wc.flush_callback = flush_forchain;
r = toku_cachetable_put(f[fnum], make_blocknum(i), fhash, (void*)i, make_pair_attr(test_object_size), wc); r = toku_cachetable_put(f[fnum], make_blocknum(i), fhash, (void*)i, make_pair_attr(test_object_size), wc);
assert(r==0); assert(r==0);
item_becomes_present(ct, f[fnum], make_blocknum(i)); item_becomes_present(ct, f[fnum], make_blocknum(i));
r = toku_cachetable_unpin(f[fnum], make_blocknum(i), fhash, CACHETABLE_CLEAN, make_pair_attr(test_object_size)); r = toku_cachetable_unpin(f[fnum], make_blocknum(i), fhash, CACHETABLE_CLEAN, make_pair_attr(test_object_size));
assert(r==0); assert(r==0);
//print_ints(); //print_ints();
} }
for (trial=0; trial<TRIALS; trial++) { for (trial=0; trial<TRIALS; trial++) {
test_mutex_lock(); test_mutex_lock();
int my_n_present = n_present; int my_n_present = n_present;
test_mutex_unlock(); test_mutex_unlock();
if (my_n_present>0) { if (my_n_present>0) {
// First touch some random ones // First touch some random ones
test_mutex_lock(); test_mutex_lock();
int whichone = random()%n_present; int whichone = random()%n_present;
CACHEFILE whichcf = present_items[whichone].cf; CACHEFILE whichcf = present_items[whichone].cf;
CACHEKEY whichkey = present_items[whichone].key; CACHEKEY whichkey = present_items[whichone].key;
test_mutex_unlock(); test_mutex_unlock();
void *value; void *value;
//printf("Touching %d (%lld, %p)\n", whichone, whichkey, whichcf); //printf("Touching %d (%lld, %p)\n", whichone, whichkey, whichcf);
u_int32_t fhash = toku_cachetable_hash(whichcf, whichkey); u_int32_t fhash = toku_cachetable_hash(whichcf, whichkey);
CACHETABLE_WRITE_CALLBACK wc = def_write_callback((void*)(long)whichkey.b); CACHETABLE_WRITE_CALLBACK wc = def_write_callback((void*)(long)whichkey.b);
wc.flush_callback = flush_forchain; wc.flush_callback = flush_forchain;
r = toku_cachetable_get_and_pin(whichcf, r = toku_cachetable_get_and_pin(whichcf,
whichkey, whichkey,
fhash, fhash,
&value, &value,
NULL, NULL,
wc, wc,
fetch_forchain, fetch_forchain,
def_pf_req_callback, def_pf_req_callback,
def_pf_callback, def_pf_callback,
TRUE, TRUE,
(void*)(long)whichkey.b (void*)(long)whichkey.b
); );
assert(r==0); assert(r==0);
r = toku_cachetable_unpin(whichcf, r = toku_cachetable_unpin(whichcf,
whichkey, whichkey,
fhash, fhash,
CACHETABLE_CLEAN, make_pair_attr(test_object_size)); CACHETABLE_CLEAN, make_pair_attr(test_object_size));
assert(r==0); assert(r==0);
} }
i += 1+ random()%100; i += 1+ random()%100;
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
// if i is a duplicate, cachetable_put will return -1 // if i is a duplicate, cachetable_put will return -1
// printf("%s:%d Add {%ld,%p}\n", __SRCFILE__, __LINE__, i, f[fnum]); // printf("%s:%d Add {%ld,%p}\n", __SRCFILE__, __LINE__, i, f[fnum]);
u_int32_t fhash = toku_cachetable_hash(f[fnum], make_blocknum(i)); u_int32_t fhash = toku_cachetable_hash(f[fnum], make_blocknum(i));
CACHETABLE_WRITE_CALLBACK wc = def_write_callback((void *)i); CACHETABLE_WRITE_CALLBACK wc = def_write_callback((void *)i);
wc.flush_callback = flush_forchain; wc.flush_callback = flush_forchain;
r = toku_cachetable_put(f[fnum], make_blocknum(i), fhash, (void*)i, make_pair_attr(test_object_size), wc); r = toku_cachetable_put(f[fnum], make_blocknum(i), fhash, (void*)i, make_pair_attr(test_object_size), wc);
assert(r==0 || r==-1); assert(r==0 || r==-1);
if (r==0) { if (r==0) {
item_becomes_present(ct, f[fnum], make_blocknum(i)); item_becomes_present(ct, f[fnum], make_blocknum(i));
...@@ -233,26 +233,26 @@ static void test_chaining (void) { ...@@ -233,26 +233,26 @@ static void test_chaining (void) {
} }
// now that we have a clock instead of an LRU, there // now that we have a clock instead of an LRU, there
// is no guarantee that PAIR stays in cachetable // is no guarantee that PAIR stays in cachetable
//long long pinned; //long long pinned;
//r = toku_cachetable_get_key_state(ct, make_blocknum(i), f[fnum], 0, 0, &pinned, 0); //r = toku_cachetable_get_key_state(ct, make_blocknum(i), f[fnum], 0, 0, &pinned, 0);
//assert(r==0); //assert(r==0);
//assert(pinned == 0); //assert(pinned == 0);
verify_cachetable_against_present(); verify_cachetable_against_present();
if (random()%10==0) { if (random()%10==0) {
i = random()%N_FILES; i = random()%N_FILES;
//printf("Close %d (%p), now n_present=%d\n", i, f[i], n_present); //printf("Close %d (%p), now n_present=%d\n", i, f[i], n_present);
//print_ints(); //print_ints();
CACHEFILE oldcf=f[i]; CACHEFILE oldcf=f[i];
r = toku_cachefile_close(&f[i], 0, FALSE, ZERO_LSN); assert(r==0); r = toku_cachefile_close(&f[i], 0, FALSE, ZERO_LSN); assert(r==0);
file_is_not_present(oldcf); file_is_not_present(oldcf);
r = toku_cachetable_openf(&f[i], ct, fname[i], O_RDWR, S_IRWXU|S_IRWXG|S_IRWXO); assert(r==0); r = toku_cachetable_openf(&f[i], ct, fname[i], O_RDWR, S_IRWXU|S_IRWXG|S_IRWXO); assert(r==0);
} }
} }
for (i=0; i<N_FILES; i++) { for (i=0; i<N_FILES; i++) {
r = toku_cachefile_close(&f[i], 0, FALSE, ZERO_LSN); assert(r==0); r = toku_cachefile_close(&f[i], 0, FALSE, ZERO_LSN); assert(r==0);
} }
r = toku_cachetable_close(&ct); assert(r==0); r = toku_cachetable_close(&ct); assert(r==0);
} }
......
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