add hacky garbage collection mechanism

git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@2484 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
This commit is contained in:
sears 2011-04-28 21:56:25 +00:00
parent c910a7af8f
commit ae7c827ab5
3 changed files with 24 additions and 3 deletions

View file

@ -538,7 +538,21 @@ datatuple * logtable<TUPLE>::findTuple_first(int xid, datatuple::key_t key, size
template<class TUPLE>
datatuple * logtable<TUPLE>::insertTupleHelper(datatuple *tuple)
{
//find the previous tuple with same key in the memtree if exists
bool need_free = true;
if(!tuple->isDelete() && expiry != 0) {
// XXX hack for paper experiment
current_timestamp++;
size_t ts_sz = sizeof(int64_t);
int64_t ts = current_timestamp;
int64_t kl = tuple->strippedkeylen();
byte * newkey = (byte*)malloc(kl + 1 + ts_sz);
memcpy(newkey, tuple->strippedkey(), kl);
newkey[kl] = 0;
memcpy(newkey+kl+1, &ts, ts_sz);
tuple = datatuple::create(newkey, kl+ 1+ ts_sz, tuple->data(), tuple->datalen());
free(newkey);
need_free = true;
} //find the previous tuple with same key in the memtree if exists
memTreeComponent<datatuple>::rbtree_t::iterator rbitr = tree_c0->find(tuple);
datatuple * t = 0;
datatuple * pre_t = 0;
@ -562,6 +576,8 @@ datatuple * logtable<TUPLE>::insertTupleHelper(datatuple *tuple)
tree_c0->insert(t);
}
if(need_free) { TUPLE::freetuple(tuple); }
return pre_t;
}
template<class TUPLE>

View file

@ -33,7 +33,7 @@ bool insert_filter(logtable<datatuple> * ltable, datatuple * t, bool dropDeletes
}
}
if(!ltable->expiry) { return true; }
if(t->timestamp() > ltable->current_timestamp + ltable->expiry) { return false; }
if(t->timestamp() < ltable->current_timestamp - ltable->expiry) { return false; }
return true;
}

View file

@ -23,6 +23,7 @@ int main(int argc, char *argv[])
signal(SIGPIPE, SIG_IGN);
int64_t c0_size = 1024 * 1024 * 512 * 1;
int log_mode = 0; // do not log by default.
int64_t expiry_delta = 0; // do not gc by default
stasis_buffer_manager_size = 1 * 1024 * 1024 * 1024 / PAGE_SIZE; // 1.5GB total
for(int i = 1; i < argc; i++) {
@ -37,8 +38,11 @@ int main(int argc, char *argv[])
} else if(!strcmp(argv[i], "--log-mode")) {
i++;
log_mode = atoi(argv[i]);
} else if(!strcmp(argv[i], "--expiry-delta")) {
i++;
expiry_delta = atoi(argv[i]);
} else {
fprintf(stderr, "Usage: %s [--test|--benchmark] [--log-mode <int>]", argv[0]);
fprintf(stderr, "Usage: %s [--test|--benchmark] [--log-mode <int>] [--expiry-delta <int>]", argv[0]);
abort();
}
}
@ -51,6 +55,7 @@ int main(int argc, char *argv[])
recordid table_root = ROOT_RECORD;
{
logtable<datatuple> ltable(log_mode, c0_size);
ltable.expiry = expiry_delta;
if(TrecordType(xid, ROOT_RECORD) == INVALID_SLOT) {
printf("Creating empty logstore\n");