Skip to content

Commit

Permalink
OAK-10150 | Add a test for index purge command where the latest OOB i…
Browse files Browse the repository at this point in the history
…ndex is disabled and the queries are served by a lower versioned index (#875)

Co-authored-by: Nitin Gupta <nitigup@adobe.com>
  • Loading branch information
nit0906 and Nitin Gupta committed Mar 22, 2023
1 parent 05a8563 commit 0720de7
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,67 @@ public void noDeleteIfNoActiveIndex() throws Exception {
}
}

// Test the scenario where the latest index is an OOB index but is disabled, and a lower versioned custom index is actually the only active index serving queries.
// Verify that the lower versioned index that is being used for queries should not get purged.
@Test
public void noDeleteIfLatestOOBIndexIsDisabled() throws Exception {
LogCustomizer custom = LogCustomizer.forLogger("org.apache.jackrabbit.oak.indexversion.IndexVersionOperation")
.enable(Level.INFO)
.create();
try {
custom.starting();
createTestData(false);
createCustomIndex(TEST_INDEX_PATH, 2, 1, false);
createCustomIndex(TEST_INDEX_PATH, 3, 0, false);
createCustomIndex(TEST_INDEX_PATH, 3, 1, false);
createCustomIndex(TEST_INDEX_PATH, 3, 2, false);
createCustomIndex(TEST_INDEX_PATH, 3, 3, false);
createCustomIndex(TEST_INDEX_PATH, 4, 0, false);

NodeStore store = fixture.getNodeStore();
NodeBuilder rootBuilder = store.getRoot().builder();
rootBuilder.getChildNode("oak:index")
.getChildNode("fooIndex-4")
.setProperty("type", "disabled");
rootBuilder.getChildNode("oak:index")
.getChildNode("fooIndex-3-custom-3")
.setProperty("type", "disabled")
.setProperty(":originalType", "lucene");
store.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);

addMockHiddenOakMount(fixture.getNodeStore(), Arrays.asList("fooIndex-3-custom-1", "fooIndex-3-custom-2"));

// At this point of time - we have /oak:index/fooIndex-4 and /oak:index/fooIndex-3-custom-3 which are disabled
// /oak:index/fooIndex-3-custom-2 and /oak:index/fooIndex-3-custom-1 which are active (hidden mount exists)
// Indexes of lower versions are all inactive (not disabled but no hidden oak-mount-exists)

runIndexPurgeCommand(true, 1, "");

List<String> logs = custom.getLogs();
// This log verification shows that /oak:index/fooIndex-4 gets filtered at the very first stage (before the list is sent to IndexVersionOperation)
// This is because it is disabled and does not have :originalType property - so it was disabled manually and not by auto purge command - hence it's simply ignored.
assertThat(logs.toString(), containsString("Reverse Sorted list [/oak:index/fooIndex-3-custom-3"));

// This log verifies that /oak:index/fooIndex-3-custom-3 (which is disabled and has :originalType property) is moved to disabled list to be handled accordingly
assertThat(logs.toString(), containsString("Disabled index list [/oak:index/fooIndex-3-custom-3"));

// This verifies that the index that is considered for isActive check and further verifications is /oak:index/fooIndex-3-custom-2
assertThat(logs.toString(), containsString("new reverse sorted list after removing disabled indexes[/oak:index/fooIndex-3-custom-2"));

NodeState indexRootNode = fixture.getNodeStore().getRoot().getChildNode("oak:index");
Assert.assertFalse(indexRootNode.getChildNode("fooIndex-2-custom-1").exists());
Assert.assertTrue(indexRootNode.getChildNode("fooIndex-3").exists());
Assert.assertEquals("disabled", indexRootNode.getChildNode("fooIndex-3").getProperty("type").getValue(Type.STRING));
Assert.assertTrue(indexRootNode.getChildNode("fooIndex-3-custom-1").exists());
Assert.assertEquals("disabled", indexRootNode.getChildNode("fooIndex-3-custom-1").getProperty("type").getValue(Type.STRING));
Assert.assertTrue(indexRootNode.getChildNode("fooIndex-3-custom-2").exists());
Assert.assertFalse(indexRootNode.getChildNode("fooIndex-3-custom-3").exists());
Assert.assertTrue(indexRootNode.getChildNode("fooIndex-4").exists());
} finally {
custom.finished();
}
}

// currently, there is known issue where indexing time will be missed during indexing job running, that need to be fixed separately.
// but before which is fixed, the purging will not do deletion in that case
@Test
Expand Down

0 comments on commit 0720de7

Please sign in to comment.