use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method failOnConflict.
// OAK-1784
@Test
public void failOnConflict() throws Exception {
final Map<Thread, Semaphore> locks = Maps.newIdentityHashMap();
NodeStore store = new MemoryNodeStore() {
@Nonnull
@Override
public NodeState merge(@Nonnull NodeBuilder builder, @Nonnull CommitHook commitHook, @Nonnull CommitInfo info) throws CommitFailedException {
Semaphore s = locks.get(Thread.currentThread());
if (s != null) {
s.acquireUninterruptibly();
}
return super.merge(builder, commitHook, info);
}
};
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");
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");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
async.run();
}
});
Semaphore s = new Semaphore(0);
locks.put(t, s);
t.start();
// make some unrelated changes to trigger indexing
builder = store.getRoot().builder();
builder.setChildNode("dummy").setProperty("foo", "bar");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
while (!s.hasQueuedThreads()) {
Thread.yield();
}
// introduce a conflict
builder = store.getRoot().builder();
builder.getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("foo").getChildNode(":index").child("a").remove();
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
s.release(100);
t.join();
builder = store.getRoot().builder();
assertNoConflictMarker(builder);
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider 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.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method validatorProviderInvocation.
@Test
public void validatorProviderInvocation() 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");
// merge it back in
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
CollectingValidatorProvider v = new CollectingValidatorProvider();
async.setValidatorProviders(ImmutableList.<ValidatorProvider>of(v));
async.run();
assertFalse(v.visitedPaths.isEmpty());
assertThat(v.visitedPaths, hasItem("/:async"));
assertThat(v.visitedPaths, hasItem("/oak:index/rootIndex"));
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.
the class AsyncIndexerServiceTest method changeCollectionEnabled.
@Test
public void changeCollectionEnabled() throws Exception {
injectDefaultServices();
Map<String, Object> config = ImmutableMap.<String, Object>of("asyncConfigs", new String[] { "async:5" });
context.registerService(IndexEditorProvider.class, new PropertyIndexEditorProvider());
MockOsgi.activate(service, context.bundleContext(), config);
NodeBuilder builder = nodeStore.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
nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
CommitInfoCollector infoCollector = new CommitInfoCollector();
nodeStore.addObserver(infoCollector);
AsyncIndexUpdate indexUpdate = getIndexUpdate("async");
indexUpdate.run();
CommitContext commitContext = (CommitContext) infoCollector.infos.get(0).getInfo().get(CommitContext.NAME);
assertNotNull(commitContext);
ChangeSet changeSet = (ChangeSet) commitContext.get(ChangeCollectorProvider.COMMIT_CONTEXT_OBSERVATION_CHANGESET);
assertNotNull(changeSet);
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider in project jackrabbit-oak by apache.
the class NodeTypeIndexTest method nodeType.
@Test
public void nodeType() throws Exception {
NodeBuilder root = store.getRoot().builder();
// remove "rep:security" as it interferes with tests
root.getChildNode("rep:security").remove();
// set "entryCount", so the node type index counts the nodes
// and the approximation is not used
root.getChildNode("oak:index").getChildNode("nodetype").setProperty("entryCount", -1);
addFolder(root, "folder-1");
addFolder(root, "folder-2");
addFile(root, "file-1");
store.merge(root, new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider())), CommitInfo.EMPTY);
NodeState rootState = store.getRoot();
NodeTypeIndex index = new NodeTypeIndex(Mounts.defaultMountInfoProvider());
FilterImpl filter;
filter = createFilter(rootState, JcrConstants.NT_FOLDER);
assertEquals(6.0, index.getCost(filter, rootState), 0.0);
checkCursor(index.query(filter, rootState), "/folder-1", "/folder-2");
filter = createFilter(rootState, JcrConstants.NT_FILE);
assertEquals(5.0, index.getCost(filter, rootState), 0.0);
checkCursor(index.query(filter, rootState), "/file-1");
filter = createFilter(rootState, JcrConstants.NT_HIERARCHYNODE);
assertEquals(7.0, index.getCost(filter, rootState), 0.0);
checkCursor(index.query(filter, rootState), "/folder-1", "/folder-2", "/file-1");
}
Aggregations