From ae7c827ab54167a691f611cccb545ddb871fd78a Mon Sep 17 00:00:00 2001 From: sears Date: Thu, 28 Apr 2011 21:56:25 +0000 Subject: [PATCH] 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 --- logstore.cpp | 18 +++++++++++++++++- merger.cpp | 2 +- newserver.cpp | 7 ++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/logstore.cpp b/logstore.cpp index 51df3d9..84b1168 100644 --- a/logstore.cpp +++ b/logstore.cpp @@ -538,7 +538,21 @@ datatuple * logtable::findTuple_first(int xid, datatuple::key_t key, size template datatuple * logtable::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::rbtree_t::iterator rbitr = tree_c0->find(tuple); datatuple * t = 0; datatuple * pre_t = 0; @@ -562,6 +576,8 @@ datatuple * logtable::insertTupleHelper(datatuple *tuple) tree_c0->insert(t); } + if(need_free) { TUPLE::freetuple(tuple); } + return pre_t; } template diff --git a/merger.cpp b/merger.cpp index d183581..c16884d 100644 --- a/merger.cpp +++ b/merger.cpp @@ -33,7 +33,7 @@ bool insert_filter(logtable * 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; } diff --git a/newserver.cpp b/newserver.cpp index 3c32968..d86c48e 100644 --- a/newserver.cpp +++ b/newserver.cpp @@ -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 ]", argv[0]); + fprintf(stderr, "Usage: %s [--test|--benchmark] [--log-mode ] [--expiry-delta ]", argv[0]); abort(); } } @@ -51,6 +55,7 @@ int main(int argc, char *argv[]) recordid table_root = ROOT_RECORD; { logtable ltable(log_mode, c0_size); + ltable.expiry = expiry_delta; if(TrecordType(xid, ROOT_RECORD) == INVALID_SLOT) { printf("Creating empty logstore\n");