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;
}
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;
}
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);
}
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));
}
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);
}
Aggregations