Skip to content

Commit fada45c

Browse files
committed
add leaseTime in redis locks
1 parent bc5b613 commit fada45c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

common/src/main/java/org/apache/atlas/service/redis/AbstractRedisService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ public abstract class AbstractRedisService implements RedisService {
2727
private static final String ATLAS_REDIS_MASTER_NAME = "atlas.redis.master_name";
2828
private static final String ATLAS_REDIS_LOCK_WAIT_TIME_MS = "atlas.redis.lock.wait_time.ms";
2929
private static final String ATLAS_REDIS_LOCK_WATCHDOG_TIMEOUT_MS = "atlas.redis.lock.watchdog_timeout.ms";
30+
private static final String ATLAS_REDIS_LEASE_TIME_MS = "atlas.redis.lease_time.ms";
3031
private static final int DEFAULT_REDIS_WAIT_TIME_MS = 15_000;
3132
private static final int DEFAULT_REDIS_LOCK_WATCHDOG_TIMEOUT_MS = 600_000;
33+
private static final int DEFAULT_REDIS_LEASE_TIME_MS = 60_000;
3234
private static final String ATLAS_METASTORE_SERVICE = "atlas-metastore-service";
3335

3436
RedissonClient redisClient;
3537
RedissonClient redisCacheClient;
3638
Map<String, RLock> keyLockMap;
3739
Configuration atlasConfig;
3840
long waitTimeInMS;
41+
long leaseTimeInMS;
3942
long watchdogTimeoutInMS;
4043

4144
@Override
@@ -44,7 +47,7 @@ public boolean acquireDistributedLock(String key) throws Exception {
4447
boolean isLockAcquired;
4548
try {
4649
RLock lock = redisClient.getFairLock(key);
47-
isLockAcquired = lock.tryLock(waitTimeInMS, TimeUnit.MILLISECONDS);
50+
isLockAcquired = lock.tryLock(waitTimeInMS, leaseTimeInMS, TimeUnit.MILLISECONDS);
4851
if (isLockAcquired) {
4952
keyLockMap.put(key, lock);
5053
} else {
@@ -57,16 +60,18 @@ public boolean acquireDistributedLock(String key) throws Exception {
5760
return isLockAcquired;
5861
}
5962

63+
6064
@Override
6165
public void releaseDistributedLock(String key) {
62-
if (!keyLockMap.containsKey(key)) {
63-
return;
64-
}
66+
if (!keyLockMap.containsKey(key)) {
67+
return;
68+
}
6569
try {
6670
RLock lock = keyLockMap.get(key);
6771
if (lock.isHeldByCurrentThread()) {
6872
lock.unlock();
6973
}
74+
7075
} catch (Exception e) {
7176
getLogger().error("Failed to release distributed lock for {}", key, e);
7277
}
@@ -106,6 +111,7 @@ private Config initAtlasConfig() throws AtlasException {
106111
keyLockMap = new ConcurrentHashMap<>();
107112
atlasConfig = ApplicationProperties.get();
108113
waitTimeInMS = atlasConfig.getLong(ATLAS_REDIS_LOCK_WAIT_TIME_MS, DEFAULT_REDIS_WAIT_TIME_MS);
114+
leaseTimeInMS = atlasConfig.getLong(ATLAS_REDIS_LEASE_TIME_MS, DEFAULT_REDIS_LEASE_TIME_MS);
109115
watchdogTimeoutInMS = atlasConfig.getLong(ATLAS_REDIS_LOCK_WATCHDOG_TIMEOUT_MS, DEFAULT_REDIS_LOCK_WATCHDOG_TIMEOUT_MS);
110116
Config redisConfig = new Config();
111117
redisConfig.setLockWatchdogTimeout(watchdogTimeoutInMS);

webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ public AtlasTypesDef updateAtlasTypeDefs(final AtlasTypesDef typesDef, @QueryPar
513513
throw new AtlasBaseException("Error while updating a type definition");
514514
} finally {
515515
RequestContext.clear();
516-
redisService.releaseDistributedLock(ATLAS_TYPEDEF_LOCK);
517516
AtlasPerfTracer.log(perf);
518517
}
519518
}

0 commit comments

Comments
 (0)