Merge "Adding deprecated implementation to cache" from Amnon

"This series adds some deprecated methods implemenetation to the CacheService
depnding on its metrics.

It also stub the getDrainProgress in StorageService."
This commit is contained in:
Pekka Enberg 2015-11-11 09:40:04 +02:00
commit e530c13f87
3 changed files with 36 additions and 16 deletions

View File

@ -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<Integer> 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);
}
}
}

View File

@ -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();
}
}

View File

@ -784,7 +784,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);
}
/**