From 76cd6a26c76e99623eabff3f9350d7cee7c082cc Mon Sep 17 00:00:00 2001 From: sears Date: Tue, 9 Mar 2010 17:47:47 +0000 Subject: [PATCH] changingMemTreeIterator -> memTreeComponent::changingMemTreeIterator git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@676 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe --- logiterators.cpp | 2 -- logiterators.h | 68 -------------------------------------------- logstore.h | 12 ++++---- memTreeComponent.cpp | 1 - memTreeComponent.h | 64 ++++++++++++++++++++++++++++++++++++++++- 5 files changed, 69 insertions(+), 78 deletions(-) diff --git a/logiterators.cpp b/logiterators.cpp index 8e1d9c8..0d14ed8 100644 --- a/logiterators.cpp +++ b/logiterators.cpp @@ -139,9 +139,7 @@ TUPLE * diskTreeIterator::getnext() } // else readTuple is null. We're done. } - return readTuple; } template class diskTreeIterator; -template class changingMemTreeIterator::rbtree_t, datatuple>; diff --git a/logiterators.h b/logiterators.h index e9a0eca..d4879cd 100644 --- a/logiterators.h +++ b/logiterators.h @@ -4,74 +4,6 @@ template class DataPage; -template -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 diff --git a/logstore.h b/logstore.h index 49de4d4..bb96c5a 100644 --- a/logstore.h +++ b/logstore.h @@ -330,7 +330,7 @@ private: logtable * ltable; uint64_t epoch; typedef mergeManyIterator< - changingMemTreeIterator::rbtree_t, TUPLE>, + typename memTreeComponent::changingMemTreeIterator, typename memTreeComponent::memTreeIterator, TUPLE> inner_merge_it_t; // typedef mergeManyIterator, diskTreeIterator, TUPLE> merge_it_t; typedef mergeManyIterator, TUPLE> merge_it_t; @@ -350,24 +350,24 @@ private: void validate() { - changingMemTreeIterator::rbtree_t, TUPLE> * c0_it; + typename memTreeComponent::changingMemTreeIterator * c0_it; typename memTreeComponent::memTreeIterator *c0_mergeable_it[1]; diskTreeIterator * 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_it = new typename memTreeComponent::changingMemTreeIterator(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut, last_returned); c0_mergeable_it[0] = new typename memTreeComponent::memTreeIterator (ltable->get_tree_c0_mergeable(), last_returned); disk_it[0] = new diskTreeIterator (ltable->get_tree_c1(), *last_returned); disk_it[1] = new diskTreeIterator (ltable->get_tree_c1_mergeable(), *last_returned); disk_it[2] = new diskTreeIterator (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 typename memTreeComponent::memTreeIterator(ltable->get_tree_c0_mergeable(), key); + c0_it = new typename memTreeComponent::changingMemTreeIterator(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut, key); + c0_mergeable_it[0] = new typename memTreeComponent::memTreeIterator (ltable->get_tree_c0_mergeable(), key); disk_it[0] = new diskTreeIterator (ltable->get_tree_c1(), *key); disk_it[1] = new diskTreeIterator (ltable->get_tree_c1_mergeable(), *key); disk_it[2] = new diskTreeIterator (ltable->get_tree_c2(), *key); } else { - c0_it = new changingMemTreeIterator::rbtree_t, TUPLE>(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut ); + c0_it = new typename memTreeComponent::changingMemTreeIterator(ltable->get_tree_c0(), ltable->getMergeData()->rbtree_mut ); c0_mergeable_it[0] = new typename memTreeComponent::memTreeIterator (ltable->get_tree_c0_mergeable() ); disk_it[0] = new diskTreeIterator (ltable->get_tree_c1() ); disk_it[1] = new diskTreeIterator (ltable->get_tree_c1_mergeable() ); diff --git a/memTreeComponent.cpp b/memTreeComponent.cpp index b59666d..3acd6d5 100644 --- a/memTreeComponent.cpp +++ b/memTreeComponent.cpp @@ -20,5 +20,4 @@ void memTreeComponent::tearDownTree(rbtree_ptr_t tree) { } delete tree; } - template class memTreeComponent; diff --git a/memTreeComponent.h b/memTreeComponent.h index 490c849..de6371d 100644 --- a/memTreeComponent.h +++ b/memTreeComponent.h @@ -73,7 +73,69 @@ public: 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_