use of org.apache.jackrabbit.oak.spi.filter.PathFilter in project jackrabbit-oak by apache.
the class SecondaryStoreCacheTest method basicTest.
@Test
public void basicTest() throws Exception {
SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty));
NodeBuilder nb = primary.getRoot().builder();
create(nb, "/a/b", "/a/c", "/x/y/z");
merge(nb);
RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
assertNull(cache.getDocumentNodeState("/a/b", rv1, rv2));
assertNull(cache.getDocumentNodeState("/x", rv1, rv2));
}
use of org.apache.jackrabbit.oak.spi.filter.PathFilter in project jackrabbit-oak by apache.
the class SecondaryStoreCacheTest method isCached.
@Test
public void isCached() throws Exception {
SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty));
assertTrue(cache.isCached("/a"));
assertTrue(cache.isCached("/a/b"));
assertFalse(cache.isCached("/x"));
}
use of org.apache.jackrabbit.oak.spi.filter.PathFilter 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);
}
use of org.apache.jackrabbit.oak.spi.filter.PathFilter in project jackrabbit-oak by apache.
the class DocumentNodeStoreService method createCachePredicate.
private Predicate<String> createCachePredicate() {
if (config.persistentCacheIncludes().length == 0) {
return Predicates.alwaysTrue();
}
if (Arrays.equals(config.persistentCacheIncludes(), new String[] { "/" })) {
return Predicates.alwaysTrue();
}
Set<String> paths = new HashSet<>();
for (String p : config.persistentCacheIncludes()) {
p = p != null ? Strings.emptyToNull(p.trim()) : null;
if (p != null) {
paths.add(p);
}
}
PathFilter pf = new PathFilter(paths, emptyList());
log.info("Configuring persistent cache to only cache nodes under paths {}", paths);
return path -> path != null && pf.filter(path) == PathFilter.Result.INCLUDE;
}
use of org.apache.jackrabbit.oak.spi.filter.PathFilter in project jackrabbit-oak by apache.
the class NodeCacheTest method persistentCacheAccessForIncludedPathOnly.
// OAK-7153
@Test
public void persistentCacheAccessForIncludedPathOnly() throws Exception {
PathFilter pf = new PathFilter(singletonList("/a"), emptyList());
Predicate<String> p = path -> pf.filter(path) == PathFilter.Result.INCLUDE;
initializeNodeStore(false, b -> b.setNodeCachePredicate(p));
NodeBuilder builder = ns.getRoot().builder();
builder.child("x");
ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
// clean caches
ns.getNodeCache().invalidateAll();
ns.getNodeChildrenCache().invalidateAll();
MeterStats stats = statsProvider.getMeter("PersistentCache.NodeCache.node.REQUESTS", StatsOptions.DEFAULT);
// hasChildNode() is not cached and will cause a request
// to the persistent cache
long requests = stats.getCount() + 1;
ns.getRoot().hasChildNode("a");
assertEquals(requests, stats.getCount());
// next call must not cause request to persistent cache
// because path is not included
ns.getRoot().hasChildNode("b");
assertEquals(requests, stats.getCount());
}
Aggregations