You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2017/12/06 16:45:37 UTC
svn commit: r1817309 - in /jackrabbit/oak/trunk/oak-store-document/src:
main/java/org/apache/jackrabbit/oak/plugins/document/
main/java/org/apache/jackrabbit/oak/plugins/document/mongo/
test/java/org/apache/jackrabbit/oak/plugins/document/mongo/
Author: mreutegg
Date: Wed Dec 6 16:45:36 2017
New Revision: 1817309
URL: http://svn.apache.org/viewvc?rev=1817309&view=rev
Log:
OAK-7033: MongoDocumentStore collection metrics
Added:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java (with props)
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
Modified: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java?rev=1817309&r1=1817308&r2=1817309&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java Wed Dec 6 16:45:36 2017
@@ -84,6 +84,22 @@ public abstract class Collection<T exten
}
};
+ /**
+ * The 'blobs' collection contains data from the blob store. The method
+ * {@link #newDocument(DocumentStore)} always throws an
+ * {@link UnsupportedOperationException} because blobs are not stored as
+ * {@link Document}s.
+ */
+ public static final Collection<Document> BLOBS =
+ new Collection<Document>("blobs") {
+ @Nonnull
+ @Override
+ public Document newDocument(DocumentStore store) {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+
private final String name;
public Collection(String name) {
Modified: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1817309&r1=1817308&r2=1817309&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java Wed Dec 6 16:45:36 2017
@@ -66,6 +66,8 @@ import org.apache.jackrabbit.oak.api.jmx
import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStoreMetrics;
import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.oak.spi.commit.ObserverTracker;
@@ -311,8 +313,6 @@ public class DocumentNodeStoreService {
mkBuilder.setBlobStore(blobStore);
}
- mkBuilder.setExecutor(executor);
-
// attach GCMonitor
final GCMonitorTracker gcMonitor = new GCMonitorTracker();
gcMonitor.start(whiteboard);
@@ -366,6 +366,7 @@ public class DocumentNodeStoreService {
registerLastRevRecoveryJob(nodeStore);
registerJournalGC(nodeStore);
registerVersionGCJob(nodeStore);
+ registerDocumentStoreMetrics(mkBuilder.getDocumentStore());
if (!isNodeStoreProvider()) {
observerTracker = new ObserverTracker(nodeStore);
@@ -422,6 +423,7 @@ public class DocumentNodeStoreService {
String persistentCache = resolvePath(config.persistentCache(), DEFAULT_PERSISTENT_CACHE);
String journalCache = resolvePath(config.journalCache(), DEFAULT_JOURNAL_CACHE);
builder.setStatisticsProvider(statisticsProvider).
+ setExecutor(executor).
memoryCacheSize(config.cache() * MB).
memoryCacheDistribution(
config.nodeCachePercentage(),
@@ -819,6 +821,15 @@ public class DocumentNodeStoreService {
props, MODIFIED_IN_SECS_RESOLUTION, true, true));
}
+ private void registerDocumentStoreMetrics(DocumentStore store) {
+ if (store instanceof MongoDocumentStore) {
+ addRegistration(scheduleWithFixedDelay(whiteboard,
+ new MongoDocumentStoreMetrics((MongoDocumentStore) store, statisticsProvider),
+ jobPropertiesFor(MongoDocumentStoreMetrics.class),
+ TimeUnit.MINUTES.toSeconds(1), false, true));
+ }
+ }
+
private String resolvePath(String value, String defaultValue) {
String path = value;
if (Strings.isNullOrEmpty(value)) {
Added: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java?rev=1817309&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java (added)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java Wed Dec 6 16:45:36 2017
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document.mongo;
+
+import java.util.Set;
+
+import com.google.common.collect.ImmutableList;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.MongoException;
+
+import org.apache.jackrabbit.oak.plugins.document.Collection;
+import org.apache.jackrabbit.oak.plugins.document.Document;
+import org.apache.jackrabbit.oak.stats.CounterStats;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.jackrabbit.oak.stats.StatsOptions.METRICS_ONLY;
+
+/**
+ * Implementation specific metrics exposed by the {@link MongoDocumentStore}.
+ */
+public final class MongoDocumentStoreMetrics implements Runnable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MongoDocumentStoreMetrics.class);
+
+ private static final ImmutableList<Collection<? extends Document>> COLLECTIONS = ImmutableList.of(
+ Collection.NODES, Collection.JOURNAL, Collection.CLUSTER_NODES, Collection.SETTINGS, Collection.BLOBS
+ );
+
+ private final DB db;
+
+ private final StatisticsProvider statsProvider;
+
+ public MongoDocumentStoreMetrics(MongoDocumentStore store,
+ StatisticsProvider statsProvider) {
+ this.db = store.getDBCollection(Collection.NODES).getDB();
+ this.statsProvider = statsProvider;
+ }
+
+ //-----------------------< Runnable >---------------------------------------
+
+ @Override
+ public void run() {
+ updateCounters();
+ }
+
+ //-----------------------< internal >---------------------------------------
+
+ private void updateCounters() {
+ LOG.debug("Updating counters");
+ try {
+ Set<String> collectionNames = db.getCollectionNames();
+ for (Collection<? extends Document> c : COLLECTIONS) {
+ if (!collectionNames.contains(c.toString())) {
+ LOG.debug("Collection {} does not exist", c);
+ continue;
+ }
+ CollectionStats stats = getStats(c);
+ updateCounter(getCounter(c, "count"), stats.count);
+ updateCounter(getCounter(c, "size"), stats.size);
+ updateCounter(getCounter(c, "storageSize"), stats.storageSize);
+ updateCounter(getCounter(c, "totalIndexSize"), stats.totalIndexSize);
+ }
+ } catch (MongoException e) {
+ LOG.warn("Updating counters failed: {}", e.toString());
+ }
+ }
+
+ private void updateCounter(CounterStats counter, long value) {
+ counter.inc(value - counter.getCount());
+ }
+
+ private CollectionStats getStats(Collection<? extends Document> c)
+ throws MongoException {
+ CollectionStats stats = new CollectionStats();
+ BasicDBObject result = db.getCollection(c.toString()).getStats();
+ stats.count = result.getLong("count", 0);
+ stats.size = result.getLong("size", 0);
+ stats.storageSize = result.getLong("storageSize", 0);
+ stats.totalIndexSize = result.getLong("totalIndexSize", 0);
+ return stats;
+ }
+
+ private CounterStats getCounter(Collection<? extends Document> c,
+ String name) {
+ String counterName = "MongoDB." + c.toString() + "." + name;
+ return statsProvider.getCounterStats(counterName, METRICS_ONLY);
+ }
+
+ private static final class CollectionStats {
+ long count;
+ long size;
+ long storageSize;
+ long totalIndexSize;
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetrics.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java?rev=1817309&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java (added)
+++ jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java Wed Dec 6 16:45:36 2017
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document.mongo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest;
+import org.apache.jackrabbit.oak.plugins.document.Collection;
+import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
+import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.junit.After;
+import org.junit.Test;
+
+import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder;
+import static org.apache.jackrabbit.oak.stats.StatsOptions.METRICS_ONLY;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class MongoDocumentStoreMetricsTest extends AbstractMongoConnectionTest {
+
+ private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
+
+ private StatisticsProvider statsProvider = new DefaultStatisticsProvider(executorService);
+
+ @After
+ public void after() throws Exception {
+ executorService.shutdown();
+ executorService.awaitTermination(1, TimeUnit.SECONDS);
+ }
+
+ @Test
+ public void updateCounters() throws Exception {
+ MongoDocumentStore store = new MongoDocumentStore(
+ mongoConnection.getDB(), newMongoDocumentNodeStoreBuilder());
+ MongoDocumentStoreMetrics metrics = new MongoDocumentStoreMetrics(store, statsProvider);
+ metrics.run();
+ // document for root node
+ assertEquals(1, getCount("MongoDB.nodes.count"));
+ // one cluster node
+ assertEquals(1, getCount("MongoDB.clusterNodes.count"));
+
+ List<UpdateOp> updates = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ updates.add(new UpdateOp("id-" + i, true));
+ }
+ assertTrue(store.create(Collection.NODES, updates));
+
+ metrics.run();
+ assertEquals(11, getCount("MongoDB.nodes.count"));
+ }
+
+ private long getCount(String name) {
+ return statsProvider.getCounterStats(name, METRICS_ONLY).getCount();
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreMetricsTest.java
------------------------------------------------------------------------------
svn:eol-style = native