mirror of
https://github.com/apache/druid.git
synced 2025-02-20 00:47:40 +00:00
add close method in Cache interface (#6540)
* add close method in Cache interface * address comments * address comments and fix travis-ci * use try-finally
This commit is contained in:
parent
607339003b
commit
e8dd3716b8
@ -21,6 +21,7 @@ package org.apache.druid.client.cache;
|
|||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import org.apache.druid.java.util.common.lifecycle.LifecycleStop;
|
||||||
import org.apache.druid.java.util.common.logger.Logger;
|
import org.apache.druid.java.util.common.logger.Logger;
|
||||||
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
||||||
import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
|
import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
|
||||||
@ -29,6 +30,7 @@ import redis.clients.jedis.JedisPool;
|
|||||||
import redis.clients.jedis.JedisPoolConfig;
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
import redis.clients.jedis.exceptions.JedisException;
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -147,6 +149,13 @@ public class RedisCache implements Cache
|
|||||||
// no resources to cleanup
|
// no resources to cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@LifecycleStop
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
pool.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CacheStats getStats()
|
public CacheStats getStats()
|
||||||
{
|
{
|
||||||
|
@ -24,13 +24,14 @@ import org.apache.druid.java.util.common.StringUtils;
|
|||||||
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.Closeable;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public interface Cache
|
public interface Cache extends Closeable
|
||||||
{
|
{
|
||||||
@Nullable
|
@Nullable
|
||||||
byte[] get(NamedKey key);
|
byte[] get(NamedKey key);
|
||||||
|
@ -28,11 +28,13 @@ import com.google.common.collect.Maps;
|
|||||||
import net.jpountz.lz4.LZ4Compressor;
|
import net.jpountz.lz4.LZ4Compressor;
|
||||||
import net.jpountz.lz4.LZ4Factory;
|
import net.jpountz.lz4.LZ4Factory;
|
||||||
import net.jpountz.lz4.LZ4FastDecompressor;
|
import net.jpountz.lz4.LZ4FastDecompressor;
|
||||||
|
import org.apache.druid.java.util.common.lifecycle.LifecycleStop;
|
||||||
import org.apache.druid.java.util.common.logger.Logger;
|
import org.apache.druid.java.util.common.logger.Logger;
|
||||||
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
||||||
import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
|
import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
|
||||||
import org.apache.druid.utils.JvmUtils;
|
import org.apache.druid.utils.JvmUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.OptionalLong;
|
import java.util.OptionalLong;
|
||||||
@ -115,6 +117,13 @@ public class CaffeineCache implements org.apache.druid.client.cache.Cache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@LifecycleStop
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
cache.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public org.apache.druid.client.cache.CacheStats getStats()
|
public org.apache.druid.client.cache.CacheStats getStats()
|
||||||
{
|
{
|
||||||
|
@ -20,10 +20,13 @@
|
|||||||
package org.apache.druid.client.cache;
|
package org.apache.druid.client.cache;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import org.apache.druid.java.util.common.lifecycle.LifecycleStop;
|
||||||
import org.apache.druid.java.util.common.logger.Logger;
|
import org.apache.druid.java.util.common.logger.Logger;
|
||||||
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -127,8 +130,35 @@ public class HybridCache implements Cache
|
|||||||
@Override
|
@Override
|
||||||
public void close(String namespace)
|
public void close(String namespace)
|
||||||
{
|
{
|
||||||
level1.close(namespace);
|
Throwable t = null;
|
||||||
level2.close(namespace);
|
try {
|
||||||
|
level1.close(namespace);
|
||||||
|
}
|
||||||
|
catch (Throwable t1) {
|
||||||
|
t = t1;
|
||||||
|
throw t1;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (t != null) {
|
||||||
|
try {
|
||||||
|
level2.close(namespace);
|
||||||
|
}
|
||||||
|
catch (Throwable t2) {
|
||||||
|
t.addSuppressed(t2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
level2.close(namespace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@LifecycleStop
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
try (Closeable closeable1 = level1; Closeable closeable2 = level2) {
|
||||||
|
// Just for closing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,8 +20,10 @@
|
|||||||
package org.apache.druid.client.cache;
|
package org.apache.druid.client.cache;
|
||||||
|
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
|
import org.apache.druid.java.util.common.lifecycle.LifecycleStop;
|
||||||
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -144,6 +146,15 @@ public class MapCache implements Cache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@LifecycleStop
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
baseMap.clear();
|
||||||
|
byteCountingLRUMap.clear();
|
||||||
|
namespaceId.clear();
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] getNamespaceId(final String identifier)
|
private byte[] getNamespaceId(final String identifier)
|
||||||
{
|
{
|
||||||
synchronized (namespaceId) {
|
synchronized (namespaceId) {
|
||||||
|
@ -46,6 +46,7 @@ import org.apache.commons.codec.digest.DigestUtils;
|
|||||||
import org.apache.druid.collections.ResourceHolder;
|
import org.apache.druid.collections.ResourceHolder;
|
||||||
import org.apache.druid.collections.StupidResourceHolder;
|
import org.apache.druid.collections.StupidResourceHolder;
|
||||||
import org.apache.druid.java.util.common.StringUtils;
|
import org.apache.druid.java.util.common.StringUtils;
|
||||||
|
import org.apache.druid.java.util.common.lifecycle.LifecycleStop;
|
||||||
import org.apache.druid.java.util.common.logger.Logger;
|
import org.apache.druid.java.util.common.logger.Logger;
|
||||||
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
|
||||||
import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
|
import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
|
||||||
@ -596,6 +597,13 @@ public class MemcachedCache implements Cache
|
|||||||
// no resources to cleanup
|
// no resources to cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@LifecycleStop
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
monitor.stop();
|
||||||
|
}
|
||||||
|
|
||||||
public static final int MAX_PREFIX_LENGTH =
|
public static final int MAX_PREFIX_LENGTH =
|
||||||
MemcachedClientIF.MAX_KEY_LENGTH
|
MemcachedClientIF.MAX_KEY_LENGTH
|
||||||
- 40 // length of namespace hash
|
- 40 // length of namespace hash
|
||||||
|
@ -253,6 +253,11 @@ public class CachingQueryRunnerTest
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CacheStats getStats()
|
public CacheStats getStats()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user