From 8a1593a776a5c47a39bc172e1075f66bafe51a77 Mon Sep 17 00:00:00 2001 From: Dan LaRocque Date: Tue, 5 May 2015 06:46:02 -0400 Subject: [PATCH] Revert "Added metrics instrumentation around manager to account for mutateMany calls. Refactored metrics initialization." This reverts commit 43690b3bea97373aca20569e35c442bd4b17289f. --- .../titan/diskstorage/Backend.java | 32 ++--- .../util/MetricInstrumentedStoreManager.java | 109 ------------------ .../graphdb/TitanOperationCountingTest.java | 27 +---- 3 files changed, 21 insertions(+), 147 deletions(-) delete mode 100644 titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/util/MetricInstrumentedStoreManager.java diff --git a/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Backend.java b/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Backend.java index 845e1754c3..26244e5c1a 100644 --- a/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Backend.java +++ b/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Backend.java @@ -31,7 +31,6 @@ import com.thinkaurelius.titan.diskstorage.util.BackendOperation; import com.thinkaurelius.titan.diskstorage.util.MetricInstrumentedStore; import com.thinkaurelius.titan.diskstorage.configuration.backend.KCVSConfiguration; -import com.thinkaurelius.titan.diskstorage.util.MetricInstrumentedStoreManager; import com.thinkaurelius.titan.diskstorage.util.StandardBaseTransactionConfig; import com.thinkaurelius.titan.diskstorage.util.time.TimestampProvider; import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration; @@ -79,7 +78,6 @@ public class Backend implements LockerProvider, AutoCloseable { public static final String ID_STORE_NAME = "titan_ids"; - public static final String METRICS_STOREMANAGER_NAME = "storeManager"; public static final String METRICS_MERGED_STORE = "stores"; public static final String METRICS_MERGED_CACHE = "caches"; public static final String METRICS_CACHE_SUFFIX = ".cache"; @@ -137,12 +135,7 @@ public class Backend implements LockerProvider, AutoCloseable { public Backend(Configuration configuration) { this.configuration = configuration; - KeyColumnValueStoreManager manager = getStorageManager(configuration); - if (configuration.get(BASIC_METRICS)) { - storeManager = new MetricInstrumentedStoreManager(manager,METRICS_STOREMANAGER_NAME,configuration.get(METRICS_MERGE_STORES),METRICS_MERGED_STORE); - } else { - storeManager = manager; - } + storeManager = getStorageManager(configuration); indexes = getIndexes(configuration); storeFeatures = storeManager.getFeatures(); @@ -220,9 +213,13 @@ public Locker getLocker(String lockerName) { */ public void initialize(Configuration config) { try { + boolean reportMetrics = configuration.get(BASIC_METRICS); + //EdgeStore & VertexIndexStore KeyColumnValueStore idStore = storeManager.openDatabase(ID_STORE_NAME); - + if (reportMetrics) { + idStore = new MetricInstrumentedStore(idStore, getMetricsStoreName(ID_STORE_NAME)); + } idAuthority = null; if (storeFeatures.isKeyConsistent()) { idAuthority = new ConsistentKeyIDAuthority(idStore, storeManager, config); @@ -233,6 +230,11 @@ public void initialize(Configuration config) { KeyColumnValueStore edgeStoreRaw = storeManagerLocking.openDatabase(EDGESTORE_NAME); KeyColumnValueStore indexStoreRaw = storeManagerLocking.openDatabase(INDEXSTORE_NAME); + if (reportMetrics) { + edgeStoreRaw = new MetricInstrumentedStore(edgeStoreRaw, getMetricsStoreName(EDGESTORE_NAME)); + indexStoreRaw = new MetricInstrumentedStore(indexStoreRaw, getMetricsStoreName(INDEXSTORE_NAME)); + } + //Configure caches if (cacheEnabled) { long expirationTime = configuration.get(DB_CACHE_TIME); @@ -256,8 +258,8 @@ public void initialize(Configuration config) { long edgeStoreCacheSize = Math.round(cacheSizeBytes * EDGESTORE_CACHE_PERCENT); long indexStoreCacheSize = Math.round(cacheSizeBytes * INDEXSTORE_CACHE_PERCENT); - edgeStore = new ExpirationKCVSCache(edgeStoreRaw,getMetricsCacheName("edgeStore"),expirationTime,cleanWaitTime,edgeStoreCacheSize); - indexStore = new ExpirationKCVSCache(indexStoreRaw,getMetricsCacheName("indexStore"),expirationTime,cleanWaitTime,indexStoreCacheSize); + edgeStore = new ExpirationKCVSCache(edgeStoreRaw,getMetricsCacheName("edgeStore",reportMetrics),expirationTime,cleanWaitTime,edgeStoreCacheSize); + indexStore = new ExpirationKCVSCache(indexStoreRaw,getMetricsCacheName("indexStore",reportMetrics),expirationTime,cleanWaitTime,indexStoreCacheSize); } else { edgeStore = new NoKCVSCache(edgeStoreRaw); indexStore = new NoKCVSCache(indexStoreRaw); @@ -374,8 +376,12 @@ public KCVSConfiguration getUserConfiguration() { return userConfig; } - private String getMetricsCacheName(String storeName) { - if (!configuration.get(BASIC_METRICS)) return null; + private String getMetricsStoreName(String storeName) { + return configuration.get(METRICS_MERGE_STORES) ? METRICS_MERGED_STORE : storeName; + } + + private String getMetricsCacheName(String storeName, boolean reportMetrics) { + if (!reportMetrics) return null; return configuration.get(METRICS_MERGE_STORES) ? METRICS_MERGED_CACHE : storeName + METRICS_CACHE_SUFFIX; } diff --git a/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/util/MetricInstrumentedStoreManager.java b/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/util/MetricInstrumentedStoreManager.java deleted file mode 100644 index c248658b84..0000000000 --- a/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/util/MetricInstrumentedStoreManager.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.thinkaurelius.titan.diskstorage.util; - -import com.codahale.metrics.Timer; -import com.google.common.base.Preconditions; -import com.thinkaurelius.titan.diskstorage.BackendException; -import com.thinkaurelius.titan.diskstorage.BaseTransactionConfig; -import com.thinkaurelius.titan.diskstorage.StaticBuffer; -import com.thinkaurelius.titan.diskstorage.StoreMetaData; -import com.thinkaurelius.titan.diskstorage.keycolumnvalue.*; -import com.thinkaurelius.titan.util.stats.MetricManager; -import static com.thinkaurelius.titan.diskstorage.util.MetricInstrumentedStore.*; - -import java.util.List; -import java.util.Map; - -import static com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.METRICS_MERGE_STORES; - -/** - * @author Matthias Broecheler (me@matthiasb.com) - */ -public class MetricInstrumentedStoreManager implements KeyColumnValueStoreManager { - - public static final String M_OPEN_DATABASE = "openDatabase"; - public static final String M_START_TX = "startTransaction"; - public static final String M_CLOSE_MANAGER = "closeManager"; - - - public static final String GLOBAL_PREFIX = "global"; - - private final KeyColumnValueStoreManager backend; - private final boolean mergeStoreMetrics; - private final String mergedMetricsName; - private final String managerMetricsName; - - public MetricInstrumentedStoreManager(KeyColumnValueStoreManager backend, String managerMetricsName, - boolean mergeStoreMetrics, String mergedMetricsName) { - this.backend = backend; - this.mergeStoreMetrics = mergeStoreMetrics; - this.mergedMetricsName = mergedMetricsName; - this.managerMetricsName = managerMetricsName; - } - - - private String getMetricsStoreName(String storeName) { - return mergeStoreMetrics ? mergedMetricsName : storeName; - } - - @Override - public KeyColumnValueStore openDatabase(String name, StoreMetaData.Container metaData) throws BackendException { - MetricManager.INSTANCE.getCounter(GLOBAL_PREFIX, managerMetricsName, M_OPEN_DATABASE, M_CALLS).inc(); - return new MetricInstrumentedStore(backend.openDatabase(name, metaData),getMetricsStoreName(name)); - } - - @Override - public void mutateMany(Map> mutations, StoreTransaction txh) throws BackendException { - if (!txh.getConfiguration().hasGroupName()) { - backend.mutateMany(mutations,txh); - } - String prefix = txh.getConfiguration().getGroupName(); - - final MetricManager mgr = MetricManager.INSTANCE; - mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_CALLS).inc(); - final Timer.Context tc = mgr.getTimer(prefix, managerMetricsName, M_MUTATE, M_TIME).time(); - - try { - backend.mutateMany(mutations,txh); - } catch (BackendException e) { - mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_EXCEPTIONS).inc(); - throw e; - } catch (RuntimeException e) { - mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_EXCEPTIONS).inc(); - throw e; - } finally { - tc.stop(); - } - } - - @Override - public StoreTransaction beginTransaction(BaseTransactionConfig config) throws BackendException { - MetricManager.INSTANCE.getCounter(GLOBAL_PREFIX, managerMetricsName, M_START_TX, M_CALLS).inc(); - return backend.beginTransaction(config); - } - - @Override - public void close() throws BackendException { - backend.close(); - MetricManager.INSTANCE.getCounter(GLOBAL_PREFIX, managerMetricsName, M_CLOSE_MANAGER, M_CALLS).inc(); - } - - @Override - public void clearStorage() throws BackendException { - backend.clearStorage(); - } - - @Override - public StoreFeatures getFeatures() { - return backend.getFeatures(); - } - - @Override - public String getName() { - return backend.getName(); - } - - @Override - public List getLocalKeyPartition() throws BackendException { - return backend.getLocalKeyPartition(); - } -} diff --git a/titan-test/src/main/java/com/thinkaurelius/titan/graphdb/TitanOperationCountingTest.java b/titan-test/src/main/java/com/thinkaurelius/titan/graphdb/TitanOperationCountingTest.java index 4c3c5fa681..c8a143a6f4 100644 --- a/titan-test/src/main/java/com/thinkaurelius/titan/graphdb/TitanOperationCountingTest.java +++ b/titan-test/src/main/java/com/thinkaurelius/titan/graphdb/TitanOperationCountingTest.java @@ -204,32 +204,9 @@ public void testReadOperations(boolean cache) { } - public static final List STORE_NAMES = - ImmutableList.of(Backend.EDGESTORE_NAME,Backend.INDEXSTORE_NAME,Backend.ID_STORE_NAME,Backend.METRICS_STOREMANAGER_NAME); - - @Test - public void testSettingProperty() throws Exception { - metricsPrefix = "metrics1"; - - mgmt.makePropertyKey("foo").dataType(String.class).cardinality(Cardinality.SINGLE).make(); - finishSchema(); - - TitanVertex v = tx.addVertex(); - v.property("foo","bar"); - tx.commit(); - - - TitanTransaction tx = graph.buildTransaction().checkExternalVertexExistence(false).groupName(metricsPrefix).start(); - v = tx.getVertex(v.longId()); - v.property("foo","bus"); - tx.commit(); - printAllMetrics(); - verifyStoreMetrics(STORE_NAMES.get(0)); - verifyStoreMetrics(STORE_NAMES.get(1)); - verifyStoreMetrics(STORE_NAMES.get(2)); - verifyStoreMetrics(STORE_NAMES.get(3), ImmutableMap.of(M_MUTATE, 1l)); - } + public static final List STORE_NAMES = + ImmutableList.of("edgeStore", "vertexIndexStore", "edgeIndexStore", "idStore"); @Test @Ignore //TODO: Ignore for now until everything is stable - then do the counting