Search in sources :

Example 71 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class CacheConsistencyRDBTest method cacheConsistency.

@Test
public void cacheConsistency() throws Exception {
    mk.commit("/", "+\"node\":{}", null, null);
    // add a child node. this will require an update
    // of _lastRev on /node
    mk.commit("/node", "+\"child\":{}", null, null);
    // make sure the document is not cached
    store.invalidateNodeDocument(Utils.getIdFromPath("/node"));
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            store.query(NODES, Utils.getKeyLowerLimit("/"), Utils.getKeyUpperLimit("/"), 10);
        }
    }, "query");
    // block thread when it tries to convert db objects
    store.semaphores.put(t, new Semaphore(0));
    t.start();
    while (!store.semaphores.get(t).hasQueuedThreads()) {
        Thread.sleep(10);
    }
    final Semaphore done = new Semaphore(0);
    new Thread(new Runnable() {

        @Override
        public void run() {
            // trigger write back of _lastRevs
            mk.runBackgroundOperations();
            done.release();
        }
    }, "mkbg").start();
    // wait at most one second for background thread
    done.tryAcquire(1, TimeUnit.SECONDS);
    store.invalidateNodeDocument(Utils.getIdFromPath("/node"));
    // release thread
    store.semaphores.get(t).release();
    t.join();
    NodeState root = mk.getNodeStore().getRoot();
    assertTrue(root.getChildNode("node").getChildNode("child").exists());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Example 72 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class CacheInvalidationIT method testCacheInvalidationHierarchicalNotExist.

@Test
public void testCacheInvalidationHierarchicalNotExist() throws CommitFailedException {
    NodeBuilder b2 = getRoot(c2).builder();
    // we create x/other, so that x is known to have a child node
    b2.child("x").child("other");
    b2.child("y");
    c2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    c2.runBackgroundOperations();
    c1.runBackgroundOperations();
    // we check for the existence of "x/futureX", which
    // should create a negative entry in the cache
    NodeState x = getRoot(c1).getChildNode("x");
    assertTrue(x.exists());
    assertFalse(x.getChildNode("futureX").exists());
    // we don't check for the existence of "y/futureY"
    NodeState y = getRoot(c1).getChildNode("y");
    assertTrue(y.exists());
    // now we add both "futureX" and "futureY"
    // in the other cluster node
    b2.child("x").child("futureX").setProperty("z", "1");
    c2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    b2.child("y").child("futureY").setProperty("z", "2");
    c2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    c2.runBackgroundOperations();
    c1.runBackgroundOperations();
    // both nodes should now be visible
    assertTrue(getRoot(c1).getChildNode("y").getChildNode("futureY").exists());
    assertTrue(getRoot(c1).getChildNode("x").getChildNode("futureX").exists());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test) AbstractMongoConnectionTest(org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)

Example 73 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState 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
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) AbstractMongoConnectionTest(org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)

Example 74 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class DocumentBundlingTest method jsonSerialization.

@Test
public void jsonSerialization() throws Exception {
    NodeBuilder builder = store.getRoot().builder();
    NodeBuilder appNB = newNode("app:Asset");
    createChild(appNB, "jcr:content", //not bundled
    "jcr:content/comments", "jcr:content/metadata", //not bundled
    "jcr:content/metadata/xmp", //includes all
    "jcr:content/renditions", "jcr:content/renditions/original", "jcr:content/renditions/original/jcr:content");
    builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
    merge(builder);
    DocumentNodeState appNode = (DocumentNodeState) getNode(store.getRoot(), "test/book.jpg");
    String json = appNode.asString();
    NodeState appNode2 = DocumentNodeState.fromString(store, json);
    AssertingDiff.assertEquals(appNode, appNode2);
}
Also used : DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractNodeState(org.apache.jackrabbit.oak.spi.state.AbstractNodeState) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 75 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class BundlorConflictTest method setUpBundlor.

@Before
public void setUpBundlor() throws CommitFailedException {
    store1 = builderProvider.newBuilder().setDocumentStore(ds).memoryCacheSize(0).setClusterId(1).setAsyncDelay(0).getNodeStore();
    store2 = builderProvider.newBuilder().setDocumentStore(ds).memoryCacheSize(0).setClusterId(2).setAsyncDelay(0).getNodeStore();
    NodeBuilder builder = store1.getRoot().builder();
    NodeBuilder prevState = builder.child("oldState");
    //Old state nt:file
    createFile(prevState, "file");
    //Old state app:Asset
    createAsset(prevState, "assset");
    merge(store1, builder);
    NodeState registryState = BundledTypesRegistry.builder().forType("nt:file", "jcr:content").registry().forType("app:Asset").include("jcr:content").include("jcr:content/metadata").include("jcr:content/renditions").include("jcr:content/renditions/**").build();
    builder = store1.getRoot().builder();
    builder.child("jcr:system").child("documentstore").setChildNode("bundlor", registryState);
    merge(store1, builder);
    syncStores();
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Before(org.junit.Before)

Aggregations

NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)580 Test (org.junit.Test)375 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)254 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)69 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)46 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)45 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)43 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)39 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)36 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)33 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)32 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)29 Nonnull (javax.annotation.Nonnull)28 Tree (org.apache.jackrabbit.oak.api.Tree)23 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState)23 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)19 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)18 ArrayList (java.util.ArrayList)17 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)16 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)15