create memTreeComponent class. Moved memTreeIterator, rbtree_t and tearDownTree into it (still need to move changableMemTreeIterator into it...)
git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@673 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
This commit is contained in:
parent
220d58bd7c
commit
de7984b05a
9 changed files with 137 additions and 121 deletions
|
@ -76,7 +76,7 @@ ENDIF ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" )
|
|||
#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
|
||||
IF ( HAVE_STASIS )
|
||||
ADD_LIBRARY(logstore logserver.cpp logstore.cpp diskTreeComponent.cpp logiterators.cpp datapage.cpp merger.cpp tuplemerger.cpp)
|
||||
ADD_LIBRARY(logstore logserver.cpp logstore.cpp diskTreeComponent.cpp memTreeComponent.cpp logiterators.cpp datapage.cpp merger.cpp tuplemerger.cpp)
|
||||
CREATE_EXECUTABLE(server)
|
||||
ENDIF ( HAVE_STASIS )
|
||||
ADD_LIBRARY(logstore_client tcpclient.cpp)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "logstore.h"
|
||||
#include "logiterators.h"
|
||||
|
||||
#include "memTreeComponent.h"
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// tree iterator implementation
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
@ -144,4 +144,4 @@ TUPLE * diskTreeIterator<TUPLE>::getnext()
|
|||
}
|
||||
|
||||
template class diskTreeIterator<datatuple>;
|
||||
template class changingMemTreeIterator<rbtree_t, datatuple>;
|
||||
template class changingMemTreeIterator<memTreeComponent<datatuple>::rbtree_t, datatuple>;
|
||||
|
|
|
@ -72,70 +72,6 @@ private:
|
|||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// memTreeIterator
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
template <class MEMTREE, class TUPLE>
|
||||
class memTreeIterator
|
||||
{
|
||||
private:
|
||||
typedef typename MEMTREE::const_iterator MTITER;
|
||||
|
||||
public:
|
||||
memTreeIterator( MEMTREE *s )
|
||||
: first_(true),
|
||||
done_(s == NULL) {
|
||||
init_iterators(s, NULL, NULL);
|
||||
}
|
||||
|
||||
memTreeIterator( MEMTREE *s, TUPLE *&key )
|
||||
: first_(true), done_(s == NULL) {
|
||||
init_iterators(s, key, NULL);
|
||||
}
|
||||
|
||||
~memTreeIterator() {
|
||||
delete it_;
|
||||
delete itend_;
|
||||
}
|
||||
|
||||
TUPLE* getnext() {
|
||||
if(done_) { return NULL; }
|
||||
if(first_) { first_ = 0;} else { (*it_)++; }
|
||||
if(*it_==*itend_) { done_= true; return NULL; }
|
||||
|
||||
return (*(*it_))->create_copy();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void init_iterators(MEMTREE * s, TUPLE * key1, TUPLE * key2) {
|
||||
if(s) {
|
||||
it_ = key1 ? new MTITER(s->find(key1)) : new MTITER(s->begin());
|
||||
itend_ = key2 ? new MTITER(s->find(key2)) : new MTITER(s->end());
|
||||
if(*it_ == *itend_) { done_ = true; }
|
||||
if(key1) {
|
||||
if(done_) {
|
||||
DEBUG("memtree opened at eot\n");
|
||||
} else {
|
||||
DEBUG("memtree opened key = %s\n", (**it_)->key());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
it_ = NULL;
|
||||
itend_ = NULL;
|
||||
}
|
||||
}
|
||||
explicit memTreeIterator() { abort(); }
|
||||
void operator=(memTreeIterator & t) { abort(); }
|
||||
int operator-(memTreeIterator & t) { abort(); }
|
||||
private:
|
||||
bool first_;
|
||||
bool done_;
|
||||
MTITER *it_;
|
||||
MTITER *itend_;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class TUPLE>
|
||||
|
|
30
logstore.cpp
30
logstore.cpp
|
@ -48,26 +48,6 @@ logtable::logtable()
|
|||
epoch = 0;
|
||||
|
||||
}
|
||||
void logtable::tearDownTree(rbtree_ptr_t tree) {
|
||||
datatuple * t = 0;
|
||||
rbtree_t::iterator old;
|
||||
for(rbtree_t::iterator delitr = tree->begin();
|
||||
delitr != tree->end();
|
||||
delitr++) {
|
||||
if(t) {
|
||||
tree->erase(old);
|
||||
datatuple::freetuple(t);
|
||||
t = 0;
|
||||
}
|
||||
t = *delitr;
|
||||
old = delitr;
|
||||
}
|
||||
if(t) {
|
||||
tree->erase(old);
|
||||
datatuple::freetuple(t);
|
||||
}
|
||||
delete tree;
|
||||
}
|
||||
|
||||
logtable::~logtable()
|
||||
{
|
||||
|
@ -78,7 +58,7 @@ logtable::~logtable()
|
|||
|
||||
if(tree_c0 != NULL)
|
||||
{
|
||||
tearDownTree(tree_c0);
|
||||
memTreeComponent<datatuple>::tearDownTree(tree_c0);
|
||||
}
|
||||
|
||||
deletelock(header_lock);
|
||||
|
@ -173,7 +153,7 @@ void logtable::flushTable()
|
|||
pthread_cond_signal(mergedata->input_ready_cond);
|
||||
|
||||
merge_count ++;
|
||||
set_tree_c0(new rbtree_t);
|
||||
set_tree_c0(new memTreeComponent<datatuple>::rbtree_t);
|
||||
|
||||
tsize = 0;
|
||||
tree_bytes = 0;
|
||||
|
@ -205,7 +185,7 @@ datatuple * logtable::findTuple(int xid, const datatuple::key_t key, size_t keyS
|
|||
datatuple *ret_tuple=0;
|
||||
|
||||
//step 1: look in tree_c0
|
||||
rbtree_t::iterator rbitr = get_tree_c0()->find(search_tuple);
|
||||
memTreeComponent<datatuple>::rbtree_t::iterator rbitr = get_tree_c0()->find(search_tuple);
|
||||
if(rbitr != get_tree_c0()->end())
|
||||
{
|
||||
DEBUG("tree_c0 size %d\n", get_tree_c0()->size());
|
||||
|
@ -350,7 +330,7 @@ datatuple * logtable::findTuple_first(int xid, datatuple::key_t key, size_t keyS
|
|||
datatuple *ret_tuple=0;
|
||||
//step 1: look in tree_c0
|
||||
|
||||
rbtree_t::iterator rbitr = get_tree_c0()->find(search_tuple);
|
||||
memTreeComponent<datatuple>::rbtree_t::iterator rbitr = get_tree_c0()->find(search_tuple);
|
||||
if(rbitr != get_tree_c0()->end())
|
||||
{
|
||||
DEBUG("tree_c0 size %d\n", tree_c0->size());
|
||||
|
@ -417,7 +397,7 @@ void logtable::insertTuple(datatuple *tuple)
|
|||
readlock(header_lock,0);
|
||||
pthread_mutex_lock(mergedata->rbtree_mut);
|
||||
//find the previous tuple with same key in the memtree if exists
|
||||
rbtree_t::iterator rbitr = tree_c0->find(tuple);
|
||||
memTreeComponent<datatuple>::rbtree_t::iterator rbitr = tree_c0->find(tuple);
|
||||
if(rbitr != tree_c0->end())
|
||||
{
|
||||
datatuple *pre_t = *rbitr;
|
||||
|
|
43
logstore.h
43
logstore.h
|
@ -5,7 +5,7 @@
|
|||
#undef begin
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
//#include <set>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
|
@ -31,16 +31,13 @@
|
|||
#include <stasis/truncation.h>
|
||||
|
||||
#include "diskTreeComponent.h"
|
||||
|
||||
#include "memTreeComponent.h"
|
||||
#include "datapage.h"
|
||||
#include "tuplemerger.h"
|
||||
#include "datatuple.h"
|
||||
|
||||
#include "logiterators.h"
|
||||
|
||||
typedef std::set<datatuple*, datatuple> rbtree_t;
|
||||
typedef rbtree_t* rbtree_ptr_t;
|
||||
|
||||
#include "merger.h"
|
||||
|
||||
template<class TUPLE>
|
||||
|
@ -64,8 +61,6 @@ public:
|
|||
void openTable(int xid, recordid rid);
|
||||
void flushTable();
|
||||
|
||||
static void tearDownTree(rbtree_ptr_t t);
|
||||
|
||||
DataPage<datatuple>* insertTuple(int xid, datatuple *tuple,diskTreeComponent *ltree);
|
||||
|
||||
datatuple * findTuple(int xid, const datatuple::key_t key, size_t keySize, diskTreeComponent *ltree);
|
||||
|
@ -86,10 +81,10 @@ public:
|
|||
inline void set_tree_c1_mergeable(diskTreeComponent *t){tree_c1_mergeable=t; bump_epoch(); }
|
||||
inline void set_tree_c2(diskTreeComponent *t){tree_c2=t; bump_epoch(); }
|
||||
|
||||
inline rbtree_ptr_t get_tree_c0(){return tree_c0;}
|
||||
inline rbtree_ptr_t get_tree_c0_mergeable(){return tree_c0_mergeable;}
|
||||
void set_tree_c0(rbtree_ptr_t newtree){tree_c0 = newtree; bump_epoch(); }
|
||||
void set_tree_c0_mergeable(rbtree_ptr_t newtree){tree_c0_mergeable = newtree; bump_epoch(); }
|
||||
inline memTreeComponent<datatuple>::rbtree_ptr_t get_tree_c0(){return tree_c0;}
|
||||
inline memTreeComponent<datatuple>::rbtree_ptr_t get_tree_c0_mergeable(){return tree_c0_mergeable;}
|
||||
void set_tree_c0(memTreeComponent<datatuple>::rbtree_ptr_t newtree){tree_c0 = newtree; bump_epoch(); }
|
||||
void set_tree_c0_mergeable(memTreeComponent<datatuple>::rbtree_ptr_t newtree){tree_c0_mergeable = newtree; bump_epoch(); }
|
||||
|
||||
void update_persistent_header(int xid);
|
||||
|
||||
|
@ -132,8 +127,8 @@ private:
|
|||
diskTreeComponent *tree_c2; //big tree
|
||||
diskTreeComponent *tree_c1; //small tree
|
||||
diskTreeComponent *tree_c1_mergeable; //small tree: ready to be merged with c2
|
||||
rbtree_ptr_t tree_c0; // in-mem red black tree
|
||||
rbtree_ptr_t tree_c0_mergeable; // in-mem red black tree: ready to be merged with c1.
|
||||
memTreeComponent<datatuple>::rbtree_ptr_t tree_c0; // in-mem red black tree
|
||||
memTreeComponent<datatuple>::rbtree_ptr_t tree_c0_mergeable; // in-mem red black tree: ready to be merged with c1.
|
||||
|
||||
int tsize; //number of tuples
|
||||
int64_t tree_bytes; //number of bytes
|
||||
|
@ -334,8 +329,10 @@ private:
|
|||
static const int C2 = 2;
|
||||
logtable * ltable;
|
||||
uint64_t epoch;
|
||||
typedef mergeManyIterator<changingMemTreeIterator<rbtree_t, TUPLE>, memTreeIterator<rbtree_t, TUPLE>, TUPLE> inner_merge_it_t;
|
||||
// typedef mergeManyIterator<memTreeIterator<rbtree_t, TUPLE>, diskTreeIterator<TUPLE>, TUPLE> merge_it_t;
|
||||
typedef mergeManyIterator<
|
||||
changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE>,
|
||||
typename memTreeComponent<TUPLE>::memTreeIterator, TUPLE> inner_merge_it_t;
|
||||
// typedef mergeManyIterator<memTreeIterator<memTreeComponent::rbtree_t, TUPLE>, diskTreeIterator<TUPLE>, TUPLE> merge_it_t;
|
||||
typedef mergeManyIterator<inner_merge_it_t, diskTreeIterator<TUPLE>, TUPLE> merge_it_t;
|
||||
|
||||
merge_it_t* merge_it_;
|
||||
|
@ -353,25 +350,25 @@ private:
|
|||
|
||||
|
||||
void validate() {
|
||||
changingMemTreeIterator<rbtree_t, TUPLE> * c0_it;
|
||||
memTreeIterator<rbtree_t, TUPLE> * c0_mergeable_it[1];
|
||||
changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE> * c0_it;
|
||||
typename memTreeComponent<TUPLE>::memTreeIterator *c0_mergeable_it[1];
|
||||
diskTreeIterator<TUPLE> * disk_it[3];
|
||||
epoch = ltable->get_epoch();
|
||||
if(last_returned) {
|
||||
c0_it = new changingMemTreeIterator<rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut, last_returned);
|
||||
c0_mergeable_it[0] = new memTreeIterator<rbtree_t, TUPLE> (ltable->get_tree_c0_mergeable(), last_returned);
|
||||
c0_it = new changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut, last_returned);
|
||||
c0_mergeable_it[0] = new typename memTreeComponent<TUPLE>::memTreeIterator (ltable->get_tree_c0_mergeable(), last_returned);
|
||||
disk_it[0] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1(), *last_returned);
|
||||
disk_it[1] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1_mergeable(), *last_returned);
|
||||
disk_it[2] = new diskTreeIterator<TUPLE> (ltable->get_tree_c2(), *last_returned);
|
||||
} else if(key) {
|
||||
c0_it = new changingMemTreeIterator<rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut, key);
|
||||
c0_mergeable_it[0] = new memTreeIterator<rbtree_t, TUPLE> (ltable->get_tree_c0_mergeable(), key);
|
||||
c0_it = new changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut, key);
|
||||
c0_mergeable_it[0] = new typename memTreeComponent<TUPLE>::memTreeIterator(ltable->get_tree_c0_mergeable(), key);
|
||||
disk_it[0] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1(), *key);
|
||||
disk_it[1] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1_mergeable(), *key);
|
||||
disk_it[2] = new diskTreeIterator<TUPLE> (ltable->get_tree_c2(), *key);
|
||||
} else {
|
||||
c0_it = new changingMemTreeIterator<rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut );
|
||||
c0_mergeable_it[0] = new memTreeIterator<rbtree_t, TUPLE> (ltable->get_tree_c0_mergeable() );
|
||||
c0_it = new changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut );
|
||||
c0_mergeable_it[0] = new typename memTreeComponent<TUPLE>::memTreeIterator (ltable->get_tree_c0_mergeable() );
|
||||
disk_it[0] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1() );
|
||||
disk_it[1] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1_mergeable() );
|
||||
disk_it[2] = new diskTreeIterator<TUPLE> (ltable->get_tree_c2() );
|
||||
|
|
24
memTreeComponent.cpp
Normal file
24
memTreeComponent.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "memTreeComponent.h"
|
||||
template<class TUPLE>
|
||||
void memTreeComponent<TUPLE>::tearDownTree(rbtree_ptr_t tree) {
|
||||
TUPLE * t = 0;
|
||||
typename rbtree_t::iterator old;
|
||||
for(typename rbtree_t::iterator delitr = tree->begin();
|
||||
delitr != tree->end();
|
||||
delitr++) {
|
||||
if(t) {
|
||||
tree->erase(old);
|
||||
TUPLE::freetuple(t);
|
||||
t = 0;
|
||||
}
|
||||
t = *delitr;
|
||||
old = delitr;
|
||||
}
|
||||
if(t) {
|
||||
tree->erase(old);
|
||||
TUPLE::freetuple(t);
|
||||
}
|
||||
delete tree;
|
||||
}
|
||||
|
||||
template class memTreeComponent<datatuple>;
|
79
memTreeComponent.h
Normal file
79
memTreeComponent.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
#ifndef _MEMTREECOMPONENT_H_
|
||||
#define _MEMTREECOMPONENT_H_
|
||||
#include <set>
|
||||
#include "datatuple.h"
|
||||
template<class TUPLE>
|
||||
class memTreeComponent {
|
||||
public:
|
||||
typedef std::set<TUPLE*, TUPLE> rbtree_t;
|
||||
typedef rbtree_t* rbtree_ptr_t;
|
||||
|
||||
static void tearDownTree(rbtree_ptr_t t);
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// memTreeIterator
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
class memTreeIterator
|
||||
{
|
||||
private:
|
||||
typedef typename rbtree_t::const_iterator MTITER;
|
||||
|
||||
public:
|
||||
memTreeIterator( rbtree_t *s )
|
||||
: first_(true),
|
||||
done_(s == NULL) {
|
||||
init_iterators(s, NULL, NULL);
|
||||
}
|
||||
|
||||
memTreeIterator( rbtree_t *s, TUPLE *&key )
|
||||
: first_(true), done_(s == NULL) {
|
||||
init_iterators(s, key, NULL);
|
||||
}
|
||||
|
||||
~memTreeIterator() {
|
||||
delete it_;
|
||||
delete itend_;
|
||||
}
|
||||
|
||||
TUPLE* getnext() {
|
||||
if(done_) { return NULL; }
|
||||
if(first_) { first_ = 0;} else { (*it_)++; }
|
||||
if(*it_==*itend_) { done_= true; return NULL; }
|
||||
|
||||
return (*(*it_))->create_copy();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void init_iterators(rbtree_t * s, TUPLE * key1, TUPLE * key2) {
|
||||
if(s) {
|
||||
it_ = key1 ? new MTITER(s->find(key1)) : new MTITER(s->begin());
|
||||
itend_ = key2 ? new MTITER(s->find(key2)) : new MTITER(s->end());
|
||||
if(*it_ == *itend_) { done_ = true; }
|
||||
if(key1) {
|
||||
if(done_) {
|
||||
// DEBUG("memtree opened at eot\n");
|
||||
} else {
|
||||
// DEBUG("memtree opened key = %s\n", (**it_)->key());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
it_ = NULL;
|
||||
itend_ = NULL;
|
||||
}
|
||||
}
|
||||
explicit memTreeIterator() { abort(); }
|
||||
void operator=(memTreeIterator & t) { abort(); }
|
||||
int operator-(memTreeIterator & t) { abort(); }
|
||||
private:
|
||||
bool first_;
|
||||
bool done_;
|
||||
MTITER *it_;
|
||||
MTITER *itend_;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
#endif //_MEMTREECOMPONENT_H_
|
|
@ -187,7 +187,7 @@ void merge_scheduler::startlogtable(int index, int64_t MAX_C0_SIZE)
|
|||
*block1_size = FUDGE * ((int)R) * (*(mdata->input_size));
|
||||
|
||||
//initialize rb-tree
|
||||
ltable->set_tree_c0(new rbtree_t);
|
||||
ltable->set_tree_c0(new memTreeComponent<datatuple>::rbtree_t);
|
||||
|
||||
//disk merger args
|
||||
|
||||
|
@ -335,8 +335,8 @@ void* memMergeThread(void*arg)
|
|||
|
||||
//create the iterators
|
||||
diskTreeIterator<datatuple> *itrA = new diskTreeIterator<datatuple>(ltable->get_tree_c1()->get_root_rec()); // XXX don't want get_root_rec() to be here.
|
||||
memTreeIterator<rbtree_t, datatuple> *itrB =
|
||||
new memTreeIterator<rbtree_t, datatuple>(ltable->get_tree_c0_mergeable());
|
||||
memTreeComponent<datatuple>::memTreeIterator *itrB =
|
||||
new memTreeComponent<datatuple>::memTreeIterator(ltable->get_tree_c0_mergeable());
|
||||
|
||||
|
||||
//create a new tree
|
||||
|
@ -396,7 +396,7 @@ void* memMergeThread(void*arg)
|
|||
delete ltable->get_tree_c1();
|
||||
|
||||
// 11.5: delete old c0_mergeable
|
||||
logtable::tearDownTree(ltable->get_tree_c0_mergeable());
|
||||
memTreeComponent<datatuple>::tearDownTree(ltable->get_tree_c0_mergeable());
|
||||
// 11: c0_mergeable = NULL
|
||||
ltable->set_tree_c0_mergeable(NULL);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ void insertProbeIter(size_t NUM_ENTRIES)
|
|||
if(data_arr.size() > NUM_ENTRIES)
|
||||
data_arr.erase(data_arr.begin()+NUM_ENTRIES, data_arr.end());
|
||||
|
||||
rbtree_t rbtree;
|
||||
memTreeComponent<datatuple>::rbtree_t rbtree;
|
||||
|
||||
int64_t datasize = 0;
|
||||
std::vector<pageid_t> dsp;
|
||||
|
@ -70,7 +70,7 @@ void insertProbeIter(size_t NUM_ENTRIES)
|
|||
|
||||
//step 1: look in tree_c0
|
||||
|
||||
rbtree_t::iterator rbitr = rbtree.find(search_tuple);
|
||||
memTreeComponent<datatuple>::rbtree_t::iterator rbitr = rbtree.find(search_tuple);
|
||||
if(rbitr != rbtree.end())
|
||||
{
|
||||
datatuple *tuple = *rbitr;
|
||||
|
|
Loading…
Reference in a new issue