Search in sources :

Example 6 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class SecondaryStoreCacheTest method binarySearch.

@Test
public void binarySearch() throws Exception {
    SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty));
    List<AbstractDocumentNodeState> roots = Lists.newArrayList();
    List<RevisionVector> revs = Lists.newArrayList();
    for (int i = 0; i < 50; i++) {
        NodeBuilder nb = primary.getRoot().builder();
        create(nb, "/a/b" + i);
        AbstractDocumentNodeState r = merge(nb);
        roots.add(r);
        revs.add(r.getRootRevision());
    }
    AbstractDocumentNodeState[] rootsArr = Iterables.toArray(roots, AbstractDocumentNodeState.class);
    Collections.shuffle(revs);
    for (RevisionVector rev : revs) {
        AbstractDocumentNodeState result = SecondaryStoreCache.findMatchingRoot(rootsArr, rev);
        assertNotNull(result);
        assertEquals(rev, result.getRootRevision());
    }
    NodeBuilder nb = primary.getRoot().builder();
    create(nb, "/a/m");
    AbstractDocumentNodeState r = merge(nb);
    AbstractDocumentNodeState result = SecondaryStoreCache.findMatchingRoot(rootsArr, r.getRootRevision());
    assertNull(result);
}
Also used : PathFilter(org.apache.jackrabbit.oak.plugins.index.PathFilter) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 7 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class DelegatingDocumentNodeStateTest method basicWorking.

@Test
public void basicWorking() throws Exception {
    RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
    RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
    builder.setProperty(asPropertyState(PROP_REVISION, rv1));
    builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
    AbstractDocumentNodeState state = DelegatingDocumentNodeState.wrap(builder.getNodeState(), NodeStateDiffer.DEFAULT_DIFFER);
    assertEquals(rv1, state.getRootRevision());
    assertEquals(rv2, state.getLastRevision());
    assertTrue(state.hasNoChildren());
    assertTrue(state.exists());
    assertFalse(state.isFromExternalChange());
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Test(org.junit.Test)

Example 8 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class DelegatingDocumentNodeStateTest method withRootRevision.

@Test
public void withRootRevision() throws Exception {
    RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
    RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
    builder.setProperty(asPropertyState(PROP_REVISION, rv1));
    builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
    AbstractDocumentNodeState state = DelegatingDocumentNodeState.wrap(builder.getNodeState(), NodeStateDiffer.DEFAULT_DIFFER);
    AbstractDocumentNodeState state2 = state.withRootRevision(rv1, false);
    assertSame(state, state2);
    RevisionVector rv4 = new RevisionVector(new Revision(1, 0, 4));
    AbstractDocumentNodeState state3 = state.withRootRevision(rv4, true);
    assertEquals(rv4, state3.getRootRevision());
    assertTrue(state3.isFromExternalChange());
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Test(org.junit.Test)

Example 9 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class BundledDocumentDiffer method getDocumentNodeState.

private DocumentNodeState getDocumentNodeState(AbstractDocumentNodeState state) {
    DocumentNodeState result;
    if (state instanceof DocumentNodeState) {
        result = (DocumentNodeState) state;
    } else if (BundlorUtils.isBundledChild(state)) {
        //In case of bundle child determine the bundling root
        //and from there traverse down to the actual child node
        checkState(BundlorUtils.isBundledChild(state));
        String bundlingPath = state.getString(DocumentBundlor.META_PROP_BUNDLING_PATH);
        String bundlingRootPath = PathUtils.getAncestorPath(state.getPath(), PathUtils.getDepth(bundlingPath));
        DocumentNodeState bundlingRoot = nodeStore.getNode(bundlingRootPath, state.getLastRevision());
        result = (DocumentNodeState) NodeStateUtils.getNode(bundlingRoot, bundlingPath);
    } else {
        result = nodeStore.getNode(state.getPath(), state.getLastRevision());
    }
    checkNotNull(result, "Node at [%s] not found for fromRev [%s]", state.getPath(), state.getLastRevision());
    return result;
}
Also used : DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)

Example 10 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class BundledDocumentDiffer method diff.

/**
     * Performs diff for bundled nodes. The passed state can be DocumentNodeState or
     * one from secondary nodestore i.e. {@code DelegatingDocumentNodeState}. So the
     * passed states cannot be cast down to DocumentNodeState
     *
     * @param from from state
     * @param to to state
     * @param w jsop diff
     * @return true if the diff needs to be continued. In case diff is complete it would return false
     */
public boolean diff(AbstractDocumentNodeState from, AbstractDocumentNodeState to, JsopWriter w) {
    boolean fromBundled = BundlorUtils.isBundledNode(from);
    boolean toBundled = BundlorUtils.isBundledNode(to);
    //Neither of the nodes bundled
    if (!fromBundled && !toBundled) {
        return true;
    }
    DocumentNodeState fromDocState = getDocumentNodeState(from);
    DocumentNodeState toDocState = getDocumentNodeState(to);
    diffChildren(fromDocState.getBundledChildNodeNames(), toDocState.getBundledChildNodeNames(), w);
    //If all child nodes are bundled then diff is complete
    if (fromDocState.hasOnlyBundledChildren() && toDocState.hasOnlyBundledChildren()) {
        return false;
    }
    return true;
}
Also used : DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)

Aggregations

AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)18 Test (org.junit.Test)9 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)8 PathFilter (org.apache.jackrabbit.oak.plugins.index.PathFilter)6 CheckForNull (javax.annotation.CheckForNull)3 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)2 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)2 Stopwatch (com.google.common.base.Stopwatch)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)1 ApplyDiff (org.apache.jackrabbit.oak.spi.state.ApplyDiff)1 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)1 Counting (org.apache.jackrabbit.oak.stats.Counting)1 TimerStats (org.apache.jackrabbit.oak.stats.TimerStats)1