2010-01-23 02:13:59 +00:00
|
|
|
#ifndef _LOG_ITERATORS_H_
|
|
|
|
#define _LOG_ITERATORS_H_
|
|
|
|
|
|
|
|
template <class TUPLE>
|
|
|
|
class DataPage;
|
|
|
|
|
2010-02-20 01:18:39 +00:00
|
|
|
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 {
|
2010-02-25 01:29:32 +00:00
|
|
|
next_ret_ = (*s_->begin())->create_copy(); // the create_copy() calls have to happen before we release mut_...
|
2010-02-20 01:18:39 +00:00
|
|
|
}
|
|
|
|
pthread_mutex_unlock(mut_);
|
|
|
|
}
|
2010-02-25 01:29:32 +00:00
|
|
|
changingMemTreeIterator( MEMTREE *s, pthread_mutex_t * rb_mut, TUPLE *&key ) : s_(s), mut_(rb_mut) {
|
2010-02-20 01:18:39 +00:00
|
|
|
pthread_mutex_lock(mut_);
|
2010-02-25 01:29:32 +00:00
|
|
|
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()) {
|
2010-02-20 01:18:39 +00:00
|
|
|
next_ret_ = NULL;
|
2010-02-25 01:29:32 +00:00
|
|
|
} 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");
|
2010-02-20 01:18:39 +00:00
|
|
|
pthread_mutex_unlock(mut_);
|
|
|
|
}
|
|
|
|
|
2010-02-25 01:29:32 +00:00
|
|
|
~changingMemTreeIterator() {
|
|
|
|
if(next_ret_) datatuple::freetuple(next_ret_);
|
|
|
|
}
|
2010-02-20 01:18:39 +00:00
|
|
|
|
|
|
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-23 02:13:59 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
// memTreeIterator
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
|
2010-01-28 02:20:49 +00:00
|
|
|
template <class MEMTREE, class TUPLE>
|
|
|
|
class memTreeIterator
|
|
|
|
{
|
2010-01-23 02:13:59 +00:00
|
|
|
private:
|
|
|
|
typedef typename MEMTREE::const_iterator MTITER;
|
|
|
|
|
2010-01-28 02:20:49 +00:00
|
|
|
public:
|
2010-02-20 01:18:39 +00:00
|
|
|
memTreeIterator( MEMTREE *s )
|
|
|
|
: first_(true),
|
|
|
|
done_(s == NULL) {
|
|
|
|
init_iterators(s, NULL, NULL);
|
|
|
|
}
|
2010-01-23 02:13:59 +00:00
|
|
|
|
2010-02-20 01:18:39 +00:00
|
|
|
memTreeIterator( MEMTREE *s, TUPLE *&key )
|
|
|
|
: first_(true), done_(s == NULL) {
|
|
|
|
init_iterators(s, key, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
~memTreeIterator() {
|
|
|
|
delete it_;
|
|
|
|
delete itend_;
|
|
|
|
}
|
2010-01-28 02:20:49 +00:00
|
|
|
|
|
|
|
TUPLE* getnext() {
|
2010-02-04 22:19:42 +00:00
|
|
|
if(done_) { return NULL; }
|
2010-02-20 01:18:39 +00:00
|
|
|
if(first_) { first_ = 0;} else { (*it_)++; }
|
|
|
|
if(*it_==*itend_) { done_= true; return NULL; }
|
2010-02-10 21:49:50 +00:00
|
|
|
|
2010-02-20 01:18:39 +00:00
|
|
|
return (*(*it_))->create_copy();
|
2010-01-23 02:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2010-02-20 01:18:39 +00:00
|
|
|
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());
|
2010-02-25 01:29:32 +00:00
|
|
|
if(*it_ == *itend_) { done_ = true; }
|
|
|
|
if(key1) {
|
|
|
|
if(done_) {
|
|
|
|
DEBUG("memtree opened at eot\n");
|
|
|
|
} else {
|
|
|
|
DEBUG("memtree opened key = %s\n", (**it_)->key());
|
|
|
|
}
|
|
|
|
}
|
2010-02-20 01:18:39 +00:00
|
|
|
} else {
|
|
|
|
it_ = NULL;
|
|
|
|
itend_ = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 02:20:49 +00:00
|
|
|
explicit memTreeIterator() { abort(); }
|
|
|
|
void operator=(memTreeIterator & t) { abort(); }
|
|
|
|
int operator-(memTreeIterator & t) { abort(); }
|
|
|
|
private:
|
|
|
|
bool first_;
|
2010-02-04 22:19:42 +00:00
|
|
|
bool done_;
|
2010-02-20 01:18:39 +00:00
|
|
|
MTITER *it_;
|
|
|
|
MTITER *itend_;
|
2010-01-23 02:13:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template <class TUPLE>
|
2010-02-20 01:18:39 +00:00
|
|
|
class diskTreeIterator
|
2010-01-23 02:13:59 +00:00
|
|
|
{
|
|
|
|
|
2010-01-28 02:20:49 +00:00
|
|
|
public:
|
2010-02-20 01:18:39 +00:00
|
|
|
explicit diskTreeIterator(recordid tree);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
2010-02-20 01:18:39 +00:00
|
|
|
explicit diskTreeIterator(recordid tree,TUPLE &key);
|
|
|
|
|
|
|
|
explicit diskTreeIterator(diskTreeComponent *tree);
|
|
|
|
|
|
|
|
explicit diskTreeIterator(diskTreeComponent *tree,TUPLE &key);
|
|
|
|
|
|
|
|
~diskTreeIterator();
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
TUPLE * getnext();
|
|
|
|
|
|
|
|
private:
|
2010-02-20 01:18:39 +00:00
|
|
|
void init_iterators(TUPLE * key1, TUPLE * key2);
|
2010-02-25 01:29:32 +00:00
|
|
|
inline void init_helper(TUPLE* key1);
|
2010-01-23 02:13:59 +00:00
|
|
|
|
2010-02-20 01:18:39 +00:00
|
|
|
explicit diskTreeIterator() { abort(); }
|
|
|
|
void operator=(diskTreeIterator & t) { abort(); }
|
|
|
|
int operator-(diskTreeIterator & t) { abort(); }
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
recordid tree_; //root of the tree
|
|
|
|
|
2010-03-09 00:09:38 +00:00
|
|
|
diskTreeComponent::iterator* lsmIterator_;
|
2010-01-23 02:13:59 +00:00
|
|
|
|
|
|
|
pageid_t curr_pageid; //current page id
|
|
|
|
DataPage<TUPLE> *curr_page; //current page
|
|
|
|
typedef typename DataPage<TUPLE>::RecordIterator DPITR_T;
|
|
|
|
DPITR_T *dp_itr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|