Skip to content

Commit 53a154e

Browse files
committed
small cleanup, improvements back until race condition in forest is resolved
1 parent 1fffcb5 commit 53a154e

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/BPlusTreeBase.hpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,9 @@ bool BPlusTreeBase<Key,T>::erase_req(node_ptr node, node_ptr parent, const Key&
483483

484484
// Remove and end with all nodes that will never be modified
485485
if(node->size() > factor){
486-
while(list.front().get() != node.get()){
486+
// !!! Fix race condition for the FOREST module. Time boxed change !!!
487+
node_ptr comp = node->is_leaf() ? parent : node;
488+
while(list.front().get() != comp.get()){
487489
node_ptr n = list.front();
488490
processSearchNodeEnd(n);
489491
list.pop_front();
@@ -720,7 +722,9 @@ bool BPlusTreeBase<Key,T>::insert_req(node_ptr node, node_ptr parent, EntryItem_
720722

721723
// Remove and end with all nodes from list that will never be modified
722724
if(node->size() < factor*2-1){
723-
while(list.front().get() != node.get()){
725+
// !!! Fix race condition for the FOREST module. Time boxed change !!!
726+
node_ptr comp = node->is_leaf() ? parent : node;
727+
while(list.front().get() != comp.get()){
724728
node_ptr n = list.front();
725729
processSearchNodeEnd(n);
726730
list.pop_front();
@@ -772,6 +776,11 @@ bool BPlusTreeBase<Key,T>::insert_req(node_ptr node, node_ptr parent, EntryItem_
772776
node_ptr nnode = nullptr;
773777

774778
if(node->size() >= factor*2){
779+
780+
// Ensure that parent node is locked
781+
assert(!list.empty());
782+
783+
// Parent node will be changed
775784
nodeChanged = true;
776785

777786
// Create new node to split to
@@ -799,19 +808,19 @@ bool BPlusTreeBase<Key,T>::insert_req(node_ptr node, node_ptr parent, EntryItem_
799808
// New node is next to current node
800809

801810
// Update dependencies of newly created node
802-
if(is_leaf(node)){
803-
node_ptr nextLeaf = node->next_leaf();
804-
nnode->set_next_leaf(nextLeaf);
805-
nnode->set_prev_leaf(node);
806-
}
811+
node_ptr nextLeaf = node->next_leaf();
812+
nnode->set_next_leaf(nextLeaf);
813+
nnode->set_prev_leaf(node);
814+
807815
// Process newly created node
808816
processInsertNode(nnode);
809817
// Process Node after search
810818
processSearchNodeEnd(nnode);
811819

812820
// Set next to newly created node prev leaf
813-
node_ptr nextLeaf = node->next_leaf();
814821
node->set_next_leaf(nnode);
822+
823+
// Update next leaf
815824
if(nextLeaf){
816825
processSearchNodeStart(nextLeaf);
817826
nextLeaf->set_prev_leaf(nnode);
@@ -823,19 +832,19 @@ bool BPlusTreeBase<Key,T>::insert_req(node_ptr node, node_ptr parent, EntryItem_
823832
// New node is before the current nide
824833

825834
// Update dependencies of newly created node
826-
if(is_leaf(node)){
827-
node_ptr prevLeaf = node->prev_leaf();
828-
nnode->set_prev_leaf(prevLeaf);
829-
nnode->set_next_leaf(node);
830-
}
835+
node_ptr prevLeaf = node->prev_leaf();
836+
nnode->set_prev_leaf(prevLeaf);
837+
nnode->set_next_leaf(node);
838+
831839
// Process newly created node
832840
processInsertNode(nnode);
833841
// Process Node after search
834842
processSearchNodeEnd(nnode);
835843

836844
// Set prev from newly created node next leaf
837-
node_ptr prevLeaf = node->prev_leaf();
838845
node->set_prev_leaf(nnode);
846+
847+
// Update prev node
839848
if(prevLeaf){
840849
processSearchNodeStart(prevLeaf);
841850
prevLeaf->set_next_leaf(nnode);

src/BPlusTreeBaseInternalNode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ int BPlusTreeBaseInternalNode<Key, T>::get_index(Node* node)
319319
if((*child_nodes)[i].get() == node)
320320
return i;
321321
}
322-
return 0;
322+
return sz;
323323
}
324324

325325
template<class Key, class T>

0 commit comments

Comments
 (0)