diff --git a/docs/configs/janusgraph-cfg.md b/docs/configs/janusgraph-cfg.md index ef199e30200..c7b2d34f43c 100644 --- a/docs/configs/janusgraph-cfg.md +++ b/docs/configs/janusgraph-cfg.md @@ -27,6 +27,8 @@ Configuration options that modify JanusGraph's caching behavior | cache.db-cache-time | Default expiration time, in milliseconds, for entries in the database-level cache. Entries are evicted when they reach this age even if the cache has room to spare. Set to 0 to disable expiration (cache entries live forever or until memory pressure triggers eviction when set to 0). | Long | 10000 | GLOBAL_OFFLINE | | cache.redis-cache-connectTimeout | Timeout during connecting to any Redis server. | Integer | 1000 | MASKABLE | | cache.redis-cache-keepAlive | Enables TCP keepAlive for connection. | Boolean | true | MASKABLE | +| cache.redis-cache-lease-ms | If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired. If the lock is acquired, it is held until unlock is invoked, or until leaseTime milliseconds have passed since the lock was granted - whichever comes first | Integer | 2000 | MASKABLE | +| cache.redis-cache-lock-wait-ms | The maximum time (in millisec) to aquire the lock. | Integer | 1000 | MASKABLE | | cache.redis-cache-lock-watchdog-ms | This prevents against infinity locked locks due to Redisson client crush or any other reason when lock can't be released in proper way. | Long | 600000 | MASKABLE | | cache.redis-cache-mastername | Master server name used by Redis Sentinel servers and master change monitoring task. | String | mymaster | MASKABLE | | cache.redis-cache-password | Password for Redis authentication. | String | password | MASKABLE | diff --git a/janusgraph-all/pom.xml b/janusgraph-all/pom.xml index 57912d39827..6649c27ac19 100644 --- a/janusgraph-all/pom.xml +++ b/janusgraph-all/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-all diff --git a/janusgraph-backend-testutils/pom.xml b/janusgraph-backend-testutils/pom.xml index 82ac83f9f82..6957f402891 100644 --- a/janusgraph-backend-testutils/pom.xml +++ b/janusgraph-backend-testutils/pom.xml @@ -4,7 +4,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-backend-testutils diff --git a/janusgraph-berkeleyje/pom.xml b/janusgraph-berkeleyje/pom.xml index 797fb7e670f..7f5b856a8ae 100644 --- a/janusgraph-berkeleyje/pom.xml +++ b/janusgraph-berkeleyje/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-berkeleyje diff --git a/janusgraph-bigtable/pom.xml b/janusgraph-bigtable/pom.xml index 6d1aae5a1a4..f90a7ebaf96 100644 --- a/janusgraph-bigtable/pom.xml +++ b/janusgraph-bigtable/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-bigtable diff --git a/janusgraph-core/pom.xml b/janusgraph-core/pom.xml index e071f65fc94..c6684f706d8 100644 --- a/janusgraph-core/pom.xml +++ b/janusgraph-core/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-core diff --git a/janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/cache/ExpirationKCVSRedisCache.java b/janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/cache/ExpirationKCVSRedisCache.java index dd1932be954..b292cd76eee 100644 --- a/janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/cache/ExpirationKCVSRedisCache.java +++ b/janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/cache/ExpirationKCVSRedisCache.java @@ -42,6 +42,8 @@ import java.util.logging.Logger; import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CACHE_KEYSPACE_PREFIX; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_LOCK_LEASE_MS; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_LOCK_WAIT_MS; import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_MAX_CACHE_SIZE; /** @@ -56,10 +58,12 @@ public class ExpirationKCVSRedisCache extends KCVSCache { private RMapCache> redisIndexKeys; private static Logger logger = Logger.getLogger("janusgraph-redis-logger"); private static FSTConfiguration fastConf = FSTConfiguration.createDefaultConfiguration(); + private Configuration configuration; public ExpirationKCVSRedisCache(final KeyColumnValueStore store, String metricsName, final long cacheTimeMS, final long invalidationGracePeriodMS, Configuration configuration) { super(store, metricsName); + this.configuration = configuration; Preconditions.checkArgument(cacheTimeMS > 0, "Cache expiration must be positive: %s", cacheTimeMS); Preconditions.checkArgument(System.currentTimeMillis() + 1000L * 3600 * 24 * 365 * 100 + cacheTimeMS > 0, "Cache expiration time too large, overflow may occur: %s", cacheTimeMS); this.cacheTimeMS = cacheTimeMS; @@ -101,7 +105,7 @@ private EntryList get(KeySliceQuery query, Callable valueLoader) thro redisCache.fastPutAsync(query, fastConf.asByteArray(entries), this.cacheTimeMS, TimeUnit.MILLISECONDS); RLock lock = redisIndexKeys.getLock(query.getKey()); try { - lock.tryLock(1, 3, TimeUnit.SECONDS); + lock.tryLock(this.configuration.get(REDIS_CACHE_LOCK_WAIT_MS), this.configuration.get(REDIS_CACHE_LOCK_LEASE_MS), TimeUnit.MILLISECONDS); ArrayList queryList = redisIndexKeys.get(query.getKey()); if (queryList == null) queryList = new ArrayList<>(); @@ -154,7 +158,7 @@ public Map getSlice(final List keys, fina redisCache.fastPutAsync(ksqs[i], fastConf.asByteArray(subresult), this.cacheTimeMS, TimeUnit.MILLISECONDS); RLock lock = redisIndexKeys.getLock(ksqs[i].getKey()); try { - lock.tryLock(3, 10, TimeUnit.SECONDS); + lock.tryLock(this.configuration.get(REDIS_CACHE_LOCK_WAIT_MS), this.configuration.get(REDIS_CACHE_LOCK_LEASE_MS), TimeUnit.MILLISECONDS); ArrayList queryList = redisIndexKeys.get(ksqs[i].getKey()); if (queryList == null) queryList = new ArrayList<>(); diff --git a/janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/cache/RedissonCache.java b/janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/cache/RedissonCache.java index 6053a4be818..e5de6b23fb0 100644 --- a/janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/cache/RedissonCache.java +++ b/janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/cache/RedissonCache.java @@ -25,12 +25,24 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; +import java.util.Objects; -import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.*; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_CONNECTION_TIME_OUT; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_KEEP_ALIVE; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_LOCK_WATCHDOG_TIMEOUT_MS; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_MASTER_NAME; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_PASSWORD; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_SENTINEL_URLS; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_SERVER_MODE; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_SERVER_URL; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CACHE_USERNAME; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_CLIENT_NAME; +import static org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.REDIS_DATABASE_ID; public class RedissonCache { private static final Logger log = LoggerFactory.getLogger(RedissonCache.class); + private static RedissonClient client; private static final String REDIS_URL_PREFIX = "redis://"; private static final String COMMA = ","; private static final String SENTINEL = "sentinel"; @@ -41,41 +53,47 @@ public class RedissonCache { private static long watchdogTimeoutInMS; public static RedissonClient getRedissonClient(Configuration configuration) { - 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() - .setDatabase(configuration.get(REDIS_DATABASE_ID)) - .setClientName(configuration.get(REDIS_CLIENT_NAME)) - .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(configuration.get(REDIS_CLIENT_NAME)) - .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"); + synchronized (RedissonCache.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); + Config config = new Config(); + switch (redisServerMode) { + case SENTINEL: + config.setLockWatchdogTimeout(watchdogTimeoutInMS) + .useSentinelServers() + .setDatabase(configuration.get(REDIS_DATABASE_ID)) + .setClientName(String.join("-",configuration.get(REDIS_CLIENT_NAME),"janusgraph")) + .setReadMode(ReadMode.MASTER_SLAVE) + .setCheckSentinelsList(false) + .setConnectTimeout(connectTimeout) + .setIdleConnectionTimeout(5_000) + .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(configuration.get(REDIS_CLIENT_NAME)) + .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); + } } - return Redisson.create(config); + return client; } private static String[] formatUrls(String[] urls) throws IllegalArgumentException { diff --git a/janusgraph-core/src/main/java/org/janusgraph/graphdb/configuration/GraphDatabaseConfiguration.java b/janusgraph-core/src/main/java/org/janusgraph/graphdb/configuration/GraphDatabaseConfiguration.java index e58a7e28e26..be7039dd003 100644 --- a/janusgraph-core/src/main/java/org/janusgraph/graphdb/configuration/GraphDatabaseConfiguration.java +++ b/janusgraph-core/src/main/java/org/janusgraph/graphdb/configuration/GraphDatabaseConfiguration.java @@ -418,6 +418,17 @@ public boolean apply(@Nullable String s) { "Maximum cache (map) size in redis, set 0 to unbound, default value is 100. Keys are evicted based on LFU mode.", ConfigOption.Type.MASKABLE, 100); + public static final ConfigOption REDIS_CACHE_LOCK_WAIT_MS = new ConfigOption<>(CACHE_NS,"redis-cache-lock-wait-ms", + "The maximum time (in millisec) to aquire the lock.", + ConfigOption.Type.MASKABLE, 1000); + + + public static final ConfigOption REDIS_CACHE_LOCK_LEASE_MS = new ConfigOption<>(CACHE_NS,"redis-cache-lease-ms", + "If the lock is not available then the current thread becomes disabled for thread scheduling purposes " + + "and lies dormant until the lock has been acquired. If the lock is acquired, it is held until unlock is invoked, " + + "or until leaseTime milliseconds have passed since the lock was granted - whichever comes first", + ConfigOption.Type.MASKABLE, 2000); + /** * The size of the database level cache. * If this value is between 0.0 (strictly bigger) and 1.0 (strictly smaller), then it is interpreted as a diff --git a/janusgraph-cql/pom.xml b/janusgraph-cql/pom.xml index 5e9ccb84dc7..211fbc2c26d 100644 --- a/janusgraph-cql/pom.xml +++ b/janusgraph-cql/pom.xml @@ -4,7 +4,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 janusgraph-cql diff --git a/janusgraph-dist/pom.xml b/janusgraph-dist/pom.xml index d357005e44c..67bad8b7409 100644 --- a/janusgraph-dist/pom.xml +++ b/janusgraph-dist/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml pom diff --git a/janusgraph-doc/pom.xml b/janusgraph-doc/pom.xml index ad26204cbf7..e0d67a4fe3a 100644 --- a/janusgraph-doc/pom.xml +++ b/janusgraph-doc/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml pom diff --git a/janusgraph-driver/pom.xml b/janusgraph-driver/pom.xml index 024b28e544f..ce7d03f83f3 100644 --- a/janusgraph-driver/pom.xml +++ b/janusgraph-driver/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-driver diff --git a/janusgraph-es/pom.xml b/janusgraph-es/pom.xml index 8cb96f77035..6e5772304b2 100644 --- a/janusgraph-es/pom.xml +++ b/janusgraph-es/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-es diff --git a/janusgraph-examples/example-berkeleyje/pom.xml b/janusgraph-examples/example-berkeleyje/pom.xml index 6585fe993df..43bb887ba8a 100644 --- a/janusgraph-examples/example-berkeleyje/pom.xml +++ b/janusgraph-examples/example-berkeleyje/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph-examples - 0.6.02 + 0.6.03 ../pom.xml example-berkeleyje diff --git a/janusgraph-examples/example-common/pom.xml b/janusgraph-examples/example-common/pom.xml index c65f5ce6e0e..28d27bf1e0a 100644 --- a/janusgraph-examples/example-common/pom.xml +++ b/janusgraph-examples/example-common/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph-examples - 0.6.02 + 0.6.03 ../pom.xml example-common diff --git a/janusgraph-examples/example-cql/pom.xml b/janusgraph-examples/example-cql/pom.xml index 0ed4d687aa0..477469e77c8 100644 --- a/janusgraph-examples/example-cql/pom.xml +++ b/janusgraph-examples/example-cql/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph-examples - 0.6.02 + 0.6.03 ../pom.xml example-cql diff --git a/janusgraph-examples/example-hbase/pom.xml b/janusgraph-examples/example-hbase/pom.xml index 016216d0f22..e1018a59e4b 100644 --- a/janusgraph-examples/example-hbase/pom.xml +++ b/janusgraph-examples/example-hbase/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph-examples - 0.6.02 + 0.6.03 ../pom.xml example-hbase diff --git a/janusgraph-examples/example-remotegraph/pom.xml b/janusgraph-examples/example-remotegraph/pom.xml index a91d59c884a..8e6916f9382 100644 --- a/janusgraph-examples/example-remotegraph/pom.xml +++ b/janusgraph-examples/example-remotegraph/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph-examples - 0.6.02 + 0.6.03 ../pom.xml example-remotegraph diff --git a/janusgraph-examples/example-tinkergraph/pom.xml b/janusgraph-examples/example-tinkergraph/pom.xml index 6ec390f6cf6..f036029b330 100644 --- a/janusgraph-examples/example-tinkergraph/pom.xml +++ b/janusgraph-examples/example-tinkergraph/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph-examples - 0.6.02 + 0.6.03 ../pom.xml example-tinkergraph diff --git a/janusgraph-examples/pom.xml b/janusgraph-examples/pom.xml index 79d677a0b22..2eae8f59475 100644 --- a/janusgraph-examples/pom.xml +++ b/janusgraph-examples/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-examples diff --git a/janusgraph-grpc/pom.xml b/janusgraph-grpc/pom.xml index c2813ad38f1..dfc5cebb009 100644 --- a/janusgraph-grpc/pom.xml +++ b/janusgraph-grpc/pom.xml @@ -4,7 +4,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 janusgraph-grpc JanusGraph-gRPC: gRPC Components for JanusGraph diff --git a/janusgraph-hadoop/pom.xml b/janusgraph-hadoop/pom.xml index 7de7bfeba52..3d525bd4b6b 100644 --- a/janusgraph-hadoop/pom.xml +++ b/janusgraph-hadoop/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-hadoop diff --git a/janusgraph-hbase/pom.xml b/janusgraph-hbase/pom.xml index 0dcd8caddd8..6a9a0a9c980 100644 --- a/janusgraph-hbase/pom.xml +++ b/janusgraph-hbase/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 janusgraph-hbase JanusGraph-HBase: Distributed Graph Database diff --git a/janusgraph-inmemory/pom.xml b/janusgraph-inmemory/pom.xml index 48146094f27..560a7fda5e4 100644 --- a/janusgraph-inmemory/pom.xml +++ b/janusgraph-inmemory/pom.xml @@ -4,7 +4,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-inmemory diff --git a/janusgraph-lucene/pom.xml b/janusgraph-lucene/pom.xml index 47733fd64d7..40c9f385a88 100644 --- a/janusgraph-lucene/pom.xml +++ b/janusgraph-lucene/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-lucene diff --git a/janusgraph-server/pom.xml b/janusgraph-server/pom.xml index e457a948de1..06f122ed05f 100644 --- a/janusgraph-server/pom.xml +++ b/janusgraph-server/pom.xml @@ -4,7 +4,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 janusgraph-server JanusGraph-Server: Server Components for JanusGraph diff --git a/janusgraph-solr/pom.xml b/janusgraph-solr/pom.xml index c8088831dcd..a4b5f89b8a8 100644 --- a/janusgraph-solr/pom.xml +++ b/janusgraph-solr/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-solr diff --git a/janusgraph-test/pom.xml b/janusgraph-test/pom.xml index 0c7b35c2cbb..09e853b8012 100644 --- a/janusgraph-test/pom.xml +++ b/janusgraph-test/pom.xml @@ -3,7 +3,7 @@ org.janusgraph janusgraph - 0.6.02 + 0.6.03 ../pom.xml janusgraph-test diff --git a/pom.xml b/pom.xml index 6b92c60a352..e3ef6d53a9c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.janusgraph janusgraph - 0.6.02 + 0.6.03 pom 3.0.0