use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class GBPTreeTest method mustThrowIfStuckInInfiniteRootCatchup.
/* Inconsistency tests */
@Test
void mustThrowIfStuckInInfiniteRootCatchup() throws IOException {
// Create a tree with root and two children.
// Corrupt one of the children and make it look like a freelist node.
// This will cause seekCursor to start from root in an attempt, believing it went wrong because of concurrent updates.
// When seekCursor comes back to the same corrupt child again and again it should eventually escape from that loop
// with an exception.
List<Long> trace = new ArrayList<>();
MutableBoolean onOffSwitch = new MutableBoolean(true);
CursorContext cursorContext = new CursorContext(trackingPageCursorTracer(trace, onOffSwitch));
// Build a tree with root and two children.
try (PageCache pageCache = createPageCache(defaultPageSize);
GBPTree<MutableLong, MutableLong> tree = index(pageCache).build()) {
// Insert data until we have a split in root
treeWithRootSplit(trace, tree, cursorContext);
long corruptChild = trace.get(1);
// We are not interested in further trace tracking
onOffSwitch.setFalse();
// Corrupt the child
corruptTheChild(pageCache, corruptChild);
assertThatThrownBy(() -> {
// when seek end up in this corrupt child we should eventually fail with a tree inconsistency exception
try (Seeker<MutableLong, MutableLong> seek = tree.seek(new MutableLong(0), new MutableLong(0), cursorContext)) {
seek.next();
}
}).isInstanceOf(TreeInconsistencyException.class).hasMessageContaining("Index traversal aborted due to being stuck in infinite loop. This is most likely caused by an inconsistency " + "in the index. Loop occurred when restarting search from root from page " + corruptChild + ".");
}
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class GBPTreeConsistencyCheckerTestBase method assertReportAllocSpaceOverlapOffsetArray.
private static <KEY, VALUE> void assertReportAllocSpaceOverlapOffsetArray(GBPTree<KEY, VALUE> index, long targetNode) throws IOException {
MutableBoolean called = new MutableBoolean();
index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {
@Override
public void nodeMetaInconsistency(long pageId, String message, Path file) {
called.setTrue();
assertEquals(targetNode, pageId);
assertThat(message).contains("Overlap between offsetArray and allocSpace");
}
}, NULL);
assertCalled(called);
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class GBPTreeConsistencyCheckerTestBase method assertReportCircularChildPointer.
private static <KEY, VALUE> void assertReportCircularChildPointer(GBPTree<KEY, VALUE> index, long targetNode) throws IOException {
MutableBoolean called = new MutableBoolean();
index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {
@Override
public void childNodeFoundAmongParentNodes(KeyRange<KEY> superRange, int level, long pageId, Path file) {
called.setTrue();
assertEquals(targetNode, pageId);
}
}, NULL);
assertCalled(called);
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class GBPTreeConsistencyCheckerTestBase method assertReportUnreasonableKeyCount.
private static <KEY, VALUE> void assertReportUnreasonableKeyCount(GBPTree<KEY, VALUE> index, long targetNode, int targetKeyCount) throws IOException {
MutableBoolean called = new MutableBoolean();
index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {
@Override
public void unreasonableKeyCount(long pageId, int keyCount, Path file) {
called.setTrue();
assertEquals(targetNode, pageId);
assertEquals(targetKeyCount, keyCount);
}
}, NULL);
assertCalled(called);
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class GBPTreeConsistencyCheckerTestBase method assertReportPointerGenerationLowerThanNodeGeneration.
private static <KEY, VALUE> void assertReportPointerGenerationLowerThanNodeGeneration(GBPTree<KEY, VALUE> index, long targetNode, GBPTreePointerType expectedPointerType) throws IOException {
MutableBoolean called = new MutableBoolean();
index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {
@Override
public void pointerHasLowerGenerationThanNode(GBPTreePointerType pointerType, long sourceNode, long pointerGeneration, long pointer, long targetNodeGeneration, Path file) {
called.setTrue();
assertEquals(targetNode, sourceNode);
assertEquals(expectedPointerType, pointerType);
}
}, NULL);
assertCalled(called);
}
Aggregations