use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method cpCleanupWErrors.
@Test
public void cpCleanupWErrors() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
FaultyIndexEditorProvder provider = new FaultyIndexEditorProvder();
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);
assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
async.run();
assertTrue("Error should have been triggered by the commit", provider.isFailed());
assertTrue("Expecting no checkpoints", store.listCheckpoints().size() == 0);
// OAK-3054 failure reports
AsyncIndexStats stats = async.getIndexStats();
String since = stats.getFailingSince();
assertTrue(stats.isFailing());
assertEquals(1, stats.getConsecutiveFailedExecutions());
assertEquals(since, stats.getLatestErrorTime());
TimeUnit.MILLISECONDS.sleep(100);
async.run();
assertTrue(stats.isFailing());
assertEquals(2, stats.getConsecutiveFailedExecutions());
assertEquals(since, stats.getFailingSince());
assertNotEquals(since, stats.getLatestErrorTime());
stats.fixed();
assertFalse(stats.isFailing());
assertEquals(0, stats.getConsecutiveFailedExecutions());
assertEquals("", stats.getFailingSince());
}
use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method traversalCount.
@Test
public void traversalCount() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
PropertyIndexEditorProvider 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 async = new AsyncIndexUpdate("async", store, provider);
async.run();
// Get rid of changes in index nodes i.e. /oak:index/rootIndex
async.run();
// Do a run without any index property change
builder = store.getRoot().builder();
builder.child("a").child("b");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
async.run();
AsyncIndexStats stats = async.getIndexStats();
assertEquals(3, stats.getNodesReadCount());
assertEquals(0, stats.getUpdates());
// Do a run with a index property change
builder = store.getRoot().builder();
builder.child("a").child("b").setProperty("foo", "bar");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
async.run();
stats = async.getIndexStats();
assertEquals(3, stats.getNodesReadCount());
assertEquals(1, stats.getUpdates());
}
use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats 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.index.AsyncIndexUpdate.AsyncIndexStats in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method closeWithHardLimit.
@Test
public void closeWithHardLimit() 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);
}
};
// Set a 1 sec close timeout
async.setCloseTimeOut(1);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
async.run();
}
});
Thread closer = new Thread(new Runnable() {
@Override
public void run() {
async.close();
}
});
// Lock to ensure that AsyncIndexUpdate waits
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 stopFlag is set
while (!async.isClosed()) ;
assertLogPhrase(lc.getLogs(), "[SOFT LIMIT HIT]");
// Let indexing run complete now
asyncLock.release();
// Wait for both threads
t.join();
// Async run would have exited with log message logged
assertLogPhrase(lc.getLogs(), "The index update interrupted");
// Wait for close call to complete
closer.join();
lc.finished();
}
use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method checkpointLostEventualConsistent.
@Test
public void checkpointLostEventualConsistent() throws Exception {
MemoryNodeStore store = new MemoryNodeStore();
final List<NodeState> rootStates = Lists.newArrayList();
store.addObserver(new Observer() {
@Override
public void contentChanged(@Nonnull NodeState root, @Nullable CommitInfo info) {
rootStates.add(root);
}
});
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();
// Create another commit so that we have two checkpoints
builder = store.getRoot().builder();
builder.child("testRoot2").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
pre.run();
pre.close();
// Look for the nodestate just before the final merge in AsyncIndexUpdate
// i.e. where older checkpoint was still referred and which has been "released"
// post last run
Collections.reverse(rootStates);
final AtomicReference<NodeState> oldRootState = new AtomicReference<NodeState>();
for (NodeState ns : rootStates) {
NodeState async = ns.getChildNode(ASYNC);
String checkpointName = async.getString("async");
if (store.retrieve(checkpointName) == null && async.getProperty(AsyncIndexUpdate.leasify("async")) == null) {
oldRootState.set(ns);
break;
}
}
assertNotNull(oldRootState.get());
final AtomicBoolean intiLeaseCalled = new AtomicBoolean(false);
// Here for the call to read existing NodeState we would return the old
// "stale" state where we have a stale checkpoint
store = new MemoryNodeStore(store.getRoot()) {
@Override
public NodeState getRoot() {
// Keep returning stale view untill initlease is not invoked
if (!intiLeaseCalled.get()) {
return oldRootState.get();
}
return super.getRoot();
}
};
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 {
intiLeaseCalled.set(true);
super.initLease();
}
};
}
};
async.run();
// This run should fail
assertTrue(async.getIndexStats().isFailing());
async.close();
}
Aggregations