Search in sources :

Example 1 with CacheStats

use of org.apache.jackrabbit.oak.cache.CacheStats in project jackrabbit-oak by apache.

the class DocumentNodeStoreService method registerJMXBeans.

private void registerJMXBeans(final DocumentNodeStore store, DocumentMK.Builder mkBuilder) throws IOException {
    addRegistration(registerMBean(whiteboard, CacheStatsMBean.class, store.getNodeCacheStats(), CacheStatsMBean.TYPE, store.getNodeCacheStats().getName()));
    addRegistration(registerMBean(whiteboard, CacheStatsMBean.class, store.getNodeChildrenCacheStats(), CacheStatsMBean.TYPE, store.getNodeChildrenCacheStats().getName()));
    for (CacheStats cs : store.getDiffCacheStats()) {
        addRegistration(registerMBean(whiteboard, CacheStatsMBean.class, cs, CacheStatsMBean.TYPE, cs.getName()));
    }
    DocumentStore ds = store.getDocumentStore();
    if (ds.getCacheStats() != null) {
        for (CacheStats cacheStats : ds.getCacheStats()) {
            addRegistration(registerMBean(whiteboard, CacheStatsMBean.class, cacheStats, CacheStatsMBean.TYPE, cacheStats.getName()));
        }
    }
    addRegistration(registerMBean(whiteboard, CheckpointMBean.class, new DocumentCheckpointMBean(store), CheckpointMBean.TYPE, "Document node store checkpoint management"));
    addRegistration(registerMBean(whiteboard, DocumentNodeStoreMBean.class, store.getMBean(), DocumentNodeStoreMBean.TYPE, "Document node store management"));
    if (mkBuilder.getBlobStoreCacheStats() != null) {
        addRegistration(registerMBean(whiteboard, CacheStatsMBean.class, mkBuilder.getBlobStoreCacheStats(), CacheStatsMBean.TYPE, mkBuilder.getBlobStoreCacheStats().getName()));
    }
    if (mkBuilder.getDocumentStoreStatsCollector() instanceof DocumentStoreStatsMBean) {
        addRegistration(registerMBean(whiteboard, DocumentStoreStatsMBean.class, (DocumentStoreStatsMBean) mkBuilder.getDocumentStoreStatsCollector(), DocumentStoreStatsMBean.TYPE, "DocumentStore Statistics"));
    }
    // register persistent cache stats
    Map<CacheType, PersistentCacheStats> persistenceCacheStats = mkBuilder.getPersistenceCacheStats();
    for (PersistentCacheStats pcs : persistenceCacheStats.values()) {
        addRegistration(registerMBean(whiteboard, PersistentCacheStatsMBean.class, pcs, PersistentCacheStatsMBean.TYPE, pcs.getName()));
    }
    final long versionGcMaxAgeInSecs = toLong(prop(PROP_VER_GC_MAX_AGE), DEFAULT_VER_GC_MAX_AGE);
    final long blobGcMaxAgeInSecs = toLong(prop(PROP_BLOB_GC_MAX_AGE), DEFAULT_BLOB_GC_MAX_AGE);
    if (store.getBlobStore() instanceof GarbageCollectableBlobStore) {
        BlobGarbageCollector gc = store.createBlobGarbageCollector(blobGcMaxAgeInSecs, ClusterRepositoryInfo.getOrCreateId(nodeStore));
        addRegistration(registerMBean(whiteboard, BlobGCMBean.class, new BlobGC(gc, executor), BlobGCMBean.TYPE, "Document node store blob garbage collection"));
    }
    Runnable startGC = new Runnable() {

        @Override
        public void run() {
            try {
                store.getVersionGarbageCollector().gc(versionGcMaxAgeInSecs, TimeUnit.SECONDS);
            } catch (IOException e) {
                log.warn("Error occurred while executing the Version Garbage Collector", e);
            }
        }
    };
    Runnable cancelGC = new Runnable() {

        @Override
        public void run() {
            store.getVersionGarbageCollector().cancel();
        }
    };
    Supplier<String> status = new Supplier<String>() {

        @Override
        public String get() {
            return store.getVersionGarbageCollector().getStatus();
        }
    };
    RevisionGC revisionGC = new RevisionGC(startGC, cancelGC, status, executor);
    addRegistration(registerMBean(whiteboard, RevisionGCMBean.class, revisionGC, RevisionGCMBean.TYPE, "Document node store revision garbage collection"));
    BlobStoreStats blobStoreStats = mkBuilder.getBlobStoreStats();
    if (!customBlobStore && blobStoreStats != null) {
        addRegistration(registerMBean(whiteboard, BlobStoreStatsMBean.class, blobStoreStats, BlobStoreStatsMBean.TYPE, ds.getClass().getSimpleName()));
    }
    if (!mkBuilder.isBundlingDisabled()) {
        addRegistration(registerMBean(whiteboard, BackgroundObserverMBean.class, store.getBundlingConfigHandler().getMBean(), BackgroundObserverMBean.TYPE, "BundlingConfigObserver"));
    }
}
Also used : CacheType(org.apache.jackrabbit.oak.plugins.document.persistentCache.CacheType) CheckpointMBean(org.apache.jackrabbit.oak.api.jmx.CheckpointMBean) PersistentCacheStats(org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCacheStats) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) Supplier(com.google.common.base.Supplier) BlobGarbageCollector(org.apache.jackrabbit.oak.plugins.blob.BlobGarbageCollector) BlobGC(org.apache.jackrabbit.oak.plugins.blob.BlobGC) IOException(java.io.IOException) RevisionGC(org.apache.jackrabbit.oak.spi.state.RevisionGC) BlobStoreStatsMBean(org.apache.jackrabbit.oak.spi.blob.stats.BlobStoreStatsMBean) PersistentCacheStatsMBean(org.apache.jackrabbit.oak.api.jmx.PersistentCacheStatsMBean) CacheStatsMBean(org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean) PersistentCacheStatsMBean(org.apache.jackrabbit.oak.api.jmx.PersistentCacheStatsMBean) BlobGCMBean(org.apache.jackrabbit.oak.plugins.blob.BlobGCMBean) BlobStoreStats(org.apache.jackrabbit.oak.plugins.blob.BlobStoreStats) CacheStats(org.apache.jackrabbit.oak.cache.CacheStats) PersistentCacheStats(org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCacheStats) RevisionGCMBean(org.apache.jackrabbit.oak.spi.state.RevisionGCMBean) BackgroundObserverMBean(org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean)

Example 2 with CacheStats

use of org.apache.jackrabbit.oak.cache.CacheStats in project jackrabbit-oak by apache.

the class DocumentMKBuilderTest method lazyInit.

@Test
public void lazyInit() throws Exception {
    Iterable<CacheStats> cacheStats = mk.getDocumentStore().getCacheStats();
    assertNotNull(cacheStats);
    assertEquals(2, Iterables.size(cacheStats));
    CacheStats docCacheStats = Iterables.get(cacheStats, 0);
    CacheStats prevDocCacheStats = Iterables.get(cacheStats, 1);
    assertEquals("Document-Documents", docCacheStats.getName());
    assertEquals("Document-PrevDocuments", prevDocCacheStats.getName());
    assertEquals(DOC_CACHE_SIZE, docCacheStats.getMaxTotalWeight());
    assertEquals(PREV_DOC_CACHE_SIZE, prevDocCacheStats.getMaxTotalWeight());
}
Also used : CacheStats(org.apache.jackrabbit.oak.cache.CacheStats) Test(org.junit.Test)

Example 3 with CacheStats

use of org.apache.jackrabbit.oak.cache.CacheStats in project jackrabbit-oak by apache.

the class DocumentNodeStoreDiffTest method diff.

// OAK-2562
@Test
public void diff() throws Exception {
    DocumentNodeStore store = mk.getNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    builder.child("other");
    for (int i = 0; i < 10; i++) {
        builder.child("test").child("folder").child("node-" + i);
    }
    merge(store, builder);
    for (int i = 0; i < 50; i++) {
        builder = store.getRoot().builder();
        builder.child("other").child("node-" + i);
        merge(store, builder);
    }
    NodeState before = store.getRoot();
    builder = store.getRoot().builder();
    builder.child("test").child("folder").child("node-x").child("child");
    NodeState after = merge(store, builder);
    for (int i = 0; i < 10; i++) {
        builder = store.getRoot().builder();
        builder.child("test").child("folder").child("node-" + i).child("child");
        merge(store, builder);
    }
    Iterable<CacheStats> stats = store.getDiffCacheStats();
    for (CacheStats cs : stats) {
        cs.resetStats();
    }
    // must not cause cache misses
    Diff.perform(before, after);
    for (CacheStats cs : stats) {
        assertEquals(0, cs.getMissCount());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) CacheStats(org.apache.jackrabbit.oak.cache.CacheStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 4 with CacheStats

use of org.apache.jackrabbit.oak.cache.CacheStats in project jackrabbit-oak by apache.

the class JournalDiffLoaderTest method withPath.

@Test
public void withPath() throws Exception {
    DocumentNodeStore ns = builderProvider.newBuilder().clock(clock).setAsyncDelay(0).getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    builder.child("foo");
    merge(ns, builder);
    ns.runBackgroundOperations();
    DocumentNodeState before = (DocumentNodeState) ns.getRoot().getChildNode("foo");
    builder = ns.getRoot().builder();
    builder.child("bar");
    merge(ns, builder);
    ns.runBackgroundOperations();
    builder = ns.getRoot().builder();
    builder.child("foo").child("a").child("b").child("c");
    merge(ns, builder);
    ns.runBackgroundOperations();
    builder = ns.getRoot().builder();
    builder.child("bar").child("a").child("b").child("c");
    merge(ns, builder);
    ns.runBackgroundOperations();
    DocumentNodeState after = (DocumentNodeState) ns.getRoot().getChildNode("foo");
    CacheStats cs = getMemoryDiffStats(ns);
    assertNotNull(cs);
    cs.resetStats();
    Set<String> changes = changeChildNodes(ns, before, after);
    assertEquals(1, changes.size());
    assertTrue(changes.contains("a"));
    // must only push /foo, /foo/a, /foo/a/b and /foo/a/b/c into cache
    assertEquals(4, cs.getElementCount());
}
Also used : CacheStats(org.apache.jackrabbit.oak.cache.CacheStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 with CacheStats

use of org.apache.jackrabbit.oak.cache.CacheStats in project jackrabbit-oak by apache.

the class PreviousDocCacheTest method cacheTestPrevDocs.

@Test
public void cacheTestPrevDocs() throws Exception {
    DocumentNodeStore ns = mk.getNodeStore();
    DocumentStore docStore = ns.getDocumentStore();
    final int SPLIT_THRESHOLD = 10;
    NodeBuilder b;
    // Set property 110 times. Split at each 10. This should lead to 11 leaf prev docs and 1 intermediate prev doc.
    for (int j = 0; j <= SPLIT_THRESHOLD; j++) {
        for (int i = 0; i < SPLIT_THRESHOLD; i++) {
            b = ns.getRoot().builder();
            b.setProperty("foo", "node-" + j + "-" + i);
            merge(ns, b);
        }
        splitDocs(ns, SPLIT_THRESHOLD);
    }
    CacheStats nodesCache = null;
    CacheStats prevDocsCache = null;
    for (CacheStats cacheStats : docStore.getCacheStats()) {
        if ("Document-Documents".equals(cacheStats.getName())) {
            nodesCache = cacheStats;
        } else if ("Document-PrevDocuments".equals(cacheStats.getName())) {
            prevDocsCache = cacheStats;
        }
    }
    assertNotNull("Nodes cache must not be null", nodesCache);
    assertNotNull("Prev docs cache must not be null", prevDocsCache);
    validateFullyLoadedCache(docStore, SPLIT_THRESHOLD, nodesCache, prevDocsCache);
    docStore.invalidateCache();
    assertEquals("No entries expected in nodes cache", 0, nodesCache.getElementCount());
    assertEquals("No entries expected in prev docs cache", 0, prevDocsCache.getElementCount());
    NodeDocument doc = docStore.find(NODES, "0:/");
    assertEquals("Only main doc entry expected in nodes cache", 1, nodesCache.getElementCount());
    assertEquals("No entries expected in prev docs cache", 0, prevDocsCache.getElementCount());
    Iterators.size(doc.getAllPreviousDocs());
    validateFullyLoadedCache(docStore, SPLIT_THRESHOLD, nodesCache, prevDocsCache);
}
Also used : CacheStats(org.apache.jackrabbit.oak.cache.CacheStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

CacheStats (org.apache.jackrabbit.oak.cache.CacheStats)10 Test (org.junit.Test)5 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)4 PersistentCacheStats (org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCacheStats)3 CacheStatsMBean (org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean)2 CheckpointMBean (org.apache.jackrabbit.oak.api.jmx.CheckpointMBean)2 PersistentCacheStatsMBean (org.apache.jackrabbit.oak.api.jmx.PersistentCacheStatsMBean)2 CacheValue (org.apache.jackrabbit.oak.cache.CacheValue)2 BlobGC (org.apache.jackrabbit.oak.plugins.blob.BlobGC)2 BlobGCMBean (org.apache.jackrabbit.oak.plugins.blob.BlobGCMBean)2 BlobGarbageCollector (org.apache.jackrabbit.oak.plugins.blob.BlobGarbageCollector)2 BlobStoreStats (org.apache.jackrabbit.oak.plugins.blob.BlobStoreStats)2 CacheType (org.apache.jackrabbit.oak.plugins.document.persistentCache.CacheType)2 StringValue (org.apache.jackrabbit.oak.plugins.document.util.StringValue)2 GarbageCollectableBlobStore (org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore)2 BlobStoreStatsMBean (org.apache.jackrabbit.oak.spi.blob.stats.BlobStoreStatsMBean)2 BackgroundObserverMBean (org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean)2 RevisionGC (org.apache.jackrabbit.oak.spi.state.RevisionGC)2 RevisionGCMBean (org.apache.jackrabbit.oak.spi.state.RevisionGCMBean)2 Supplier (com.google.common.base.Supplier)1