use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method closeWithSoftLimit.
@Test
public void closeWithSoftLimit() throws Exception {
NodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
final Semaphore asyncLock = new Semaphore(1);
final AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider) {
@Override
protected AsyncUpdateCallback newAsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String beforeCheckpoint, AsyncIndexStats indexStats, AtomicBoolean stopFlag) {
try {
asyncLock.acquire();
} catch (InterruptedException ignore) {
}
return super.newAsyncUpdateCallback(store, name, leaseTimeOut, beforeCheckpoint, indexStats, stopFlag);
}
};
async.setCloseTimeOut(1000);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
async.run();
}
});
Thread closer = new Thread(new Runnable() {
@Override
public void run() {
async.close();
}
});
asyncLock.acquire();
t.start();
//Wait till async gets to wait state i.e. inside run
while (!asyncLock.hasQueuedThreads()) ;
LogCustomizer lc = createLogCustomizer(Level.DEBUG);
closer.start();
//Wait till closer is in waiting state
while (!async.isClosing()) ;
//For softLimit case the flag should not be set
assertFalse(async.isClosed());
assertLogPhrase(lc.getLogs(), "[WAITING]");
//Let indexing run complete now
asyncLock.release();
//Wait for both threads
t.join();
closer.join();
//Close call should complete
assertLogPhrase(lc.getLogs(), "[CLOSED OK]");
}
use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method taskSplitNoMatch.
@Test
public void taskSplitNoMatch() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "ignored", true, false, ImmutableSet.of("baz"), null).setProperty(ASYNC_PROPERTY_NAME, "async-ignored");
builder.child("testRoot").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
async.run();
assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
String firstCp = store.listCheckpoints().iterator().next();
builder = store.getRoot().builder();
builder.child("testRoot").setProperty("foo", "def");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
IndexTaskSpliter splitter = async.getTaskSplitter();
// no match on the provided path
splitter.registerSplit(newHashSet("/oak:index/ignored"), "async-slow");
async.run();
Set<String> checkpoints = newHashSet(store.listCheckpoints());
assertTrue("Expecting a single checkpoint", checkpoints.size() == 1);
String secondCp = checkpoints.iterator().next();
NodeState asyncNode = store.getRoot().getChildNode(ASYNC);
assertEquals(secondCp, asyncNode.getString("async"));
assertNull(firstCp, asyncNode.getString("async-slow"));
}
use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method recoverFromMissingCpRef.
/**
* OAK-1959, stale ref to checkpoint thorws the indexer into a reindexing
* loop
*/
@Test
public void recoverFromMissingCpRef() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
new AsyncIndexUpdate("async", store, provider).run();
checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex", INDEX_CONTENT_NODE_NAME, "abc", "testRoot");
builder = store.getRoot().builder();
// change cp ref to point to a non-existing one
builder.child(ASYNC).setProperty("async", "faulty");
builder.child("testAnother").setProperty("foo", "def");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
new AsyncIndexUpdate("async", store, provider).run();
checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex", INDEX_CONTENT_NODE_NAME, "def", "testAnother");
}
use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method greedyLeaseReindex.
@Test
public void greedyLeaseReindex() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
AsyncIndexUpdate pre = new AsyncIndexUpdate("async", store, provider);
pre.run();
pre.close();
// rm all cps to simulate 'missing cp scenario'
for (String cp : store.listCheckpoints()) {
store.release(cp);
}
final AtomicBoolean greedyLease = new AtomicBoolean(false);
final AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider) {
@Override
protected AsyncUpdateCallback newAsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String beforeCheckpoint, AsyncIndexStats indexStats, AtomicBoolean stopFlag) {
return new AsyncUpdateCallback(store, name, leaseTimeOut, beforeCheckpoint, indexStats, stopFlag) {
@Override
protected void initLease() throws CommitFailedException {
greedyLease.set(true);
super.initLease();
}
@Override
protected void prepare(String afterCheckpoint) throws CommitFailedException {
assertTrue(greedyLease.get());
super.prepare(afterCheckpoint);
}
};
}
};
async.run();
async.close();
assertTrue(greedyLease.get());
}
use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method longTimeFailingIndexMarkedAsCorrupt.
@Test
public void longTimeFailingIndexMarkedAsCorrupt() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "barIndex", true, false, ImmutableSet.of("bar"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot1").setProperty("foo", "abc");
builder.child("testRoot2").setProperty("bar", "abc");
// merge it back in
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
TestIndexEditorProvider provider = new TestIndexEditorProvider();
Clock clock = new Clock.Virtual();
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
async.getCorruptIndexHandler().setClock(clock);
async.run();
//1. Basic sanity check. Indexing works
PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
assertEquals(ImmutableSet.of("testRoot1"), find(lookup, "foo", "abc"));
assertEquals(ImmutableSet.of("testRoot2"), find(lookup, "bar", "abc"));
//2. Add some new content
builder = store.getRoot().builder();
builder.child("testRoot3").setProperty("foo", "xyz");
builder.child("testRoot4").setProperty("bar", "xyz");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
//3. Now fail the indexing for 'bar'
provider.enableFailureMode("/oak:index/barIndex");
async.run();
assertTrue(async.getIndexStats().isFailing());
//barIndex is failing but not yet considered corrupted
assertTrue(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/barIndex"));
assertFalse(async.getCorruptIndexHandler().getCorruptIndexData("async").containsKey("/oak:index/barIndex"));
CorruptIndexInfo barIndexInfo = async.getCorruptIndexHandler().getFailingIndexData("async").get("/oak:index/barIndex");
//fooIndex is fine
assertFalse(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/fooIndex"));
//lookup should also fail as indexing failed
lookup = new PropertyIndexLookup(store.getRoot());
assertTrue(find(lookup, "foo", "xyz").isEmpty());
assertTrue(find(lookup, "bar", "xyz").isEmpty());
//4.Now move the clock forward and let the failing index marked as corrupt
clock.waitUntil(clock.getTime() + async.getCorruptIndexHandler().getCorruptIntervalMillis() + 1);
//5. Let async run again
async.run();
//Indexing would be considered as failing
assertTrue(async.getIndexStats().isFailing());
assertEquals(IndexStatsMBean.STATUS_FAILING, async.getIndexStats().getStatus());
//barIndex should be considered corrupt now
assertTrue(async.getCorruptIndexHandler().getCorruptIndexData("async").containsKey("/oak:index/barIndex"));
lookup = new PropertyIndexLookup(store.getRoot());
//fooIndex should now report updated result. barIndex would fail
assertEquals(ImmutableSet.of("testRoot3"), find(lookup, "foo", "xyz"));
assertTrue(find(lookup, "bar", "xyz").isEmpty());
assertEquals(1, barIndexInfo.getSkippedCount());
//6. Index some stuff
builder = store.getRoot().builder();
builder.child("testRoot5").setProperty("foo", "pqr");
builder.child("testRoot6").setProperty("bar", "pqr");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
async.run();
assertTrue(async.getIndexStats().isFailing());
//barIndex should be skipped
assertEquals(2, barIndexInfo.getSkippedCount());
//7. Lets reindex barIndex and ensure index is not misbehaving
provider.disableFailureMode();
builder = store.getRoot().builder();
builder.child("oak:index").child("barIndex").setProperty("reindex", true);
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
async.run();
//now barIndex should not be part of failing index
assertFalse(async.getCorruptIndexHandler().getFailingIndexData("async").containsKey("/oak:index/barIndex"));
}
Aggregations