Class BPlusTreeReplaceRemoveRaceTest
java.lang.Object
org.apache.ignite.internal.persistence.tree.BPlusTreeReplaceRemoveRaceTest
Test is based on
BPlusTreeSelfTest and has a partial copy of its code.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classShort forT2<Integer, Integer>.protected static classTest tree, mapsIntegertoInteger. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
PAGE_SIZE
protected static final int PAGE_SIZE- See Also:
-
pageMem
-
-
Constructor Details
-
BPlusTreeReplaceRemoveRaceTest
public BPlusTreeReplaceRemoveRaceTest()
-
-
Method Details
-
setUp
public void setUp() -
tearDown
- Throws:
IgniteCheckedException
-
testConcurrentPutRemove
Tests a very specific scenario for concurrent replace and remove that used to corrupt the tree before the fix. Consider the following tree, represented by atreevariable in test:
Individual replace[ 5:0 ] / \ [ 2:0 | 4:0 ] [ 6:0 ] / | \ / \ [ 1:0 | 2:0 ] [ 3:0 | 4:0 ] [ 5:0 ] [ 6:0 ] [ 7:0 ]4:0to4:8would take two steps and look like this:
Note that inbetween these two updates tree is fully unlocked and available for modifications. So, if one tries to remove// Inner node goes first. [ 5:0 ] / \ [ 2:0 | 4:8 ] [ 6:0 ] / | \ / \ [ 1:0 | 2:0 ] [ 3:0 | 4:0 ] [ 5:0 ] [ 6:0 ] [ 7:0 ] // Leaf node goes last. [ 5:0 ] / \ [ 2:0 | 4:8 ] [ 6:0 ] / | \ / \ [ 1:0 | 2:0 ] [ 3:0 | 4:8 ] [ 5:0 ] [ 6:0 ] [ 7:0 ]5:0during the replacement, following modifications would happen:
It is clear that root has an invalid value// Inner node update from replacement goes first, as before. [ 5:0 ] / \ [ 2:0 | 4:8 ] [ 6:0 ] / | \ / \ [ 1:0 | 2:0 ] [ 3:0 | 4:0 ] [ 5:0 ] [ 6:0 ] [ 7:0 ] // Removal of 5:0 starts from the leaf. [ 5:0 ] / \ [ 2:0 | 4:8 ] [ 6:0 ] / | \ / \ [ 1:0 | 2:0 ] [ 3:0 | 4:0 ] [] [ 6:0 ] [ 7:0 ] // Merge of empty branch is now required, 4:8 is removed from inner node. [ 5:0 ] / \ [ 2:0 ] [ 6:0 ] / \ / \ [ 1:0 | 2:0 ] [ 3:0 | 4:0 ] [ 6:0 ] [ 7:0 ] // Inner replace is happening in the root. To do that, closest left value is retrieved from the leaf, it's 4:0. [ 4:0 ] / \ [ 2:0 ] [ 6:0 ] / \ / \ [ 1:0 | 2:0 ] [ 3:0 | 4:0 ] [ 6:0 ] [ 7:0 ] // At this point removal is complete. Last replacement step will do the following. [ 4:0 ] / \ [ 2:0 ] [ 6:0 ] / \ / \ [ 1:0 | 2:0 ] [ 3:0 | 4:8 ] [ 6:0 ] [ 7:0 ]4:0, hence the tree should be considered corrupted. This is the exact situation that test is trying to check. Several iterations are required for this, given that there's no guaranteed way to force a tree to perform page modifications in the desired order. Typically, less than10attempts have been required to get a corrupted tree. Value50is arbitrary and has been chosen to be big enough for test to fail in case of regression, but not too big so that test won't run for too long.- Throws:
Exception- If failed.
-