Commit 956652f1 authored by Rich Prohaska's avatar Rich Prohaska

update pma cursors whenever the kv pairs are moved in the pma index.

add pma_bulk_insert functionality.



git-svn-id: file:///svn/tokudb@89 c7de825b-a66e-492c-adef-691d508d4ae1
parent e0bf2ec7
......@@ -42,3 +42,8 @@ static inline void *kv_pair_val(struct kv_pair *pair) {
static inline int kv_pair_vallen(struct kv_pair *pair) {
return pair->vallen;
}
struct kv_pair_tag {
struct kv_pair *pair;
int oldtag, newtag;
};
struct list {
struct list *next, *prev;
};
static inline void list_init(struct list *head) {
head->next = head->prev = head;
}
static inline int list_empty(struct list *head) {
return head->next == head;
}
static inline struct list *list_head(struct list *head) {
return head->next;
}
static inline struct list *list_tail(struct list *head) {
return head->prev;
}
static inline void list_insert_between(struct list *a, struct list *list, struct list *b) {
list->next = a->next;
list->prev = b->prev;
a->next = b->prev = list;
}
static inline void list_push(struct list *head, struct list *list) {
list_insert_between(head->prev, list, head);
}
static inline void list_push_head(struct list *head, struct list *list) {
list_insert_between(head, list, head->next);
}
static inline void list_remove(struct list *list) {
list->next->prev = list->prev;
list->prev->next = list->next;
}
static inline struct list *list_pop(struct list *head) {
struct list *list = head->prev;
list_remove(list);
return list;
}
static inline struct list *list_pop_head(struct list *head) {
struct list *list = head->next;
list_remove(list);
return list;
}
static inline void list_move(struct list *newhead, struct list *oldhead) {
struct list *first = oldhead->next;
struct list *last = oldhead->prev;
assert(!list_empty(oldhead));
newhead->next = first;
newhead->prev = last;
last->next = first->prev = newhead;
list_init(oldhead);
}
#define list_struct(p, t, f) (t*)((char*)(p) - __builtin_offsetof(t, f))
......@@ -3,7 +3,7 @@
struct pma_cursor {
PMA pma;
int position; /* -1 if the position is undefined. */
PMA_CURSOR next,prev;
struct list next;
void *skey, *sval; /* used in dbts. */
};
......@@ -19,19 +19,20 @@ struct pma {
* Regions of size 32 are 80% full. Regions of size 64 are 70% full.
* Regions of size 128 are 60% full. Regions of size 256 are 50% full.
* The densitystep is 0.10. */
PMA_CURSOR cursors_head, cursors_tail;
struct list cursors;
int (*compare_fun)(DB*,const DBT*,const DBT*);
void *skey, *sval; /* used in dbts */
};
int pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi);
void pmainternal_calculate_parameters (PMA pma);
int pmainternal_smooth_region (struct kv_pair *pairs[], int n, int idx);
int pmainternal_smooth_region (struct kv_pair *pairs[], int n, int idx, int base, PMA pma);
int pmainternal_printpairs (struct kv_pair *pairs[], int N);
int pmainternal_make_space_at (PMA pma, int idx);
int pmainternal_find (PMA pma, DBT *, DB*); // The DB is so the comparison fuction can be called.
void print_pma (PMA pma); /* useful for debugging, so keep the name short. I.e., not pmainternal_print_pma() */
int pmainternal_init_array(PMA pma, int asksize);
struct kv_pair **pmainternal_extract_pairs(PMA pma, int lo, int hi);
int pma_resize_array(PMA pma, int asksize);
struct kv_pair_tag *pmainternal_extract_pairs(PMA pma, int lo, int hi);
void pma_update_region(PMA pma, struct list *cursorset, struct kv_pair_tag *, int n);
This diff is collapsed.
This diff is collapsed.
......@@ -36,7 +36,27 @@ int pma_delete (PMA, DBT *, DB*);
* Don't modify the returned data. Don't free it. */
enum pma_errors pma_lookup (PMA, DBT*, DBT*, DB*);
int pma_split(PMA old, PMA *newa, PMA *newb, PMA_CURSOR *cursors, int ncursors);
/*
* split a pma into 2 pma's. the new pma's are designated the
* left and right pma's. the left and right pma's have roughly the same
* key and value space.
*
* old - the old pma
* newa - the new pma on the left
* newb - the new pma on the right
*/
int pma_split(PMA old, PMA *newa, PMA *newb);
/*
* insert several key value pairs into an empty pma
*
* pma - the pma that the key value pairs will be inserted into.
* must be empty with no cursors.
* keys - an array of pointers and lengths of the keys
* vals - an array of pointers and lengths of the values
* n_newpairs - the number of key value pairs
*/
int pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs);
/* Move the cursor to the beginning or the end or to a key */
int pma_cursor (PMA, PMA_CURSOR *);
......@@ -45,6 +65,7 @@ int pma_cursor_free (PMA_CURSOR*);
int pma_cursor_set_position_last (PMA_CURSOR c);
int pma_cursor_set_position_first (PMA_CURSOR c);
int pma_cursor_set_position_next (PMA_CURSOR c); /* Requires the cursor is init'd. Returns DB_NOTFOUND if we fall off the end. */
int pma_cursor_set_position_prev (PMA_CURSOR c);
int pma_cget_current (PMA_CURSOR c, DBT *key, DBT *val);
/* Return PMA_NOTFOUND if the pma is empty. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment