use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method testAsyncExecutionStats.
@Test
public void testAsyncExecutionStats() throws Exception {
final Set<String> knownCheckpoints = Sets.newHashSet();
MemoryNodeStore store = new MemoryNodeStore() {
@Override
public synchronized NodeState retrieve(@Nonnull String checkpoint) {
if (!knownCheckpoints.isEmpty() && !knownCheckpoints.contains(checkpoint)) {
return null;
}
return super.retrieve(checkpoint);
}
};
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");
// merge it back in
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider, statsProvider, false);
runOneCycle(async);
assertEquals(1, async.getIndexStats().getExecutionStats().getExecutionCounter().getCount());
//Run a cycle so that change of reindex flag gets indexed
runOneCycle(async);
assertEquals(2, async.getIndexStats().getExecutionStats().getExecutionCounter().getCount());
long indexedNodeCount = async.getIndexStats().getExecutionStats().getIndexedNodeCount().getCount();
//Now run so that it results in an empty cycle
runOneCycle(async);
assertEquals(indexedNodeCount, async.getIndexStats().getExecutionStats().getIndexedNodeCount().getCount());
//Do some updates and counter should increase
builder = store.getRoot().builder();
builder.child("testRoot2").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
runOneCycle(async);
assertEquals(4, async.getIndexStats().getExecutionStats().getExecutionCounter().getCount());
//Do some updates but disable checkpoints. Counter should not increase
builder = store.getRoot().builder();
builder.child("testRoot3").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
//Disable new checkpoint retrieval
knownCheckpoints.addAll(store.listCheckpoints());
runOneCycle(async);
assertEquals(0, lastExecutionStats(async.getIndexStats().getExecutionCount()));
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method cpCleanupWChanges.
@Test
public void cpCleanupWChanges() 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);
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);
async.run();
assertTrue("Expecting one checkpoint", store.listCheckpoints().size() == 1);
String secondCp = store.listCheckpoints().iterator().next();
assertFalse("Store should keep only second checkpoint", secondCp.equals(firstCp));
assertEquals(secondCp, store.getRoot().getChildNode(ASYNC).getString("async"));
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method checkpointStability.
@Test
public void checkpointStability() 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);
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
//Initial indexing
async.run();
//Now checkpoints = [checkpoints0]
//Index again so as to get change in reindex flag done
async.run();
//Now checkpoints = [checkpoints1]. checkpoints0 released
//Now make some changes to
builder = store.getRoot().builder();
builder.child("testRoot2").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
async.run();
//Now checkpoints = [checkpoints1]. Note that size is 1 so new checkpoint name remains same
LogCustomizer customLogs = LogCustomizer.forLogger(AsyncIndexUpdate.class.getName()).filter(Level.WARN).create();
builder = store.getRoot().builder();
builder.child("testRoot3").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
customLogs.starting();
async.run();
assertEquals(Collections.emptyList(), customLogs.getLogs());
customLogs.finished();
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method branchBaseOnCheckpoint.
// OAK-1749
@Test
public void branchBaseOnCheckpoint() throws Exception {
final Semaphore retrieve = new Semaphore(1);
final Semaphore checkpoint = new Semaphore(0);
NodeStore store = new MemoryNodeStore() {
@CheckForNull
@Override
public NodeState retrieve(@Nonnull String checkpoint) {
retrieve.acquireUninterruptibly();
try {
return super.retrieve(checkpoint);
} finally {
retrieve.release();
}
}
@Nonnull
@Override
public String checkpoint(long lifetime, @Nonnull Map<String, String> properties) {
try {
return super.checkpoint(lifetime, properties);
} finally {
checkpoint.release();
}
}
};
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", false, ImmutableSet.of("foo"), null, TYPE, Collections.singletonMap(ASYNC_PROPERTY_NAME, "async"));
builder.child("test").setProperty("foo", "a");
builder.child("child");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
final AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
async.run();
builder = store.getRoot().builder();
builder.child("test").setProperty("foo", "b");
builder.child("child").setProperty("prop", "value");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
async.run();
}
});
// drain checkpoint permits
checkpoint.acquireUninterruptibly(checkpoint.availablePermits());
// block NodeStore.retrieve()
retrieve.acquireUninterruptibly();
t.start();
// wait until async update called checkpoint
retrieve.release();
checkpoint.acquireUninterruptibly();
builder = store.getRoot().builder();
builder.child("child").remove();
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
// allow async update to proceed with NodeStore.retrieve()
retrieve.release();
t.join();
assertFalse(store.getRoot().hasChildNode("child"));
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method taskSplit.
@Test
public void taskSplit() 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), "changedIndex", true, false, ImmutableSet.of("bar"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "ignored1", true, false, ImmutableSet.of("baz"), null).setProperty(ASYNC_PROPERTY_NAME, "async-ignored");
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "ignored2", true, false, ImmutableSet.of("etc"), null);
builder.child("testRoot").setProperty("foo", "abc");
builder.child("testRoot").setProperty("bar", "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");
builder.child("testRoot").setProperty("bar", "def");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
IndexTaskSpliter splitter = async.getTaskSplitter();
splitter.registerSplit(newHashSet("/oak:index/changedIndex"), "async-slow");
async.run();
Set<String> checkpoints = newHashSet(store.listCheckpoints());
assertTrue("Expecting two checkpoints", checkpoints.size() == 2);
assertTrue(checkpoints.remove(firstCp));
String secondCp = checkpoints.iterator().next();
NodeState asyncNode = store.getRoot().getChildNode(ASYNC);
assertEquals(firstCp, asyncNode.getString("async-slow"));
assertEquals(secondCp, asyncNode.getString("async"));
assertFalse(newHashSet(asyncNode.getStrings("async-temp")).contains(firstCp));
NodeState indexNode = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME);
assertEquals("async", indexNode.getChildNode("rootIndex").getString("async"));
assertEquals("async-ignored", indexNode.getChildNode("ignored1").getString("async"));
assertNull(indexNode.getChildNode("ignored2").getString("async"));
assertEquals("async-slow", indexNode.getChildNode("changedIndex").getString("async"));
assertEquals(false, indexNode.getChildNode("changedIndex").getBoolean("reindex"));
// new index task is on previous checkpoint
PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
assertEquals(ImmutableSet.of("testRoot"), find(lookup, "bar", "abc"));
assertEquals(ImmutableSet.of(), find(lookup, "bar", "def"));
}
Aggregations