Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce leaseTime to 1500 milliseconds #1

Merged
merged 2 commits into from
Jun 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions redisson/src/main/java/org/redisson/jcache/JCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V> {
private static final RedisCommand<Boolean> EVAL_PUT_IF_ABSENT = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 7, ValueType.MAP);
private static final RedisCommand<Boolean> EVAL_REMOVE_KEY_VALUE = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 8, ValueType.MAP);
private static final RedisCommand<Boolean> EVAL_CONTAINS_KEY = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 6, ValueType.MAP_KEY);

private static final long LEASE_TIME = 1500;

private final JCacheManager cacheManager;
private final JCacheConfiguration<K, V> config;
Expand Down Expand Up @@ -313,7 +315,7 @@ private Long getAccessTimeout() {

V load(K key) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
V value = getValueLocked(key);
if (value == null) {
Expand Down Expand Up @@ -702,7 +704,7 @@ public void run() {
try {
if (!containsKey(key) || replaceExistingValues) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
if (!containsKey(key)|| replaceExistingValues) {
V value;
Expand Down Expand Up @@ -742,7 +744,7 @@ private RLock getLock(K key) {
private RLock getLockedLock(K key) {
String lockName = getLockName(key);
RLock lock = redisson.getLock(lockName);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
return lock;
}

Expand All @@ -760,7 +762,7 @@ public void put(K key, V value) {
long startTime = currentNanoTime();
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
List<Object> result = getAndPutValueLocked(key, value);
if (result.isEmpty()) {
Expand Down Expand Up @@ -970,7 +972,7 @@ public V getAndPut(K key, V value) {
long startTime = currentNanoTime();
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
List<Object> result = getAndPutValueLocked(key, value);
if (result.isEmpty()) {
Expand Down Expand Up @@ -1068,7 +1070,7 @@ public void putAll(Map<? extends K, ? extends V> map) {
long startTime = currentNanoTime();
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);

List<Object> result = getAndPutValue(key, value);
if (result.isEmpty()) {
Expand Down Expand Up @@ -1172,7 +1174,7 @@ public boolean putIfAbsent(K key, V value) {
long startTime = currentNanoTime();
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
boolean result = putIfAbsentValueLocked(key, value);
if (result) {
Expand Down Expand Up @@ -1254,7 +1256,7 @@ public boolean remove(K key) {
long startTime = System.currentTimeMillis();
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
V oldValue = getValue(key);
boolean result = removeValue(key);
Expand Down Expand Up @@ -1395,7 +1397,7 @@ public boolean remove(K key, V value) {
boolean result;
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
result = removeValueLocked(key, value);
if (result) {
Expand Down Expand Up @@ -1487,7 +1489,7 @@ public V getAndRemove(K key) {
long startTime = currentNanoTime();
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
Object value = getAndRemoveValue(key);
if (value != null) {
Expand Down Expand Up @@ -1690,7 +1692,7 @@ public boolean replace(K key, V oldValue, V newValue) {
long startTime = currentNanoTime();
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
long result = replaceValueLocked(key, oldValue, newValue);
if (result == 1) {
Expand Down Expand Up @@ -1934,7 +1936,7 @@ public boolean replace(K key, V value) {
long startTime = currentNanoTime();
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
boolean result = replaceValueLocked(key, value);
if (result) {
Expand Down Expand Up @@ -1988,7 +1990,7 @@ public V getAndReplace(K key, V value) {
long startTime = currentNanoTime();
if (config.isWriteThrough()) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
try {
V result = getAndReplaceValueLocked(key, value);
if (result != null) {
Expand Down Expand Up @@ -2046,7 +2048,7 @@ public void removeAll(Set<? extends K> keys) {
if (config.isWriteThrough()) {
for (K key : keys) {
RLock lock = getLock(key);
lock.lock(5, TimeUnit.SECONDS);
lock.lock(LEASE_TIME, TimeUnit.MILLISECONDS);
V result = getAndRemoveValue(key);
if (result != null) {
deletedKeys.put(key, result);
Expand Down