Commit aab39b23 authored by Zardosht Kasheff's avatar Zardosht Kasheff

refs #61, remove test helper function toku_cachefile_flush,

fix tests that use it to not need it
parent 9803fcac
......@@ -502,18 +502,6 @@ void toku_cachefile_close(CACHEFILE *cfp, bool oplsn_valid, LSN oplsn) {
toku_free(cf);
}
//
// This client calls this function to flush all PAIRs belonging to
// a cachefile from the cachetable. The client must ensure that
// while this function is called, no other thread does work on the
// cachefile.
//
void toku_cachefile_flush (CACHEFILE cf) {
bjm_wait_for_jobs_to_finish(cf->bjm);
CACHETABLE ct = cf->cachetable;
cachetable_flush_cachefile(ct, cf);
}
// This hash function comes from Jenkins: http://burtleburtle.net/bob/c/lookup3.c
// The idea here is to mix the bits thoroughly so that we don't have to do modulo by a prime number.
// Instead we can use a bitmask on a table of size power of two.
......@@ -2440,10 +2428,10 @@ static void remove_all_pairs_for_close(CACHETABLE ct, CACHEFILE cf) {
}
static void verify_cachefile_flushed(CACHETABLE ct UU(), CACHEFILE cf UU()) {
#ifdef TOKU_DEBUG_PARANOID
// assert here that cachefile is flushed by checking
// pair_list and finding no pairs belonging to this cachefile
// Make a list of pairs that belong to this cachefile.
#ifdef TOKU_DEBUG_PARANOID
if (cf) {
ct->list.write_list_lock();
// assert here that cachefile is flushed by checking
......@@ -2488,14 +2476,11 @@ static void cachetable_flush_cachefile(CACHETABLE ct, CACHEFILE cf) {
//
// first write out dirty PAIRs
write_dirty_pairs_for_close(ct, cf);
// now that everything is clean, get rid of everything
remove_all_pairs_for_close(ct, cf);
verify_cachefile_flushed(ct, cf);
if (cf) {
bjm_reset(cf->bjm);
}
}
/* Requires that no locks be held that are used by the checkpoint logic */
......
......@@ -524,12 +524,6 @@ int toku_cachefile_count_pinned (CACHEFILE, int /*printthem*/ );
// If oplsn_valid is true then use oplsn as the LSN of the close instead of asking the logger. oplsn_valid being true is only allowed during recovery, and requires that you are removing the last reference (otherwise the lsn wouldn't make it in.)
void toku_cachefile_close (CACHEFILE*, bool oplsn_valid, LSN oplsn);
// Flush the cachefile.
// Effect: Flush everything owned by the cachefile from the cachetable. All dirty
// blocks are written. All unpinned blocks are evicted from the cachetable.
// Returns: 0 if success, otherwise returns an error number.
void toku_cachefile_flush(CACHEFILE);
// Return on success (different from pread and pwrite)
//int cachefile_pwrite (CACHEFILE, const void *buf, size_t count, toku_off_t offset);
//int cachefile_pread (CACHEFILE, void *buf, size_t count, toku_off_t offset);
......
......@@ -91,6 +91,8 @@ PATENT RIGHTS GRANT:
CACHEFILE f1;
bool should_close;
static int
cleaner_callback(
void* UU(ftnode_pv),
......@@ -99,13 +101,18 @@ cleaner_callback(
void* UU(extraargs)
)
{
int r = toku_test_cachetable_unpin(f1,blocknum, fullhash,CACHETABLE_CLEAN,make_pair_attr(8));
should_close = true;
sleep(2);
PAIR_ATTR attr = make_pair_attr(8);
attr.cache_pressure_size = 8;
int r = toku_test_cachetable_unpin(f1, blocknum, fullhash, CACHETABLE_CLEAN, attr);
assert(r==0);
return 0;
}
static void
cachetable_test (void) {
should_close = false;
const int test_limit = 400;
int r;
CACHETABLE ct;
......@@ -117,20 +124,22 @@ cachetable_test (void) {
r = toku_cachetable_openf(&f1, ct, fname1, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(r == 0);
void* v1;
//void* v2;
long s1;
//long s2;
for (int j = 0; j < 50000; j++) {
for (int i = 0; i < 10; i++) {
CACHETABLE_WRITE_CALLBACK wc = def_write_callback(NULL);
wc.cleaner_callback = cleaner_callback;
r = toku_cachetable_get_and_pin(f1, make_blocknum(i), i, &v1, &s1, wc, def_fetch, def_pf_req_callback, def_pf_callback, true, NULL);
r = toku_test_cachetable_unpin(f1, make_blocknum(i), i, CACHETABLE_DIRTY, make_pair_attr(8));
}
toku_cachefile_flush(f1);
for (int i = 0; i < 10; i++) {
CACHETABLE_WRITE_CALLBACK wc = def_write_callback(NULL);
wc.cleaner_callback = cleaner_callback;
r = toku_cachetable_get_and_pin(f1, make_blocknum(i), i, &v1, &s1, wc, def_fetch, def_pf_req_callback, def_pf_callback, true, NULL);
PAIR_ATTR attr = make_pair_attr(8);
attr.cache_pressure_size = 8;
r = toku_test_cachetable_unpin(f1, make_blocknum(i), i, CACHETABLE_DIRTY, attr);
}
while (!should_close) {
usleep(1024);
}
toku_cachetable_verify(ct);
toku_cachefile_close(&f1, false, ZERO_LSN);
toku_cachetable_verify(ct);
toku_cachetable_close(&ct);
......
......@@ -142,16 +142,13 @@ test_cachetable_def_flush (int n) {
}
// def_flush
toku_cachefile_flush(f1);
toku_cachefile_verify(f1);
toku_cachefile_close(&f1, false, ZERO_LSN);
toku_cachefile_verify(f2);
// verify keys do not exist in f1 but do exist in f2
// verify keys exist in f2
for (i=0; i<n; i++) {
uint32_t hi;
void *v;
hi = toku_cachetable_hash(f1, make_blocknum(i));
r = toku_cachetable_maybe_get_and_pin(f1, make_blocknum(i), hi, PL_WRITE_EXPENSIVE, &v);
assert(r != 0);
hi = toku_cachetable_hash(f2, make_blocknum(i));
r = toku_cachetable_maybe_get_and_pin(f2, make_blocknum(i), hi, PL_WRITE_EXPENSIVE, &v);
assert(r == 0);
......@@ -159,7 +156,6 @@ test_cachetable_def_flush (int n) {
assert(r == 0);
}
toku_cachefile_close(&f1, false, ZERO_LSN);
toku_cachefile_close(&f2, false, ZERO_LSN);
toku_cachetable_close(&ct);
}
......
......@@ -98,12 +98,12 @@ static void kibbutz_work(void *fe_v)
{
CACHEFILE CAST_FROM_VOIDP(f1, fe_v);
sleep(2);
foo = true;
// note that we make the size 16 to induce an eviction
// once evictions are moved to their own thread, we need
// to modify this test
int r = toku_test_cachetable_unpin(f1, make_blocknum(1), 1, CACHETABLE_CLEAN, make_pair_attr(16));
assert(r==0);
foo = true;
remove_background_job_from_cf(f1);
}
......@@ -120,16 +120,8 @@ run_test (void) {
r = toku_cachetable_openf(&f1, ct, fname1, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(r == 0);
void* v1;
//void* v2;
long s1;
//long s2;
CACHETABLE_WRITE_CALLBACK wc = def_write_callback(NULL);
r = toku_cachetable_get_and_pin(f1, make_blocknum(1), 1, &v1, &s1, wc, def_fetch, def_pf_req_callback, def_pf_callback, true, NULL);
foo = false;
cachefile_kibbutz_enq(f1, kibbutz_work, f1);
toku_cachefile_flush(f1);
assert(foo);
assert(f1);
r = toku_cachetable_get_and_pin(f1, make_blocknum(1), 1, &v1, &s1, wc, def_fetch, def_pf_req_callback, def_pf_callback, true, NULL);
foo = false;
......
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