Commit 2d22815d authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Fix up the {{{toku_serialize_brtnode_size_slow}}} to work right on non-leaf nodes. Fixes #685.

git-svn-id: file:///svn/tokudb@3393 c7de825b-a66e-492c-adef-691d508d4ae1
parent a8a3471e
...@@ -27,7 +27,7 @@ static const int brtnode_header_overhead = (8+ // magic "tokunode" or "tokulea ...@@ -27,7 +27,7 @@ static const int brtnode_header_overhead = (8+ // magic "tokunode" or "tokulea
4+ // localfingerprint 4+ // localfingerprint
4); // crc32 at the end 4); // crc32 at the end
static unsigned int toku_serialize_brtnode_size_slow(BRTNODE node) { static unsigned int toku_serialize_brtnode_size_slow (BRTNODE node) {
unsigned int size=brtnode_header_overhead; unsigned int size=brtnode_header_overhead;
if (node->height>0) { if (node->height>0) {
unsigned int hsize=0; unsigned int hsize=0;
...@@ -35,17 +35,13 @@ static unsigned int toku_serialize_brtnode_size_slow(BRTNODE node) { ...@@ -35,17 +35,13 @@ static unsigned int toku_serialize_brtnode_size_slow(BRTNODE node) {
int i; int i;
size+=4; /* n_children */ size+=4; /* n_children */
size+=4; /* subtree fingerprint. */ size+=4; /* subtree fingerprint. */
size+=4*(node->u.n.n_children-1); /* key lengths*/
if (node->flags & TOKU_DB_DUPSORT) size += 4*(node->u.n.n_children-1);
for (i=0; i<node->u.n.n_children-1; i++) { for (i=0; i<node->u.n.n_children-1; i++) {
size+=4;
if (node->flags & TOKU_DB_DUPSORT) size += 4;
csize+=toku_brtnode_pivot_key_len(node, node->u.n.childkeys[i]); csize+=toku_brtnode_pivot_key_len(node, node->u.n.childkeys[i]);
} }
for (i=0; i<node->u.n.n_children; i++) { size+=(8+4+4)*(node->u.n.n_children); /* For each child, a child offset, a count for the number of hash table entries, and the subtree fingerprint. */
size+=8; // diskoff
size+=4; // subsum
}
int n_buffers = node->u.n.n_children; int n_buffers = node->u.n.n_children;
size+=4; /* n_entries */
assert(0 <= n_buffers && n_buffers < TREE_FANOUT+1); assert(0 <= n_buffers && n_buffers < TREE_FANOUT+1);
for (i=0; i< n_buffers; i++) { for (i=0; i< n_buffers; i++) {
FIFO_ITERATE(BNC_BUFFER(node,i), FIFO_ITERATE(BNC_BUFFER(node,i),
...@@ -87,17 +83,11 @@ unsigned int toku_serialize_brtnode_size (BRTNODE node) { ...@@ -87,17 +83,11 @@ unsigned int toku_serialize_brtnode_size (BRTNODE node) {
result+=(4 /* n_entries in buffer table. */ result+=(4 /* n_entries in buffer table. */
+4); /* the pma size */ +4); /* the pma size */
result+=node->u.l.n_bytes_in_buffer; result+=node->u.l.n_bytes_in_buffer;
#if 0
if (toku_memory_check) { if (toku_memory_check) {
unsigned int slowresult = toku_serialize_brtnode_size_slow(node); unsigned int slowresult = toku_serialize_brtnode_size_slow(node);
if (result!=slowresult) printf("%s:%d result=%d slowresult=%d\n", __FILE__, __LINE__, result, slowresult); if (result!=slowresult) printf("%s:%d result=%d slowresult=%d\n", __FILE__, __LINE__, result, slowresult);
assert(result==slowresult); assert(result==slowresult);
} }
#else
unsigned int slowresult = toku_serialize_brtnode_size_slow(node);
if (result != slowresult)
result = slowresult;
#endif
} }
return result; return result;
} }
...@@ -106,7 +96,10 @@ void toku_serialize_brtnode_to (int fd, DISKOFF off, DISKOFF size, BRTNODE node) ...@@ -106,7 +96,10 @@ void toku_serialize_brtnode_to (int fd, DISKOFF off, DISKOFF size, BRTNODE node)
//printf("%s:%d serializing\n", __FILE__, __LINE__); //printf("%s:%d serializing\n", __FILE__, __LINE__);
struct wbuf w; struct wbuf w;
int i; int i;
unsigned int calculated_size = toku_serialize_brtnode_size(node); unsigned int calculated_size = toku_serialize_brtnode_size_slow(node);
if (calculated_size!=toku_serialize_brtnode_size(node)) {
printf("Sizes don't match: %d %d\n", calculated_size, toku_serialize_brtnode_size(node));
}
assert(calculated_size<=size); assert(calculated_size<=size);
//char buf[size]; //char buf[size];
char *MALLOC_N(size,buf); char *MALLOC_N(size,buf);
......
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