Search in sources :

Example 11 with AbstractDocumentNodeState

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

the class SecondaryStoreCache method findMatchingRoot.

static AbstractDocumentNodeState findMatchingRoot(AbstractDocumentNodeState[] roots, RevisionVector key) {
    int low = 0;
    int high = roots.length - 1;
    //Perform a binary search as the array is sorted in ascending order
    while (low <= high) {
        int mid = (low + high) >>> 1;
        AbstractDocumentNodeState midVal = roots[mid];
        int cmp = midVal.getRootRevision().compareTo(key);
        if (cmp < 0) {
            low = mid + 1;
        } else if (cmp > 0) {
            high = mid - 1;
        } else {
            // key found
            return midVal;
        }
    }
    // key not found.
    return null;
}
Also used : AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)

Example 12 with AbstractDocumentNodeState

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

the class SecondaryStoreCache method findMatchingRoot.

@CheckForNull
private AbstractDocumentNodeState findMatchingRoot(RevisionVector rr) {
    if (isEmpty()) {
        return null;
    }
    //Use a local variable as the array can get changed in process
    AbstractDocumentNodeState[] roots = previousRoots;
    AbstractDocumentNodeState latest = roots[roots.length - 1];
    AbstractDocumentNodeState oldest = roots[0];
    if (rr.compareTo(latest.getRootRevision()) > 0) {
        knownMissedNew.mark();
        return null;
    }
    if (rr.compareTo(oldest.getRootRevision()) < 0) {
        knownMissedOld.mark();
        return null;
    }
    AbstractDocumentNodeState result = findMatchingRoot(roots, rr);
    if (result != null) {
        return result;
    }
    knownMissedInRange.mark();
    return null;
}
Also used : AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) CheckForNull(javax.annotation.CheckForNull)

Example 13 with AbstractDocumentNodeState

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

the class SecondaryStoreCacheTest method updateAndReadAtReadRev.

@Test
public void updateAndReadAtReadRev() throws Exception {
    SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty));
    NodeBuilder nb = primary.getRoot().builder();
    create(nb, "/a/b", "/a/c", "/x/y/z");
    AbstractDocumentNodeState r1 = merge(nb);
    //Update some other part of tree i.e. which does not change lastRev for /a/c
    nb = primary.getRoot().builder();
    create(nb, "/a/e/d");
    AbstractDocumentNodeState r2 = merge(nb);
    //Lookup should work fine
    AbstractDocumentNodeState a_r2 = documentState(r2, "/a/c");
    AbstractDocumentNodeState result = cache.getDocumentNodeState("/a/c", r2.getRootRevision(), a_r2.getLastRevision());
    assertTrue(EqualsDiff.equals(a_r2, result));
    //Child docs should only have lastRev and not root rev
    assertTrue(result.hasProperty(DelegatingDocumentNodeState.PROP_LAST_REV));
    assertFalse(result.hasProperty(DelegatingDocumentNodeState.PROP_REVISION));
    //Root doc would have both meta props
    assertTrue(secondary.getRoot().hasProperty(DelegatingDocumentNodeState.PROP_LAST_REV));
    assertTrue(secondary.getRoot().hasProperty(DelegatingDocumentNodeState.PROP_REVISION));
    nb = primary.getRoot().builder();
    nb.child("a").child("c").remove();
    AbstractDocumentNodeState r3 = merge(nb);
    //Now look from older revision
    result = cache.getDocumentNodeState("/a/c", r3.getRootRevision(), a_r2.getLastRevision());
    //now as its not visible from head it would not be visible
    assertNull(result);
}
Also used : PathFilter(org.apache.jackrabbit.oak.plugins.index.PathFilter) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 14 with AbstractDocumentNodeState

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

the class SecondaryStoreCacheTest method updateAndReadAtPrevRevision.

@Test
public void updateAndReadAtPrevRevision() throws Exception {
    SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty));
    NodeBuilder nb = primary.getRoot().builder();
    create(nb, "/a/b", "/a/c");
    AbstractDocumentNodeState r0 = merge(nb);
    AbstractDocumentNodeState a_c_0 = documentState(primary.getRoot(), "/a/c");
    //Update some other part of tree i.e. which does not change lastRev for /a/c
    nb = primary.getRoot().builder();
    create(nb, "/a/c/d");
    AbstractDocumentNodeState r1 = merge(nb);
    AbstractDocumentNodeState a_c_1 = documentState(primary.getRoot(), "/a/c");
    AbstractDocumentNodeState result = cache.getDocumentNodeState("/a/c", r1.getRootRevision(), a_c_1.getLastRevision());
    assertTrue(EqualsDiff.equals(a_c_1, result));
    //Read from older revision
    result = cache.getDocumentNodeState("/a/c", r0.getRootRevision(), a_c_0.getLastRevision());
    assertTrue(EqualsDiff.equals(a_c_0, result));
}
Also used : PathFilter(org.apache.jackrabbit.oak.plugins.index.PathFilter) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 15 with AbstractDocumentNodeState

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

the class NodeCacheTest method testAsyncCache.

@Test
public void testAsyncCache() throws Exception {
    initializeNodeStore(true);
    ns.setNodeStateCache(new PathExcludingCache("/c"));
    NodeBuilder builder = ns.getRoot().builder();
    builder.child("a").child("b");
    builder.child("c").child("d");
    AbstractDocumentNodeState root = (AbstractDocumentNodeState) ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    PathRev prc = new PathRev("/c", root.getRootRevision());
    PathRev pra = new PathRev("/a", root.getRootRevision());
    Counting counter = nodeCache.getPersistentCacheStats().getPutRejectedAsCachedInSecCounter();
    long count0 = counter.getCount();
    //Adding this should be rejected
    nodeCache.evicted(prc, (DocumentNodeState) root.getChildNode("c"), RemovalCause.SIZE);
    long count1 = counter.getCount();
    assertTrue(count1 > count0);
    //Adding this should NOT be rejected
    nodeCache.evicted(pra, (DocumentNodeState) root.getChildNode("a"), RemovalCause.SIZE);
    long count2 = counter.getCount();
    assertEquals(count1, count2);
}
Also used : PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Counting(org.apache.jackrabbit.oak.stats.Counting) Test(org.junit.Test)

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