Skip to content

Commit

Permalink
PLT-191: update cache timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
n5nk committed Nov 28, 2023
1 parent 20c223f commit 90606b4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private EntryList get(KeySliceQuery query, Callable<EntryList> valueLoader) {
redisCache.fastPutAsync(query, fastConf.asByteArray(entries));
RLock lock = redisIndexKeys.getLock(query.getKey());
try {
lock.tryLock(1, 2, TimeUnit.SECONDS);
lock.tryLock(3, 10, TimeUnit.SECONDS);
ArrayList<KeySliceQuery> queryList = redisIndexKeys.get(query.getKey());
if (queryList == null)
queryList = new ArrayList<>();
Expand Down Expand Up @@ -182,7 +182,7 @@ public Map<StaticBuffer, EntryList> getSlice(final List<StaticBuffer> keys, fina
redisCache.fastPutAsync(ksqs[i], fastConf.asByteArray(subresult));
RLock lock = redisIndexKeys.getLock(ksqs[i].getKey());
try {
lock.tryLock(1, 2, TimeUnit.SECONDS);
lock.tryLock(3, 10, TimeUnit.SECONDS);
ArrayList<KeySliceQuery> queryList = redisIndexKeys.get(ksqs[i].getKey());
if (queryList == null)
queryList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Objects;

import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.*;

public class RedissonCache {

private static RedissonClient client;
private static final Logger log = LoggerFactory.getLogger(RedissonCache.class);
private static final String REDIS_URL_PREFIX = "redis://";
private static final String COMMA = ",";
Expand All @@ -44,47 +42,40 @@ public class RedissonCache {
private static long watchdogTimeoutInMS;

public static RedissonClient getRedissonClient(Configuration configuration) {
synchronized (RedissonClient.class) {
if (Objects.isNull(client)) {
redisServerMode = configuration.get(REDIS_CACHE_SERVER_MODE);
connectTimeout = configuration.get(REDIS_CACHE_CONNECTION_TIME_OUT);
keepAlive = configuration.get(REDIS_CACHE_KEEP_ALIVE);
watchdogTimeoutInMS = configuration.get(REDIS_CACHE_LOCK_WATCHDOG_TIMEOUT_MS);
log.info("Creating connection for redis:{}", redisServerMode);
System.out.println("Creating connection for redis:"+redisServerMode);
Config config = new Config();
switch (redisServerMode) {
case SENTINEL:
config.setLockWatchdogTimeout(watchdogTimeoutInMS)
.useSentinelServers()
.setClientName(JANUSGRAPH_REDIS)
.setReadMode(ReadMode.MASTER_SLAVE)
.setCheckSentinelsList(false)
.setConnectTimeout(connectTimeout)
.setKeepAlive(keepAlive)
.setMasterName(configuration.get(REDIS_CACHE_MASTER_NAME))
.addSentinelAddress(formatUrls(configuration.get(REDIS_CACHE_SENTINEL_URLS).split(COMMA)))
.setUsername(configuration.get(REDIS_CACHE_USERNAME))
.setPassword(configuration.get(REDIS_CACHE_PASSWORD));
break;
case STANDALONE:
config.setLockWatchdogTimeout(watchdogTimeoutInMS)
.useSingleServer()
.setClientName(JANUSGRAPH_REDIS)
.setAddress(formatUrls(configuration.get(REDIS_CACHE_SERVER_URL).split(COMMA))[0])
.setConnectTimeout(connectTimeout)
.setKeepAlive(keepAlive)
.setUsername(configuration.get(REDIS_CACHE_USERNAME))
.setPassword(configuration.get(REDIS_CACHE_PASSWORD));
break;
default:
throw new JanusGraphConfigurationException("Invalid redis server mode");
}
client = Redisson.create(config);
}
redisServerMode = configuration.get(REDIS_CACHE_SERVER_MODE);
connectTimeout = configuration.get(REDIS_CACHE_CONNECTION_TIME_OUT);
keepAlive = configuration.get(REDIS_CACHE_KEEP_ALIVE);
watchdogTimeoutInMS = configuration.get(REDIS_CACHE_LOCK_WATCHDOG_TIMEOUT_MS);
log.info("Creating connection for redis:{}", redisServerMode);
Config config = new Config();
switch (redisServerMode) {
case SENTINEL:
config.setLockWatchdogTimeout(watchdogTimeoutInMS)
.useSentinelServers()
.setClientName(JANUSGRAPH_REDIS)
.setReadMode(ReadMode.MASTER_SLAVE)
.setCheckSentinelsList(false)
.setConnectTimeout(connectTimeout)
.setKeepAlive(keepAlive)
.setMasterName(configuration.get(REDIS_CACHE_MASTER_NAME))
.addSentinelAddress(formatUrls(configuration.get(REDIS_CACHE_SENTINEL_URLS).split(COMMA)))
.setUsername(configuration.get(REDIS_CACHE_USERNAME))
.setPassword(configuration.get(REDIS_CACHE_PASSWORD));
break;
case STANDALONE:
config.setLockWatchdogTimeout(watchdogTimeoutInMS)
.useSingleServer()
.setClientName(JANUSGRAPH_REDIS)
.setAddress(formatUrls(configuration.get(REDIS_CACHE_SERVER_URL).split(COMMA))[0])
.setConnectTimeout(connectTimeout)
.setKeepAlive(keepAlive)
.setUsername(configuration.get(REDIS_CACHE_USERNAME))
.setPassword(configuration.get(REDIS_CACHE_PASSWORD));
break;
default:
throw new JanusGraphConfigurationException("Invalid redis server mode");
}

return client;
return Redisson.create(config);
}

private static String[] formatUrls(String[] urls) throws IllegalArgumentException {
Expand Down

0 comments on commit 90606b4

Please sign in to comment.