changingMemTreeIterator -> memTreeComponent::changingMemTreeIterator

git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@676 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
This commit is contained in:
sears 2010-03-09 17:47:47 +00:00
parent 104f38f517
commit 76cd6a26c7
5 changed files with 69 additions and 78 deletions

View file

@ -139,9 +139,7 @@ TUPLE * diskTreeIterator<TUPLE>::getnext()
} }
// else readTuple is null. We're done. // else readTuple is null. We're done.
} }
return readTuple; return readTuple;
} }
template class diskTreeIterator<datatuple>; template class diskTreeIterator<datatuple>;
template class changingMemTreeIterator<memTreeComponent<datatuple>::rbtree_t, datatuple>;

View file

@ -4,74 +4,6 @@
template <class TUPLE> template <class TUPLE>
class DataPage; class DataPage;
template <class MEMTREE, class TUPLE>
class changingMemTreeIterator
{
private:
typedef typename MEMTREE::const_iterator MTITER;
public:
changingMemTreeIterator( MEMTREE *s, pthread_mutex_t * rb_mut ) : s_(s), mut_(rb_mut) {
pthread_mutex_lock(mut_);
if(s_->begin() == s_->end()) {
next_ret_ = NULL;
} else {
next_ret_ = (*s_->begin())->create_copy(); // the create_copy() calls have to happen before we release mut_...
}
pthread_mutex_unlock(mut_);
}
changingMemTreeIterator( MEMTREE *s, pthread_mutex_t * rb_mut, TUPLE *&key ) : s_(s), mut_(rb_mut) {
pthread_mutex_lock(mut_);
if(key) {
if(s_->find(key) != s_->end()) {
next_ret_ = (*(s_->find(key)))->create_copy();
} else if(s_->upper_bound(key) != s_->end()) {
next_ret_ = (*(s_->upper_bound(key)))->create_copy();
} else {
next_ret_ = NULL;
}
} else {
if(s_->begin() == s_->end()) {
next_ret_ = NULL;
} else {
next_ret_ = (*s_->begin())->create_copy(); // the create_copy() calls have to happen before we release mut_...
}
}
DEBUG("changing mem next ret = %s key = %s\n", next_ret_ ? (const char*)next_ret_->key() : "NONE", key ? (const char*)key->key() : "NULL");
pthread_mutex_unlock(mut_);
}
~changingMemTreeIterator() {
if(next_ret_) datatuple::freetuple(next_ret_);
}
TUPLE* getnext() {
pthread_mutex_lock(mut_);
TUPLE * ret = next_ret_;
if(next_ret_) {
if(s_->upper_bound(next_ret_) == s_->end()) {
next_ret_ = 0;
} else {
next_ret_ = (*s_->upper_bound(next_ret_))->create_copy();
}
}
pthread_mutex_unlock(mut_);
return ret;
}
private:
explicit changingMemTreeIterator() { abort(); }
void operator=(changingMemTreeIterator & t) { abort(); }
int operator-(changingMemTreeIterator & t) { abort(); }
private:
MEMTREE *s_;
TUPLE * next_ret_;
pthread_mutex_t * mut_;
};
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
template <class TUPLE> template <class TUPLE>

View file

@ -330,7 +330,7 @@ private:
logtable * ltable; logtable * ltable;
uint64_t epoch; uint64_t epoch;
typedef mergeManyIterator< typedef mergeManyIterator<
changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE>, typename memTreeComponent<TUPLE>::changingMemTreeIterator,
typename memTreeComponent<TUPLE>::memTreeIterator, TUPLE> inner_merge_it_t; typename memTreeComponent<TUPLE>::memTreeIterator, TUPLE> inner_merge_it_t;
// typedef mergeManyIterator<memTreeIterator<memTreeComponent::rbtree_t, TUPLE>, diskTreeIterator<TUPLE>, TUPLE> 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; typedef mergeManyIterator<inner_merge_it_t, diskTreeIterator<TUPLE>, TUPLE> merge_it_t;
@ -350,24 +350,24 @@ private:
void validate() { void validate() {
changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE> * c0_it; typename memTreeComponent<TUPLE>::changingMemTreeIterator * c0_it;
typename memTreeComponent<TUPLE>::memTreeIterator *c0_mergeable_it[1]; typename memTreeComponent<TUPLE>::memTreeIterator *c0_mergeable_it[1];
diskTreeIterator<TUPLE> * disk_it[3]; diskTreeIterator<TUPLE> * disk_it[3];
epoch = ltable->get_epoch(); epoch = ltable->get_epoch();
if(last_returned) { if(last_returned) {
c0_it = new changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut, last_returned); c0_it = new typename memTreeComponent<TUPLE>::changingMemTreeIterator(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); 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[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[1] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1_mergeable(), *last_returned);
disk_it[2] = new diskTreeIterator<TUPLE> (ltable->get_tree_c2(), *last_returned); disk_it[2] = new diskTreeIterator<TUPLE> (ltable->get_tree_c2(), *last_returned);
} else if(key) { } else if(key) {
c0_it = new changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut, key); c0_it = new typename memTreeComponent<TUPLE>::changingMemTreeIterator(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut, key);
c0_mergeable_it[0] = new typename memTreeComponent<TUPLE>::memTreeIterator(ltable->get_tree_c0_mergeable(), 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[0] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1(), *key);
disk_it[1] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1_mergeable(), *key); disk_it[1] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1_mergeable(), *key);
disk_it[2] = new diskTreeIterator<TUPLE> (ltable->get_tree_c2(), *key); disk_it[2] = new diskTreeIterator<TUPLE> (ltable->get_tree_c2(), *key);
} else { } else {
c0_it = new changingMemTreeIterator<typename memTreeComponent<TUPLE>::rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut ); c0_it = new typename memTreeComponent<TUPLE>::changingMemTreeIterator(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut );
c0_mergeable_it[0] = new typename memTreeComponent<TUPLE>::memTreeIterator (ltable->get_tree_c0_mergeable() ); 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[0] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1() );
disk_it[1] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1_mergeable() ); disk_it[1] = new diskTreeIterator<TUPLE> (ltable->get_tree_c1_mergeable() );

View file

@ -20,5 +20,4 @@ void memTreeComponent<TUPLE>::tearDownTree(rbtree_ptr_t tree) {
} }
delete tree; delete tree;
} }
template class memTreeComponent<datatuple>; template class memTreeComponent<datatuple>;

View file

@ -73,7 +73,69 @@ public:
MTITER *itend_; MTITER *itend_;
}; };
///////////////////////////////////////////////////////////////// class changingMemTreeIterator
{
private:
typedef typename rbtree_t::const_iterator MTITER;
public:
changingMemTreeIterator( rbtree_t *s, pthread_mutex_t * rb_mut ) : s_(s), mut_(rb_mut) {
pthread_mutex_lock(mut_);
if(s_->begin() == s_->end()) {
next_ret_ = NULL;
} else {
next_ret_ = (*s_->begin())->create_copy(); // the create_copy() calls have to happen before we release mut_...
}
pthread_mutex_unlock(mut_);
}
changingMemTreeIterator( rbtree_t *s, pthread_mutex_t * rb_mut, TUPLE *&key ) : s_(s), mut_(rb_mut) {
pthread_mutex_lock(mut_);
if(key) {
if(s_->find(key) != s_->end()) {
next_ret_ = (*(s_->find(key)))->create_copy();
} else if(s_->upper_bound(key) != s_->end()) {
next_ret_ = (*(s_->upper_bound(key)))->create_copy();
} else {
next_ret_ = NULL;
}
} else {
if(s_->begin() == s_->end()) {
next_ret_ = NULL;
} else {
next_ret_ = (*s_->begin())->create_copy(); // the create_copy() calls have to happen before we release mut_...
}
}
// DEBUG("changing mem next ret = %s key = %s\n", next_ret_ ? (const char*)next_ret_->key() : "NONE", key ? (const char*)key->key() : "NULL");
pthread_mutex_unlock(mut_);
}
~changingMemTreeIterator() {
if(next_ret_) datatuple::freetuple(next_ret_);
}
TUPLE* getnext() {
pthread_mutex_lock(mut_);
TUPLE * ret = next_ret_;
if(next_ret_) {
if(s_->upper_bound(next_ret_) == s_->end()) {
next_ret_ = 0;
} else {
next_ret_ = (*s_->upper_bound(next_ret_))->create_copy();
}
}
pthread_mutex_unlock(mut_);
return ret;
}
private:
explicit changingMemTreeIterator() { abort(); }
void operator=(changingMemTreeIterator & t) { abort(); }
int operator-(changingMemTreeIterator & t) { abort(); }
rbtree_t *s_;
TUPLE * next_ret_;
pthread_mutex_t * mut_;
};
}; };
#endif //_MEMTREECOMPONENT_H_ #endif //_MEMTREECOMPONENT_H_