use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class SecureNodeBuilderTest method before.
@Before
public void before() throws Exception {
NodeBuilder rootBuilder = store.getRoot().builder();
rootBuilder.setProperty("prop", "value").setProperty(NAME_NON_ACCESSIBLE, "value");
rootBuilder.child(NAME_ACCESSIBLE).setProperty("prop", "value").setProperty(NAME_NON_ACCESSIBLE, "value");
rootBuilder.child(NAME_NON_ACCESSIBLE).setProperty("prop", "value").setProperty(NAME_NON_ACCESSIBLE, "value");
store.merge(rootBuilder, new EmptyHook(), new CommitInfo("id", null));
rootBuilder = store.getRoot().builder();
secureNodeBuilder = new SecureNodeBuilder(rootBuilder, new LazyValue<PermissionProvider>() {
@Override
protected PermissionProvider createValue() {
return permissionProvider;
}
});
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class ClusterConflictTest method mergeRetryWhileBackgroundRead.
// OAK-3433
@Test
public void mergeRetryWhileBackgroundRead() throws Exception {
DocumentNodeStore ns1 = mk.getNodeStore();
NodeBuilder b1 = ns1.getRoot().builder();
b1.child("a").child("b").child("c").child("foo");
merge(ns1, b1);
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
NodeBuilder b2 = ns2.getRoot().builder();
// force cache fill
assertNodeExists(b2, "/a/b/c/foo");
// remove /a/b/c on ns1
b1 = ns1.getRoot().builder();
b1.child("a").child("b").child("c").remove();
merge(ns1, b1);
// perform some change on ns2
b2.child("z");
merge(ns2, b2);
runBackgroundUpdate(ns2);
// this will pickup changes done by ns2 and update
// the head revision
runBackgroundRead(ns1);
// the next step is where the issue described
// in OAK-3433 occurs.
// the journal entry with changes done on ns1 is pushed
// with the current head revision, which is newer
// than the most recent change in the journal entry
runBackgroundUpdate(ns1);
// perform a background read after the rebase
// the first merge attempt will fail with a conflict
// because /a/b/c is seen as changed in the future
// without the fix for OAK-3433:
// the second merge attempt succeeds because now the
// /a/b/c change revision is visible and happened before the commit
// revision but before the base revision
b2 = ns2.getRoot().builder();
b2.child("z").setProperty("q", "v");
try {
ns2.merge(b2, new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
runBackgroundRead(ns2);
NodeBuilder builder = after.builder();
if (builder.getChildNode("a").getChildNode("b").hasChildNode("c")) {
builder.child("a").child("b").child("c").child("bar");
} else {
throw new CommitFailedException(CommitFailedException.OAK, 0, "/a/b/c does not exist anymore");
}
return builder.getNodeState();
}
}, CommitInfo.EMPTY);
fail("Merge must fail with CommitFailedException");
} catch (CommitFailedException e) {
// expected
}
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class ClusterTest method fromExternalChange.
@Test
public void fromExternalChange() throws Exception {
final List<DocumentNodeState> rootStates1 = Lists.newArrayList();
DocumentNodeStore ns1 = createMK(1, 0).getNodeStore();
ns1.addObserver(new Observer() {
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
rootStates1.add((DocumentNodeState) root);
}
});
final List<DocumentNodeState> rootStates2 = Lists.newArrayList();
DocumentNodeStore ns2 = createMK(2, 0).getNodeStore();
ns2.addObserver(new Observer() {
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
rootStates2.add((DocumentNodeState) root);
}
});
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
rootStates1.clear();
rootStates2.clear();
NodeBuilder builder = ns1.getRoot().builder();
builder.child("foo");
merge(ns1, builder);
assertEquals(1, rootStates1.size());
assertEquals(0, rootStates2.size());
assertFalse(rootStates1.get(0).isFromExternalChange());
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
assertEquals(1, rootStates1.size());
assertEquals(1, rootStates2.size());
assertTrue(rootStates2.get(0).isFromExternalChange());
NodeState foo = rootStates2.get(0).getChildNode("foo");
assertTrue(foo instanceof DocumentNodeState);
assertTrue(((DocumentNodeState) foo).isFromExternalChange());
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class OakTest method commitContextInCommitInfo.
@Test
public void commitContextInCommitInfo() throws Exception {
CommitInfoCapturingStore store = new CommitInfoCapturingStore();
Oak oak = new Oak(store);
ContentRepository repo = oak.with(new OpenSecurityProvider()).createContentRepository();
assertThat(store.infos, is(not(empty())));
for (CommitInfo ci : store.infos) {
assertNotNull(ci.getInfo().get(CommitContext.NAME));
}
((Closeable) repo).close();
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class NodeStoreDiffTest method testDiff.
/**
* This testcase demonstrates that diff logic in merge part traverses node path
* which are not affected by the commit
* @throws Exception
*/
@Test
public void testDiff() throws Exception {
createNodes("/oak:index/prop-a", "/oak:index/prop-b", "/etc/workflow");
//1. Make some other changes so as to bump root rev=3
createNodes("/fake/a");
createNodes("/fake/b");
//2 - Start change
NodeBuilder b2 = ns.getRoot().builder();
createNodes(b2, "/etc/workflow/instance1");
tds.reset();
//3. Merge which does a rebase
ns.merge(b2, new CommitHook() {
@Nonnull
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
NodeBuilder rb = after.builder();
createNodes(rb, "/oak:index/prop-a/a1");
//2.1 Commit some change under prop-
//This cause diff in lastRev of base node state in ModifiedNodeState for
//oak:index due to which when the base state is compared in ModifiedNodeState
//then it fetches the new DocumentNodeState whose lastRev is greater than this.base.lastRev
//but less then lastRev of the of readRevision. Where readRevision is the rev of root node when
//rebase was performed
// remember paths accessed so far
List<String> paths = Lists.newArrayList(tds.paths);
//This is not to be done in actual cases as CommitHooks are invoked in critical sections
//and creating nodes from within CommitHooks would cause deadlock. This is done here to ensure
//that changes are done when rebase has been performed and merge is about to happen
createNodes("/oak:index/prop-b/b1");
// reset accessed paths
tds.reset();
tds.paths.addAll(paths);
return rb.getNodeState();
}
}, CommitInfo.EMPTY);
//Assert that diff logic does not traverse to /oak:index/prop-b/b1 as
//its not part of commit
assertFalse(tds.paths.contains("/oak:index/prop-b/b1"));
}
Aggregations