use of org.apache.jackrabbit.oak.spi.commit.Observer in project jackrabbit-oak by apache.
the class RepositoryFixture method configureLuceneProvider.
private void configureLuceneProvider(Oak oak) throws IOException {
LuceneIndexEditorProvider ep = new LuceneIndexEditorProvider();
LuceneIndexProvider provider = new LuceneIndexProvider();
oak.with((QueryIndexProvider) provider).with((Observer) provider).with(ep);
}
use of org.apache.jackrabbit.oak.spi.commit.Observer in project jackrabbit-oak by apache.
the class Oak method createNewContentRepository.
private ContentRepository createNewContentRepository() {
final RepoStateCheckHook repoStateCheckHook = new RepoStateCheckHook();
final List<Registration> regs = Lists.newArrayList();
regs.add(whiteboard.register(Executor.class, getExecutor(), Collections.emptyMap()));
IndexEditorProvider indexEditors = CompositeIndexEditorProvider.compose(indexEditorProviders);
OakInitializer.initialize(store, new CompositeInitializer(initializers), indexEditors);
QueryIndexProvider indexProvider = CompositeQueryIndexProvider.compose(queryIndexProviders);
commitHooks.add(repoStateCheckHook);
List<CommitHook> initHooks = new ArrayList<CommitHook>(commitHooks);
initHooks.add(new EditorHook(CompositeEditorProvider.compose(editorProviders)));
if (asyncTasks != null) {
IndexMBeanRegistration indexRegistration = new IndexMBeanRegistration(whiteboard);
regs.add(indexRegistration);
for (Entry<String, Long> t : asyncTasks.entrySet()) {
AsyncIndexUpdate task = new AsyncIndexUpdate(t.getKey(), store, indexEditors);
indexRegistration.registerAsyncIndexer(task, t.getValue());
closer.register(task);
}
PropertyIndexAsyncReindex asyncPI = new PropertyIndexAsyncReindex(new AsyncIndexUpdate(IndexConstants.ASYNC_REINDEX_VALUE, store, indexEditors, true), getExecutor());
regs.add(registerMBean(whiteboard, PropertyIndexAsyncReindexMBean.class, asyncPI, PropertyIndexAsyncReindexMBean.TYPE, "async"));
}
regs.add(registerMBean(whiteboard, NodeCounterMBean.class, new NodeCounter(store), NodeCounterMBean.TYPE, "nodeCounter"));
regs.add(registerMBean(whiteboard, QueryEngineSettingsMBean.class, queryEngineSettings, QueryEngineSettingsMBean.TYPE, "settings"));
// FIXME: OAK-810 move to proper workspace initialization
// initialize default workspace
Iterable<WorkspaceInitializer> workspaceInitializers = Iterables.transform(securityProvider.getConfigurations(), new Function<SecurityConfiguration, WorkspaceInitializer>() {
@Override
public WorkspaceInitializer apply(SecurityConfiguration sc) {
return sc.getWorkspaceInitializer();
}
});
OakInitializer.initialize(workspaceInitializers, store, defaultWorkspaceName, indexEditors);
// add index hooks later to prevent the OakInitializer to do excessive indexing
with(new IndexUpdateProvider(indexEditors, failOnMissingIndexProvider));
withEditorHook();
// Register observer last to prevent sending events while initialising
for (Observer observer : observers) {
regs.add(whiteboard.register(Observer.class, observer, emptyMap()));
}
RepositoryManager repositoryManager = new RepositoryManager(whiteboard);
regs.add(registerMBean(whiteboard, RepositoryManagementMBean.class, repositoryManager, RepositoryManagementMBean.TYPE, repositoryManager.getName()));
CommitHook composite = CompositeHook.compose(commitHooks);
regs.add(whiteboard.register(CommitHook.class, composite, Collections.emptyMap()));
final Tracker<Descriptors> t = whiteboard.track(Descriptors.class);
return new ContentRepositoryImpl(store, composite, defaultWorkspaceName, queryEngineSettings.unwrap(), indexProvider, securityProvider, new AggregatingDescriptors(t)) {
@Override
public void close() throws IOException {
super.close();
repoStateCheckHook.close();
new CompositeRegistration(regs).unregister();
closer.close();
}
};
}
use of org.apache.jackrabbit.oak.spi.commit.Observer in project jackrabbit-oak by apache.
the class CommitQueueTest method concurrentCommits.
@Test
public void concurrentCommits() throws Exception {
final DocumentNodeStore store = builderProvider.newBuilder().getNodeStore();
AtomicBoolean running = new AtomicBoolean(true);
Closeable observer = store.addObserver(new Observer() {
private RevisionVector before = new RevisionVector(new Revision(0, 0, store.getClusterId()));
@Override
public void contentChanged(@Nonnull NodeState root, @Nullable CommitInfo info) {
DocumentNodeState after = (DocumentNodeState) root;
RevisionVector r = after.getRootRevision();
LOG.debug("seen: {}", r);
if (r.compareTo(before) < 0) {
exceptions.add(new Exception("Inconsistent revision sequence. Before: " + before + ", after: " + r));
}
before = r;
}
});
// perform commits with multiple threads
List<Thread> writers = new ArrayList<Thread>();
for (int i = 0; i < NUM_WRITERS; i++) {
final Random random = new Random(i);
writers.add(new Thread(new Runnable() {
@Override
public void run() {
try {
for (int i = 0; i < COMMITS_PER_WRITER; i++) {
Commit commit = store.newCommit(null, null);
try {
Thread.sleep(0, random.nextInt(1000));
} catch (InterruptedException e) {
// ignore
}
if (random.nextInt(5) == 0) {
// cancel 20% of the commits
store.canceled(commit);
} else {
boolean isBranch = random.nextInt(5) == 0;
store.done(commit, isBranch, CommitInfo.EMPTY);
}
}
} catch (Exception e) {
exceptions.add(e);
}
}
}));
}
for (Thread t : writers) {
t.start();
}
for (Thread t : writers) {
t.join();
}
running.set(false);
observer.close();
store.dispose();
assertNoExceptions();
}
use of org.apache.jackrabbit.oak.spi.commit.Observer 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();
}
use of org.apache.jackrabbit.oak.spi.commit.Observer in project jackrabbit-oak by apache.
the class NodeStoreTest method afterCommitHook.
@Test
public void afterCommitHook() throws CommitFailedException, InterruptedException {
assumeTrue(store instanceof Observable);
final AtomicReference<NodeState> observedRoot = new AtomicReference<NodeState>(null);
final CountDownLatch latch = new CountDownLatch(2);
((Observable) store).addObserver(new Observer() {
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
if (root.getChildNode("test").hasChildNode("newNode")) {
observedRoot.set(checkNotNull(root));
latch.countDown();
}
}
});
NodeState root = store.getRoot();
NodeBuilder rootBuilder = root.builder();
NodeBuilder testBuilder = rootBuilder.child("test");
NodeBuilder newNodeBuilder = testBuilder.child("newNode");
newNodeBuilder.setProperty("n", 42);
testBuilder.getChildNode("a").remove();
store.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
// triggers the observer
NodeState newRoot = store.getRoot();
latch.await(2, TimeUnit.SECONDS);
NodeState after = observedRoot.get();
assertNotNull(after);
assertTrue(after.getChildNode("test").getChildNode("newNode").exists());
assertFalse(after.getChildNode("test").getChildNode("a").exists());
assertEquals(42, (long) after.getChildNode("test").getChildNode("newNode").getProperty("n").getValue(LONG));
assertEquals(newRoot, after);
}
Aggregations