end is the cursor position of the first record of the unvisited child link range, which is needed if the insert requires switching from update to rebuild mode.
| 6398 | // end is the cursor position of the first record of the unvisited child link range, which |
| 6399 | // is needed if the insert requires switching from update to rebuild mode. |
| 6400 | void insert(BTreePage::BinaryTree::Cursor end, const VectorRef<RedwoodRecordRef>& recs) { |
| 6401 | int i = 0; |
| 6402 | if (updating) { |
| 6403 | // Update must be done in the new tree, not the original tree where the end cursor will be from |
| 6404 | end.switchTree(btPage()->tree()); |
| 6405 | |
| 6406 | // TODO: insert recs in a random order to avoid new subtree being entirely right child links |
| 6407 | while (i != recs.size()) { |
| 6408 | const RedwoodRecordRef& rec = recs[i]; |
| 6409 | debug_printf("internal page (updating) insert: %s\n", rec.toString(false).c_str()); |
| 6410 | |
| 6411 | if (!end.insert(rec)) { |
| 6412 | debug_printf("internal page: failed to insert %s, switching to rebuild\n", |
| 6413 | rec.toString(false).c_str()); |
| 6414 | |
| 6415 | // Update failed, so populate rebuild vector with everything up to but not including end, which |
| 6416 | // may include items from recs that were already added. |
| 6417 | auto c = end; |
| 6418 | if (c.moveFirst()) { |
| 6419 | rebuild.reserve(rebuild.arena(), c.tree->numItems); |
| 6420 | while (c != end) { |
| 6421 | debug_printf(" internal page rebuild: add %s\n", c.get().toString(false).c_str()); |
| 6422 | rebuild.push_back(rebuild.arena(), c.get()); |
| 6423 | c.moveNext(); |
| 6424 | } |
| 6425 | } |
| 6426 | updating = false; |
| 6427 | break; |
| 6428 | } |
| 6429 | btPage()->kvBytes += rec.kvBytes(); |
| 6430 | ++i; |
| 6431 | } |
| 6432 | } |
| 6433 | |
| 6434 | // Not updating existing page so just add recs to rebuild vector |
| 6435 | if (!updating) { |
| 6436 | rebuild.reserve(rebuild.arena(), rebuild.size() + recs.size()); |
| 6437 | while (i != recs.size()) { |
| 6438 | const RedwoodRecordRef& rec = recs[i]; |
| 6439 | debug_printf("internal page (rebuilding) insert: %s\n", rec.toString(false).c_str()); |
| 6440 | rebuild.push_back(rebuild.arena(), rec); |
| 6441 | ++i; |
| 6442 | } |
| 6443 | } |
| 6444 | } |
| 6445 | |
| 6446 | void keep(BTreePage::BinaryTree::Cursor begin, BTreePage::BinaryTree::Cursor end) { |
| 6447 | if (!updating) { |
nothing calls this directly
no test coverage detected