Commit 8db687e6 authored by John Esmet's avatar John Esmet

FT-590 Calculate a node's weight using a 64 bit integer to prevent

overflow
parent a0150fee
...@@ -182,25 +182,21 @@ static int ...@@ -182,25 +182,21 @@ static int
find_heaviest_child(FTNODE node) find_heaviest_child(FTNODE node)
{ {
int max_child = 0; int max_child = 0;
int max_weight = toku_bnc_nbytesinbuf(BNC(node, 0)) + BP_WORKDONE(node, 0); uint64_t max_weight = toku_bnc_nbytesinbuf(BNC(node, 0)) + BP_WORKDONE(node, 0);
int i;
if (0) printf("%s:%d weights: %d", __FILE__, __LINE__, max_weight); invariant(node->n_children > 0);
paranoid_invariant(node->n_children>0); for (int i = 1; i < node->n_children; i++) {
for (i=1; i<node->n_children; i++) { uint64_t bytes_in_buf = toku_bnc_nbytesinbuf(BNC(node, i));
#ifdef TOKU_DEBUG_PARANOID uint64_t workdone = BP_WORKDONE(node, i);
if (BP_WORKDONE(node,i)) { if (workdone > 0) {
assert(toku_bnc_nbytesinbuf(BNC(node,i)) > 0); invariant(bytes_in_buf > 0);
} }
#endif uint64_t this_weight = bytes_in_buf + workdone;
int this_weight = toku_bnc_nbytesinbuf(BNC(node,i)) + BP_WORKDONE(node,i);;
if (0) printf(" %d", this_weight);
if (max_weight < this_weight) { if (max_weight < this_weight) {
max_child = i; max_child = i;
max_weight = this_weight; max_weight = this_weight;
} }
} }
if (0) printf("\n");
return max_child; return max_child;
} }
......
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