Search in sources :

Example 6 with PathFilter

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));
}
Also used : PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 7 with PathFilter

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"));
}
Also used : PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) Test(org.junit.Test)

Example 8 with PathFilter

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);
}
Also used : PathFilter(org.apache.jackrabbit.oak.spi.filter.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 9 with PathFilter

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;
}
Also used : Arrays(java.util.Arrays) CacheStats(org.apache.jackrabbit.oak.cache.CacheStats) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) CronExpression(org.quartz.CronExpression) Map(java.util.Map) BlobIdTracker(org.apache.jackrabbit.oak.plugins.blob.datastore.BlobIdTracker) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) CheckpointMBean(org.apache.jackrabbit.oak.api.jmx.CheckpointMBean) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore) Predicate(com.google.common.base.Predicate) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Dictionary(java.util.Dictionary) MongoClientURI(com.mongodb.MongoClientURI) AbstractServiceTracker(org.apache.jackrabbit.oak.spi.whiteboard.AbstractServiceTracker) ObserverTracker(org.apache.jackrabbit.oak.spi.commit.ObserverTracker) ComponentContext(org.osgi.service.component.ComponentContext) RevisionGCMBean(org.apache.jackrabbit.oak.spi.state.RevisionGCMBean) GenericDescriptors(org.apache.jackrabbit.oak.spi.descriptors.GenericDescriptors) Strings(com.google.common.base.Strings) Component(org.osgi.service.component.annotations.Component) Closer(com.google.common.io.Closer) Predicates(com.google.common.base.Predicates) GCMonitor(org.apache.jackrabbit.oak.spi.gc.GCMonitor) IOUtils.closeQuietly(org.apache.jackrabbit.oak.commons.IOUtils.closeQuietly) PersistentCacheStatsMBean(org.apache.jackrabbit.oak.api.jmx.PersistentCacheStatsMBean) BlobStoreWrapper(org.apache.jackrabbit.oak.spi.blob.BlobStoreWrapper) Descriptors(org.apache.jackrabbit.oak.api.Descriptors) MongoDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder) PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) PersistentCacheStats(org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCacheStats) OsgiWhiteboard(org.apache.jackrabbit.oak.osgi.OsgiWhiteboard) BlobStoreStats(org.apache.jackrabbit.oak.plugins.blob.BlobStoreStats) DelegatingGCMonitor(org.apache.jackrabbit.oak.spi.gc.DelegatingGCMonitor) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) IOException(java.io.IOException) SimpleValueFactory(org.apache.jackrabbit.commons.SimpleValueFactory) MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder) BlobTrackingStore(org.apache.jackrabbit.oak.plugins.blob.BlobTrackingStore) BlobGarbageCollector(org.apache.jackrabbit.oak.plugins.blob.BlobGarbageCollector) GCMonitorTracker(org.apache.jackrabbit.oak.spi.gc.GCMonitorTracker) BackgroundObserverMBean(org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean) Constants(org.osgi.framework.Constants) BlobGC(org.apache.jackrabbit.oak.plugins.blob.BlobGC) SharedDataStoreUtils(org.apache.jackrabbit.oak.plugins.blob.datastore.SharedDataStoreUtils) LoggerFactory(org.slf4j.LoggerFactory) ConfigurationPolicy(org.osgi.service.component.annotations.ConfigurationPolicy) Utils(org.apache.jackrabbit.oak.plugins.document.util.Utils) CacheStatsMBean(org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean) Clusterable(org.apache.jackrabbit.oak.spi.state.Clusterable) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) BlobStoreStatsMBean(org.apache.jackrabbit.oak.spi.blob.stats.BlobStoreStatsMBean) ParseException(java.text.ParseException) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) WhiteboardExecutor(org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardExecutor) Collections.emptyList(java.util.Collections.emptyList) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) DEFAULT_MEMORY_CACHE_SIZE(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder.DEFAULT_MEMORY_CACHE_SIZE) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) WhiteboardUtils.scheduleWithFixedDelay(org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.scheduleWithFixedDelay) RDBDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder) RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder) FilenameUtils(org.apache.commons.io.FilenameUtils) WhiteboardUtils.registerMBean(org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean) ClusterRepositoryInfo(org.apache.jackrabbit.oak.spi.cluster.ClusterRepositoryInfo) ONLY_STANDALONE_TARGET(org.apache.jackrabbit.oak.spi.blob.osgi.SplitBlobStoreService.ONLY_STANDALONE_TARGET) Supplier(com.google.common.base.Supplier) CacheType(org.apache.jackrabbit.oak.plugins.document.persistentCache.CacheType) HashMap(java.util.HashMap) RevisionGC(org.apache.jackrabbit.oak.spi.state.RevisionGC) HashSet(java.util.HashSet) BlobGCMBean(org.apache.jackrabbit.oak.plugins.blob.BlobGCMBean) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) DataSource(javax.sql.DataSource) Activate(org.osgi.service.component.annotations.Activate) Nonnull(javax.annotation.Nonnull) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration) Logger(org.slf4j.Logger) MongoDocumentStoreMetrics(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStoreMetrics) PropertiesUtil.toLong(org.apache.jackrabbit.oak.commons.PropertiesUtil.toLong) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) MODIFIED_IN_SECS_RESOLUTION(org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS_RESOLUTION) VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) LoggingGCMonitor(org.apache.jackrabbit.oak.spi.gc.LoggingGCMonitor) TimeUnit(java.util.concurrent.TimeUnit) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) Closeable(java.io.Closeable) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) SharedDataStore(org.apache.jackrabbit.oak.plugins.blob.SharedDataStore) NodeStoreProvider(org.apache.jackrabbit.oak.spi.state.NodeStoreProvider) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) HashSet(java.util.HashSet)

Example 10 with PathFilter

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());
}
Also used : CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) StatsOptions(org.apache.jackrabbit.oak.stats.StatsOptions) Collections.singletonList(java.util.Collections.singletonList) EmptyHook(org.apache.jackrabbit.oak.spi.commit.EmptyHook) Lists(com.google.common.collect.Lists) DocumentMKBuilderProvider(org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider) DocumentNodeStateCache(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStateCache) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Assert.fail(org.junit.Assert.fail) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) JsopDiff(org.apache.jackrabbit.oak.json.JsopDiff) PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) Collections.emptyList(java.util.Collections.emptyList) Counting(org.apache.jackrabbit.oak.stats.Counting) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) File(java.io.File) Executors(java.util.concurrent.Executors) Consumer(java.util.function.Consumer) List(java.util.List) Rule(org.junit.Rule) Predicate(com.google.common.base.Predicate) RemovalCause(com.google.common.cache.RemovalCause) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) DefaultStatisticsProvider(org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) MeterStats(org.apache.jackrabbit.oak.stats.MeterStats) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) MeterStats(org.apache.jackrabbit.oak.stats.MeterStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

PathFilter (org.apache.jackrabbit.oak.spi.filter.PathFilter)16 Test (org.junit.Test)13 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)12 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)6 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)4 Predicate (com.google.common.base.Predicate)3 Collections.emptyList (java.util.Collections.emptyList)3 StatisticsProvider (org.apache.jackrabbit.oak.stats.StatisticsProvider)3 RemovalCause (com.google.common.cache.RemovalCause)2 Lists (com.google.common.collect.Lists)2 File (java.io.File)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Executors (java.util.concurrent.Executors)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Consumer (java.util.function.Consumer)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Predicates (com.google.common.base.Predicates)1 Strings (com.google.common.base.Strings)1