From 54d451de882c35c983cb1503ffac69ce0bd23791 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Tue, 10 Nov 2015 15:58:51 +0200 Subject: [PATCH 1/3] CacheMetrics: Add recent hit rate The depricated recent hit rate implementation was add from Origin as it is still been used by external system. Signed-off-by: Amnon Heiman --- .../apache/cassandra/metrics/CacheMetrics.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/cassandra/metrics/CacheMetrics.java b/src/main/java/org/apache/cassandra/metrics/CacheMetrics.java index 9eb8d4a..c15f199 100644 --- a/src/main/java/org/apache/cassandra/metrics/CacheMetrics.java +++ b/src/main/java/org/apache/cassandra/metrics/CacheMetrics.java @@ -24,6 +24,8 @@ package org.apache.cassandra.metrics; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + import com.cloudius.urchin.api.APIClient; import com.cloudius.urchin.metrics.APIMetrics; import com.cloudius.urchin.metrics.DefaultNameFactory; @@ -48,6 +50,9 @@ public class CacheMetrics { /** Total number of cache entries */ public final Gauge entries; + private final AtomicLong lastRequests = new AtomicLong(0); + private final AtomicLong lastHits = new AtomicLong(0); + private APIClient c = new APIClient(); /** @@ -101,6 +106,17 @@ public class CacheMetrics { // for backward compatibility @Deprecated public double getRecentHitRate() { - return 0; + long r = requests.count(); + long h = hits.count(); + try + { + return ((double)(h - lastHits.get())) / (r - lastRequests.get()); + } + finally + { + lastRequests.set(r); + lastHits.set(h); + } } + } From 01477809acd738682c87fa6b8fda5745fd2c3b7b Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Tue, 10 Nov 2015 16:54:48 +0200 Subject: [PATCH 2/3] CacheService: Add depricated unimplemented methods This patch follow origin in the implementation of the depricated methods in CacheService. It propogate the request to the relevant metrics. Signed-off-by: Amnon Heiman --- .../cassandra/service/CacheService.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/apache/cassandra/service/CacheService.java b/src/main/java/org/apache/cassandra/service/CacheService.java index ffe2257..441a608 100644 --- a/src/main/java/org/apache/cassandra/service/CacheService.java +++ b/src/main/java/org/apache/cassandra/service/CacheService.java @@ -211,7 +211,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getKeyCacheHits() { log(" getKeyCacheHits()"); - return c.getLongValue(""); + return keyCache.hits.count(); } /** @@ -220,7 +220,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getRowCacheHits() { log(" getRowCacheHits()"); - return c.getLongValue(""); + return rowCache.hits.count(); } /** @@ -229,7 +229,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getKeyCacheRequests() { log(" getKeyCacheRequests()"); - return c.getLongValue(""); + return keyCache.requests.count(); } /** @@ -238,7 +238,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getRowCacheRequests() { log(" getRowCacheRequests()"); - return c.getLongValue(""); + return rowCache.requests.count(); } /** @@ -247,7 +247,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public double getKeyCacheRecentHitRate() { log(" getKeyCacheRecentHitRate()"); - return c.getDoubleValue(""); + return keyCache.getRecentHitRate(); } /** @@ -256,7 +256,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public double getRowCacheRecentHitRate() { log(" getRowCacheRecentHitRate()"); - return c.getDoubleValue(""); + return rowCache.getRecentHitRate(); } /** @@ -265,7 +265,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getRowCacheCapacityInMB() { log(" getRowCacheCapacityInMB()"); - return c.getLongValue(""); + return getRowCacheCapacityInBytes() / 1024 / 1024; } /** @@ -274,7 +274,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getRowCacheCapacityInBytes() { log(" getRowCacheCapacityInBytes()"); - return c.getLongValue(""); + return rowCache.capacity.value(); } /** @@ -283,7 +283,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getKeyCacheCapacityInMB() { log(" getKeyCacheCapacityInMB()"); - return c.getLongValue(""); + return getKeyCacheCapacityInBytes() / 1024 / 1024; } /** @@ -292,7 +292,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getKeyCacheCapacityInBytes() { log(" getKeyCacheCapacityInBytes()"); - return c.getLongValue(""); + return keyCache.capacity.value(); } /** @@ -301,7 +301,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getRowCacheSize() { log(" getRowCacheSize()"); - return c.getLongValue(""); + return rowCache.size.value(); } /** @@ -310,7 +310,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getRowCacheEntries() { log(" getRowCacheEntries()"); - return c.getLongValue(""); + return rowCache.size.value(); } /** @@ -319,7 +319,7 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getKeyCacheSize() { log(" getKeyCacheSize()"); - return c.getLongValue(""); + return keyCache.size.value(); } /** @@ -328,6 +328,6 @@ public class CacheService implements CacheServiceMBean { @Deprecated public long getKeyCacheEntries() { log(" getKeyCacheEntries()"); - return c.getLongValue(""); + return keyCache.size.value(); } } From 07b319d82733212a3e35f93563a543fe7fdc364c Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Tue, 10 Nov 2015 17:03:50 +0200 Subject: [PATCH 3/3] StorageService: Stub the getDrainProgress Drain progress is not implemented yet, it is needed by the nodetool command so it will not fail. This patches the functionality until the API will be ready, which, in that time it would be revert. Signed-off-by: Amnon Heiman --- .../java/org/apache/cassandra/service/StorageService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/cassandra/service/StorageService.java b/src/main/java/org/apache/cassandra/service/StorageService.java index bae9cec..eaa0c56 100644 --- a/src/main/java/org/apache/cassandra/service/StorageService.java +++ b/src/main/java/org/apache/cassandra/service/StorageService.java @@ -769,7 +769,11 @@ public class StorageService extends NotificationBroadcasterSupport /** get the progress of a drain operation */ public String getDrainProgress() { log(" getDrainProgress()"); - return c.getStringValue("/storage_service/drain"); + // FIXME + // This is a workaround so the nodetool would work + // it should be revert when the drain progress will be implemented + //return c.getStringValue("/storage_service/drain"); + return String.format("Drained %s/%s ColumnFamilies", 0, 0); } /**