use of org.apache.jackrabbit.oak.spi.commit.CommitInfo 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.CommitInfo in project jackrabbit-oak by apache.
the class DocumentNodeStoreStatsCollectorIT method failedMerge.
@Test
public void failedMerge() throws Exception {
CommitHook failingHook = new CommitHook() {
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
throw new CommitFailedException(CommitFailedException.MERGE, 0, "");
}
};
NodeBuilder nb1 = nodeStore.getRoot().builder();
nb1.child("a");
try {
nodeStore.merge(nb1, failingHook, CommitInfo.EMPTY);
fail();
} catch (CommitFailedException ignore) {
}
verify(statsCollector).failedMerge(anyInt(), anyLong(), eq(false), eq(false));
//Should be called once more with exclusive lock
verify(statsCollector).failedMerge(anyInt(), anyLong(), eq(false), eq(true));
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method nonBlockingReset.
// OAK-2620
@Test
public void nonBlockingReset() throws Exception {
final List<String> failure = Lists.newArrayList();
final AtomicReference<ReentrantReadWriteLock> mergeLock = new AtomicReference<ReentrantReadWriteLock>();
MemoryDocumentStore store = new MemoryDocumentStore() {
@Override
public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) {
for (Map.Entry<Key, Operation> entry : update.getChanges().entrySet()) {
if (entry.getKey().getName().equals(NodeDocument.COLLISIONS)) {
ReentrantReadWriteLock rwLock = mergeLock.get();
if (rwLock.getReadHoldCount() > 0 || rwLock.getWriteHoldCount() > 0) {
failure.add("Branch reset still holds merge lock");
break;
}
}
}
return super.findAndUpdate(collection, update);
}
};
DocumentNodeStore ds = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).getNodeStore();
// do not retry merges
ds.setMaxBackOffMillis(0);
DocumentNodeState root = ds.getRoot();
final DocumentNodeStoreBranch b = ds.createBranch(root);
// branch state is now Unmodified
assertTrue(b.getMergeLock() instanceof ReentrantReadWriteLock);
mergeLock.set((ReentrantReadWriteLock) b.getMergeLock());
NodeBuilder builder = root.builder();
builder.child("foo");
b.setRoot(builder.getNodeState());
// branch state is now InMemory
builder.child("bar");
b.setRoot(builder.getNodeState());
try {
b.merge(new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
NodeBuilder foo = after.builder().child("foo");
for (int i = 0; i <= DocumentMK.UPDATE_LIMIT; i++) {
foo.setProperty("prop", i);
}
throw new CommitFailedException("Fail", 0, "");
}
}, CommitInfo.EMPTY);
} catch (CommitFailedException e) {
// expected
}
for (String s : failure) {
fail(s);
}
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class ExternalChangesTest method changeSetForExternalChanges.
@Test
public void changeSetForExternalChanges() throws Exception {
NodeBuilder b1 = ns1.getRoot().builder();
b1.child("a");
b1.setProperty("foo1", "bar");
ns1.merge(b1, newCollectingHook(), newCommitInfo());
NodeBuilder b2 = ns1.getRoot().builder();
b2.child("b");
b2.setProperty("foo2", "bar");
ns1.merge(b2, newCollectingHook(), newCommitInfo());
ns1.runBackgroundUpdateOperations();
c2.reset();
ns2.runBackgroundReadOperations();
CommitInfo ci = c2.getExternalChange();
CommitContext cc = (CommitContext) ci.getInfo().get(CommitContext.NAME);
assertNotNull(cc);
ChangeSet cs = (ChangeSet) cc.get(ChangeCollectorProvider.COMMIT_CONTEXT_OBSERVATION_CHANGESET);
assertNotNull(cs);
assertFalse(cs.anyOverflow());
assertThat(cs.getPropertyNames(), containsInAnyOrder("foo1", "foo2"));
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class DocumentBundlingTest method recreatedBundledNode2.
@Test
public void recreatedBundledNode2() throws Exception {
NodeBuilder builder = store.getRoot().builder();
NodeBuilder fileNode = newNode("nt:file");
fileNode.child("jcr:content").setProperty("jcr:data", "foo");
builder.child("test").setChildNode("book.jpg", fileNode.getNodeState());
merge(builder);
builder = store.getRoot().builder();
builder.child("a");
//In this case we recreate the node in CommitHook
store.merge(builder, new EditorHook(new EditorProvider() {
@Override
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
return new BookRecreatingEditor(builder);
}
}), CommitInfo.EMPTY);
}
Aggregations