Commit 9566acc4 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Log node splits a little better. Addresses #27

git-svn-id: file:///svn/tokudb@1679 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0a4c6f53
...@@ -300,7 +300,7 @@ static void initialize_brtnode (BRT t, BRTNODE n, DISKOFF nodename, int height) ...@@ -300,7 +300,7 @@ static void initialize_brtnode (BRT t, BRTNODE n, DISKOFF nodename, int height)
} }
} }
static void create_new_brtnode (BRT t, BRTNODE *result, int height) { static void create_new_brtnode (BRT t, BRTNODE *result, int height, TOKUTXN txn) {
TAGMALLOC(BRTNODE, n); TAGMALLOC(BRTNODE, n);
int r; int r;
DISKOFF name = malloc_diskblock(t, t->h->nodesize); DISKOFF name = malloc_diskblock(t, t->h->nodesize);
...@@ -314,6 +314,7 @@ static void create_new_brtnode (BRT t, BRTNODE *result, int height) { ...@@ -314,6 +314,7 @@ static void create_new_brtnode (BRT t, BRTNODE *result, int height) {
//printf("%s:%d putting %p (%lld) parent=%p\n", __FILE__, __LINE__, n, n->thisnodename, parent_brtnode); //printf("%s:%d putting %p (%lld) parent=%p\n", __FILE__, __LINE__, n, n->thisnodename, parent_brtnode);
r=toku_cachetable_put(t->cf, n->thisnodename, n, brtnode_size(n), r=toku_cachetable_put(t->cf, n->thisnodename, n, brtnode_size(n),
toku_brtnode_flush_callback, toku_brtnode_fetch_callback, t); toku_brtnode_flush_callback, toku_brtnode_fetch_callback, t);
r=toku_log_newbrtnode(txn, toku_txn_get_txnid(txn), toku_cachefile_filenum(t->cf), n->thisnodename, height, n->nodesize, (t->flags&TOKU_DB_DUPSORT)!=0, n->rand4fingerprint);
assert(r==0); assert(r==0);
} }
...@@ -358,8 +359,8 @@ static int brtleaf_split (TOKUTXN txn, FILENUM filenum, BRT t, BRTNODE node, BRT ...@@ -358,8 +359,8 @@ static int brtleaf_split (TOKUTXN txn, FILENUM filenum, BRT t, BRTNODE node, BRT
BRTNODE A,B; BRTNODE A,B;
assert(node->height==0); assert(node->height==0);
assert(t->h->nodesize>=node->nodesize); /* otherwise we might be in trouble because the nodesize shrank. */ assert(t->h->nodesize>=node->nodesize); /* otherwise we might be in trouble because the nodesize shrank. */
create_new_brtnode(t, &A, 0); create_new_brtnode(t, &A, 0, txn);
create_new_brtnode(t, &B, 0); create_new_brtnode(t, &B, 0, txn);
//printf("leaf_split %lld - %lld %lld\n", node->thisnodename, A->thisnodename, B->thisnodename); //printf("leaf_split %lld - %lld %lld\n", node->thisnodename, A->thisnodename, B->thisnodename);
//printf("%s:%d A PMA= %p\n", __FILE__, __LINE__, A->u.l.buffer); //printf("%s:%d A PMA= %p\n", __FILE__, __LINE__, A->u.l.buffer);
//printf("%s:%d B PMA= %p\n", __FILE__, __LINE__, A->u.l.buffer); //printf("%s:%d B PMA= %p\n", __FILE__, __LINE__, A->u.l.buffer);
...@@ -396,14 +397,14 @@ static void brt_update_fingerprint_when_moving_hashtable (BRTNODE oldnode, BRTNO ...@@ -396,14 +397,14 @@ static void brt_update_fingerprint_when_moving_hashtable (BRTNODE oldnode, BRTNO
} }
/* Side effect: sets splitk->data pointer to a malloc'd value */ /* Side effect: sets splitk->data pointer to a malloc'd value */
static void brt_nonleaf_split (BRT t, BRTNODE node, BRTNODE *nodea, BRTNODE *nodeb, DBT *splitk) { static void brt_nonleaf_split (BRT t, BRTNODE node, BRTNODE *nodea, BRTNODE *nodeb, DBT *splitk, TOKUTXN txn) {
int n_children_in_a = node->u.n.n_children/2; int n_children_in_a = node->u.n.n_children/2;
BRTNODE A,B; BRTNODE A,B;
assert(node->height>0); assert(node->height>0);
assert(node->u.n.n_children>=2); // Otherwise, how do we split? We need at least two children to split. */ assert(node->u.n.n_children>=2); // Otherwise, how do we split? We need at least two children to split. */
assert(t->h->nodesize>=node->nodesize); /* otherwise we might be in trouble because the nodesize shrank. */ assert(t->h->nodesize>=node->nodesize); /* otherwise we might be in trouble because the nodesize shrank. */
create_new_brtnode(t, &A, node->height); create_new_brtnode(t, &A, node->height, txn);
create_new_brtnode(t, &B, node->height); create_new_brtnode(t, &B, node->height, txn);
A->u.n.n_children=n_children_in_a; A->u.n.n_children=n_children_in_a;
B->u.n.n_children=node->u.n.n_children-n_children_in_a; B->u.n.n_children=node->u.n.n_children-n_children_in_a;
//printf("%s:%d %p (%lld) becomes %p and %p\n", __FILE__, __LINE__, node, node->thisnodename, A, B); //printf("%s:%d %p (%lld) becomes %p and %p\n", __FILE__, __LINE__, node, node->thisnodename, A, B);
...@@ -709,7 +710,7 @@ static int handle_split_of_child (BRT t, BRTNODE node, int childnum, ...@@ -709,7 +710,7 @@ static int handle_split_of_child (BRT t, BRTNODE node, int childnum,
if (node->u.n.n_children>TREE_FANOUT) { if (node->u.n.n_children>TREE_FANOUT) {
//printf("%s:%d about to split having pushed %d out of %d keys\n", __FILE__, __LINE__, i, n_pairs); //printf("%s:%d about to split having pushed %d out of %d keys\n", __FILE__, __LINE__, i, n_pairs);
brt_nonleaf_split(t, node, nodea, nodeb, splitk); brt_nonleaf_split(t, node, nodea, nodeb, splitk, txn);
//printf("%s:%d did split\n", __FILE__, __LINE__); //printf("%s:%d did split\n", __FILE__, __LINE__);
split_count++; split_count++;
*did_split=1; *did_split=1;
......
...@@ -566,6 +566,14 @@ int toku_pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi) { ...@@ -566,6 +566,14 @@ int toku_pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi) {
return n; return n;
} }
/* find the smallest power of 2 >= n */
static unsigned int pma_array_size(PMA pma __attribute__((unused)), int asksize) {
int n = PMA_MIN_ARRAY_SIZE;
while (n < asksize)
n *= 2;
return n;
}
int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM filenum, int maxsize) { int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM filenum, int maxsize) {
int error; int error;
TAGMALLOC(PMA, result); TAGMALLOC(PMA, result);
...@@ -581,10 +589,14 @@ int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM fil ...@@ -581,10 +589,14 @@ int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM fil
result->sval = 0; result->sval = 0;
result->N = PMA_MIN_ARRAY_SIZE; result->N = PMA_MIN_ARRAY_SIZE;
result->pairs = 0; result->pairs = 0;
error = old_pma_resize_array(result, result->N, 0); {
if (error) { unsigned int n = pma_array_size(result, result->N);
toku_free(result); error = toku_resize_pma_exactly(result, 0, n);
return -1; if (error) {
toku_free(result);
return -1;
}
toku_pmainternal_calculate_parameters(result);
} }
if (maxsize == 0) if (maxsize == 0)
maxsize = 4*1024; maxsize = 4*1024;
...@@ -597,15 +609,6 @@ int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM fil ...@@ -597,15 +609,6 @@ int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM fil
assert((unsigned long)result->pairs[result->N]==0xdeadbeefL); assert((unsigned long)result->pairs[result->N]==0xdeadbeefL);
return 0; return 0;
} }
/* find the smallest power of 2 >= n */
static unsigned int pma_array_size(PMA pma __attribute__((unused)), int asksize) {
int n = PMA_MIN_ARRAY_SIZE;
while (n < asksize)
n *= 2;
return n;
}
int toku_resize_pma_exactly (PMA pma, int oldsize, int newsize) { int toku_resize_pma_exactly (PMA pma, int oldsize, int newsize) {
pma->N = newsize; pma->N = newsize;
......
...@@ -77,13 +77,16 @@ $(ALL_TESTS): ...@@ -77,13 +77,16 @@ $(ALL_TESTS):
ifeq ($(VERBOSE),2) ifeq ($(VERBOSE),2)
VERBVERBOSE=-v VERBVERBOSE=-v
MAYBEATSIGN= MAYBEATSIGN=
VERBQUIET=
else else
ifeq ($(VERBOSE),1) ifeq ($(VERBOSE),1)
VERBVERBOSE= VERBVERBOSE=
MAYBEATSIGN= MAYBEATSIGN=
VERBQUIET=
else else
VERBVERBOSE= VERBVERBOSE=
MAYBEATSIGN=@ MAYBEATSIGN=@
VERBQUIET=--quiet
endif endif
endif endif
...@@ -140,7 +143,7 @@ $(patsubst %,test_%.bdbrun,$(NO_VGRIND)): BDB_SUPPRESSIONS= ...@@ -140,7 +143,7 @@ $(patsubst %,test_%.bdbrun,$(NO_VGRIND)): BDB_SUPPRESSIONS=
.PHONY: %.recover .PHONY: %.recover
all.recover: test_log2.recover test_log3.recover test_log4.recover test_log5.recover all.recover: test_log2.recover test_log3.recover test_log4.recover test_log5.recover
%.recover: %.tdb %.recover: %.tdb
$(MAYBEATSIGN) cd ../../newbrt;make --quiet recover $(MAYBEATSIGN) cd ../../newbrt;make $(VERBQUIET) recover
$(MAYBEATSIGN) $(VGRIND) ./$< $(MAYBEATSIGN) $(VGRIND) ./$<
$(MAYBEATSIGN) rm -rf dir.$(patsubst %.tdb,%.c.tdb,$<).recover $(MAYBEATSIGN) rm -rf dir.$(patsubst %.tdb,%.c.tdb,$<).recover
$(MAYBEATSIGN) mkdir dir.$(patsubst %.tdb,%.c.tdb,$<).recover $(MAYBEATSIGN) mkdir dir.$(patsubst %.tdb,%.c.tdb,$<).recover
......
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