Add REST endpoint to list caches
GET /config/server/caches/ lists the server caches. Caches defined by plugins are included. The implementation of the SSH show-caches was adapted so that it uses the new REST endpoint to get the information about the caches. This avoids code duplication. For disk caches a new interface was introduced in gerrit-server. This is done because the list caches REST endpoint needs extra information for disk caches which can only be provided by the disk cache, aka H2CacheImpl. H2CacheImpl is defined in gerrit-cache-h2, but gerrit-server doesn't have a dependency on it and hence can't use instanceof to check whether a cache is a disk cache. Adding this dependency is not wanted and also not possible (because gerrit-cache-h2 already depends on gerrit-server and we can't have cycles in the dependencies). Change-Id: I21bf6e114310f98051a0a8db01012511f58d4add Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import com.google.common.hash.BloomFilter;
|
||||
import com.google.common.hash.Funnel;
|
||||
import com.google.common.hash.Funnels;
|
||||
import com.google.common.hash.PrimitiveSink;
|
||||
import com.google.gerrit.server.cache.PersistentCache;
|
||||
import com.google.gerrit.server.util.TimeUtil;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
@@ -63,7 +64,8 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
*
|
||||
* @see H2CacheFactory
|
||||
*/
|
||||
public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
|
||||
public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> implements
|
||||
PersistentCache {
|
||||
private static final Logger log = LoggerFactory.getLogger(H2CacheImpl.class);
|
||||
|
||||
private final Executor executor;
|
||||
@@ -156,6 +158,7 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
|
||||
return mem.stats();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskStats diskStats() {
|
||||
return store.diskStats();
|
||||
}
|
||||
@@ -193,29 +196,6 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
|
||||
}, delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public static class DiskStats {
|
||||
long size;
|
||||
long space;
|
||||
long hitCount;
|
||||
long missCount;
|
||||
|
||||
public long size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public long space() {
|
||||
return space;
|
||||
}
|
||||
|
||||
public long hitCount() {
|
||||
return hitCount;
|
||||
}
|
||||
|
||||
public long requestCount() {
|
||||
return hitCount + missCount;
|
||||
}
|
||||
}
|
||||
|
||||
static class ValueHolder<V> {
|
||||
final V value;
|
||||
long created;
|
||||
@@ -599,9 +579,8 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
|
||||
}
|
||||
|
||||
DiskStats diskStats() {
|
||||
DiskStats d = new DiskStats();
|
||||
d.hitCount = hitCount.get();
|
||||
d.missCount = missCount.get();
|
||||
long size = 0;
|
||||
long space = 0;
|
||||
SqlHandle c = null;
|
||||
try {
|
||||
c = acquire();
|
||||
@@ -613,8 +592,8 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
|
||||
+ " FROM data");
|
||||
try {
|
||||
if (r.next()) {
|
||||
d.size = r.getLong(1);
|
||||
d.space = r.getLong(2);
|
||||
size = r.getLong(1);
|
||||
space = r.getLong(2);
|
||||
}
|
||||
} finally {
|
||||
r.close();
|
||||
@@ -628,7 +607,7 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
|
||||
} finally {
|
||||
release(c);
|
||||
}
|
||||
return d;
|
||||
return new DiskStats(size, space, hitCount.get(), missCount.get());
|
||||
}
|
||||
|
||||
private SqlHandle acquire() throws SQLException {
|
||||
|
||||
Reference in New Issue
Block a user