use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore 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.memory.MemoryNodeStore 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.memory.MemoryNodeStore 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.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class SecondaryStoreObserverTest method setUp.
@Before
public void setUp() throws IOException {
primary = builderProvider.newBuilder().getNodeStore();
secondary = new MemoryNodeStore();
}
use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.
the class AsyncPropertyIndexTest method testAsyncPropertyLookup.
@Test
public void testAsyncPropertyLookup() throws Exception {
NodeStore store = new MemoryNodeStore();
assertTrue(Iterables.isEmpty(store.checkpoints()));
NodeBuilder builder = store.getRoot().builder();
//add a property index on 'foo'
NodeBuilder def = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, of("foo"), null);
def.setProperty(REINDEX_ASYNC_PROPERTY_NAME, true);
// add some content
builder.child("a").setProperty("foo", "abc");
builder.child("b").setProperty("foo", Arrays.asList("abc", "def"), STRINGS);
NodeState head = store.merge(builder, hook, EMPTY);
// query the index, check it doesn't get indexed by the normal PI
FilterImpl f = createFilter(head, NT_BASE);
PropertyIndexLookup lookup = new PropertyIndexLookup(head);
try {
assertEquals(of(), find(lookup, "foo", "abc", f));
fail();
} catch (IllegalArgumentException e) {
// expected: no index for "foo"
}
// run async first time, there are some changes
AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true);
async.run();
assertEquals(ASYNC_REINDEX_VALUE, store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("foo").getString(ASYNC_PROPERTY_NAME));
// run async second time, there are no changes, should switch to sync
async.run();
async.close();
assertEquals(null, store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("foo").getString(ASYNC_PROPERTY_NAME));
assertTrue(Iterables.isEmpty(store.checkpoints()));
// add content, it should be indexed synchronously
builder = store.getRoot().builder();
builder.child("c").setProperty("foo", "def");
head = store.merge(builder, hook, EMPTY);
f = createFilter(head, NT_BASE);
lookup = new PropertyIndexLookup(head);
assertEquals(ImmutableSet.of("b", "c"), find(lookup, "foo", "def", f));
}
Aggregations