evil? lucky? whitespace cleanup
git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@666 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
This commit is contained in:
parent
b75ad3675c
commit
020f0faf17
2 changed files with 572 additions and 664 deletions
File diff suppressed because it is too large
Load diff
|
@ -33,7 +33,7 @@ typedef struct RegionAllocConf_t
|
||||||
} RegionAllocConf_t;
|
} RegionAllocConf_t;
|
||||||
|
|
||||||
struct indexnode_rec {
|
struct indexnode_rec {
|
||||||
pageid_t ptr;
|
pageid_t ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef pageid_t(*diskTreeComponent_page_allocator_t)(int, void *);
|
typedef pageid_t(*diskTreeComponent_page_allocator_t)(int, void *);
|
||||||
|
@ -41,152 +41,145 @@ typedef void(*diskTreeComponent_page_deallocator_t)(int, void *);
|
||||||
|
|
||||||
class diskTreeComponent{
|
class diskTreeComponent{
|
||||||
public:
|
public:
|
||||||
diskTreeComponent(int xid): region_alloc(new DataPage<datatuple>::RegionAllocator(xid, 10000)) {create(xid);} // XXX shouldn't hardcode region size.
|
diskTreeComponent(int xid): region_alloc(new DataPage<datatuple>::RegionAllocator(xid, 10000)) {create(xid);} // XXX shouldn't hardcode region size.
|
||||||
diskTreeComponent(int xid, recordid root, recordid state, recordid dp_state)
|
diskTreeComponent(int xid, recordid root, recordid state, recordid dp_state)
|
||||||
: tree_state(state),
|
: tree_state(state),
|
||||||
root_rec(root),
|
root_rec(root),
|
||||||
region_alloc(new DataPage<datatuple>::RegionAllocator(xid, dp_state)) { lastLeaf = -1; }
|
region_alloc(new DataPage<datatuple>::RegionAllocator(xid, dp_state)) { lastLeaf = -1; }
|
||||||
private:
|
private:
|
||||||
recordid create(int xid);
|
recordid create(int xid);
|
||||||
public:
|
public:
|
||||||
void print_tree(int xid);
|
void print_tree(int xid);
|
||||||
|
|
||||||
static void init_stasis();
|
static void init_stasis();
|
||||||
static void deinit_stasis();
|
static void deinit_stasis();
|
||||||
private:
|
private:
|
||||||
static pageid_t alloc_region(int xid, void *conf);
|
static pageid_t alloc_region(int xid, void *conf);
|
||||||
public:
|
public:
|
||||||
static pageid_t alloc_region_rid(int xid, void * ridp);
|
static pageid_t alloc_region_rid(int xid, void * ridp);
|
||||||
static void force_region_rid(int xid, recordid rid);
|
static void force_region_rid(int xid, recordid rid);
|
||||||
static pageid_t*list_region_rid(int xid, void * ridp, pageid_t * region_len, pageid_t * region_count);
|
static pageid_t*list_region_rid(int xid, void * ridp,
|
||||||
static void dealloc_region_rid(int xid, recordid rid);
|
pageid_t * region_len, pageid_t * region_count);
|
||||||
static void free_region_rid(int xid, recordid tree,
|
static void dealloc_region_rid(int xid, recordid rid);
|
||||||
diskTreeComponent_page_deallocator_t dealloc,
|
static void free_region_rid(int xid, recordid tree,
|
||||||
void *allocator_state);
|
diskTreeComponent_page_deallocator_t dealloc,
|
||||||
|
void *allocator_state);
|
||||||
|
|
||||||
static void writeNodeRecord(int xid, Page *p, recordid &rid,
|
static void writeNodeRecord(int xid, Page *p, recordid &rid,
|
||||||
const byte *key, size_t keylen, pageid_t ptr);
|
const byte *key, size_t keylen, pageid_t ptr);
|
||||||
|
|
||||||
static void writeRecord(int xid, Page *p, recordid &rid,
|
static void writeRecord(int xid, Page *p, recordid &rid,
|
||||||
const byte *data, size_t datalen);
|
const byte *data, size_t datalen);
|
||||||
|
|
||||||
static void writeRecord(int xid, Page *p, slotid_t slot,
|
static void writeRecord(int xid, Page *p, slotid_t slot,
|
||||||
const byte *data, size_t datalen);
|
const byte *data, size_t datalen);
|
||||||
|
|
||||||
static const byte* readRecord(int xid, Page * p, recordid &rid);
|
static const byte* readRecord(int xid, Page * p, recordid &rid);
|
||||||
static const byte* readRecord(int xid, Page * p, slotid_t slot, int64_t size);
|
static const byte* readRecord(int xid, Page * p, slotid_t slot, int64_t size);
|
||||||
|
|
||||||
static int32_t readRecordLength(int xid, Page *p, slotid_t slot);
|
static int32_t readRecordLength(int xid, Page *p, slotid_t slot);
|
||||||
|
|
||||||
//return the left-most leaf, these are not data pages, although referred to as leaf
|
//return the left-most leaf, these are not data pages, although referred to as leaf
|
||||||
static pageid_t findFirstLeaf(int xid, Page *root, int64_t depth);
|
static pageid_t findFirstLeaf(int xid, Page *root, int64_t depth);
|
||||||
//return the right-most leaf
|
//return the right-most leaf
|
||||||
static pageid_t findLastLeaf(int xid, Page *root, int64_t depth) ;
|
static pageid_t findLastLeaf(int xid, Page *root, int64_t depth) ;
|
||||||
|
|
||||||
//reads the given record and returns the page id stored in it
|
//reads the given record and returns the page id stored in it
|
||||||
static pageid_t lookupLeafPageFromRid(int xid, recordid rid);
|
static pageid_t lookupLeafPageFromRid(int xid, recordid rid);
|
||||||
|
|
||||||
//returns a record that stores the pageid where the given key should be in, i.e. if it exists
|
//returns a record that stores the pageid where the given key should be in, i.e. if it exists
|
||||||
static recordid lookup(int xid, Page *node, int64_t depth, const byte *key,
|
static recordid lookup(int xid, Page *node, int64_t depth, const byte *key,
|
||||||
size_t keySize);
|
size_t keySize);
|
||||||
|
|
||||||
//returns the id of the data page that could contain the given key
|
//returns the id of the data page that could contain the given key
|
||||||
static pageid_t findPage(int xid, recordid tree, const byte *key, size_t keySize);
|
static pageid_t findPage(int xid, recordid tree, const byte *key, size_t keySize);
|
||||||
|
|
||||||
|
|
||||||
//appends a leaf page, val_page is the id of the leaf page
|
//appends a leaf page, val_page is the id of the leaf page
|
||||||
//rmLeafID --> rightmost leaf id
|
//rmLeafID --> rightmost leaf id
|
||||||
static recordid appendPage(int xid, recordid tree, pageid_t & rmLeafID,
|
static recordid appendPage(int xid, recordid tree, pageid_t & rmLeafID,
|
||||||
const byte *key,size_t keySize,
|
const byte *key,size_t keySize,
|
||||||
diskTreeComponent_page_allocator_t allocator, void *allocator_state,
|
diskTreeComponent_page_allocator_t allocator, void *allocator_state,
|
||||||
long val_page);
|
long val_page);
|
||||||
|
|
||||||
static recordid appendInternalNode(int xid, Page *p,
|
static recordid appendInternalNode(int xid, Page *p,
|
||||||
int64_t depth,
|
int64_t depth,
|
||||||
const byte *key, size_t key_len,
|
const byte *key, size_t key_len,
|
||||||
pageid_t val_page, pageid_t lastLeaf,
|
pageid_t val_page, pageid_t lastLeaf,
|
||||||
diskTreeComponent_page_allocator_t allocator,
|
diskTreeComponent_page_allocator_t allocator,
|
||||||
void *allocator_state);
|
void *allocator_state);
|
||||||
|
|
||||||
static recordid buildPathToLeaf(int xid, recordid root, Page *root_p,
|
static recordid buildPathToLeaf(int xid, recordid root, Page *root_p,
|
||||||
int64_t depth, const byte *key, size_t key_len,
|
int64_t depth, const byte *key, size_t key_len,
|
||||||
pageid_t val_page, pageid_t lastLeaf,
|
pageid_t val_page, pageid_t lastLeaf,
|
||||||
diskTreeComponent_page_allocator_t allocator,
|
diskTreeComponent_page_allocator_t allocator,
|
||||||
void *allocator_state);
|
void *allocator_state);
|
||||||
|
|
||||||
inline DataPage<datatuple>::RegionAllocator* get_alloc() { return region_alloc; }
|
inline DataPage<datatuple>::RegionAllocator* get_alloc() { return region_alloc; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initialize a page for use as an internal node of the tree.
|
Initialize a page for use as an internal node of the tree.
|
||||||
*/
|
*/
|
||||||
inline static void initializeNodePage(int xid, Page *p);
|
inline static void initializeNodePage(int xid, Page *p);
|
||||||
|
|
||||||
recordid &get_tree_state(){return tree_state;}
|
recordid &get_tree_state(){return tree_state;}
|
||||||
recordid &get_root_rec(){return root_rec;}
|
recordid &get_root_rec(){return root_rec;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const static RegionAllocConf_t REGION_ALLOC_STATIC_INITIALIZER;
|
const static RegionAllocConf_t REGION_ALLOC_STATIC_INITIALIZER;
|
||||||
const static int64_t DEPTH;
|
const static int64_t DEPTH;
|
||||||
const static int64_t COMPARATOR;
|
const static int64_t COMPARATOR;
|
||||||
const static int64_t FIRST_SLOT;
|
const static int64_t FIRST_SLOT;
|
||||||
const static size_t root_rec_size;
|
const static size_t root_rec_size;
|
||||||
const static int64_t PREV_LEAF;
|
const static int64_t PREV_LEAF;
|
||||||
const static int64_t NEXT_LEAF;
|
const static int64_t NEXT_LEAF;
|
||||||
|
|
||||||
pageid_t lastLeaf;
|
pageid_t lastLeaf;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void print_tree(int xid, pageid_t pid, int64_t depth);
|
void print_tree(int xid, pageid_t pid, int64_t depth);
|
||||||
|
|
||||||
private:
|
recordid tree_state;
|
||||||
recordid tree_state;
|
recordid root_rec;
|
||||||
recordid root_rec;
|
|
||||||
|
|
||||||
DataPage<datatuple>::RegionAllocator* region_alloc;
|
|
||||||
|
|
||||||
|
DataPage<datatuple>::RegionAllocator* region_alloc;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Page * p;
|
Page * p;
|
||||||
recordid current;
|
recordid current;
|
||||||
indexnode_rec *t;
|
indexnode_rec *t;
|
||||||
int justOnePage;
|
int justOnePage;
|
||||||
} diskTreeComponentIterator_t;
|
} diskTreeComponentIterator_t;
|
||||||
|
|
||||||
|
|
||||||
class diskTreeComponentIterator
|
class diskTreeComponentIterator {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static lladdIterator_t* open(int xid, recordid root);
|
static lladdIterator_t* open(int xid, recordid root);
|
||||||
static lladdIterator_t* openAt(int xid, recordid root, const byte* key, len_t keylen);
|
static lladdIterator_t* openAt(int xid, recordid root, const byte* key, len_t keylen);
|
||||||
static int next(int xid, lladdIterator_t *it);
|
static int next(int xid, lladdIterator_t *it);
|
||||||
static void close(int xid, lladdIterator_t *it);
|
static void close(int xid, lladdIterator_t *it);
|
||||||
|
|
||||||
|
|
||||||
static inline size_t key (int xid, lladdIterator_t *it, byte **key)
|
static inline size_t key (int xid, lladdIterator_t *it, byte **key) {
|
||||||
{
|
diskTreeComponentIterator_t * impl = (diskTreeComponentIterator_t*)it->impl;
|
||||||
diskTreeComponentIterator_t * impl = (diskTreeComponentIterator_t*)it->impl;
|
*key = (byte*)(impl->t+1);
|
||||||
*key = (byte*)(impl->t+1);
|
return impl->current.size - sizeof(indexnode_rec);
|
||||||
return impl->current.size - sizeof(indexnode_rec);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
static inline size_t value(int xid, lladdIterator_t *it, byte **value) {
|
||||||
|
diskTreeComponentIterator_t * impl = (diskTreeComponentIterator_t*)it->impl;
|
||||||
|
*value = (byte*)&(impl->t->ptr);
|
||||||
|
return sizeof(impl->t->ptr);
|
||||||
|
}
|
||||||
|
|
||||||
static inline size_t value(int xid, lladdIterator_t *it, byte **value)
|
static inline void tupleDone(int xid, void *it) { }
|
||||||
{
|
static inline void releaseLock(int xid, void *it) { }
|
||||||
diskTreeComponentIterator_t * impl = (diskTreeComponentIterator_t*)it->impl;
|
|
||||||
*value = (byte*)&(impl->t->ptr);
|
|
||||||
return sizeof(impl->t->ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void tupleDone(int xid, void *it) { }
|
|
||||||
static inline void releaseLock(int xid, void *it) { }
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* DISKTREECOMPONENT_H_ */
|
#endif /* DISKTREECOMPONENT_H_ */
|
||||||
|
|
Loading…
Reference in a new issue