From 68ad0addc773e12d83162485995b8f817160383f Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Wed, 4 Nov 2020 10:55:52 +0300 Subject: [PATCH] =?UTF-8?q?Revert=20"Avoid=20redisson=20fair=20lock=20bloc?= =?UTF-8?q?king=20if=20there=20are=20lots=20of=20registered=20thr=E2=80=A6?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/redisson/RedissonFairLock.java | 16 ------ .../org/redisson/RedissonFairLockTest.java | 57 ------------------- 2 files changed, 73 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonFairLock.java b/redisson/src/main/java/org/redisson/RedissonFairLock.java index b6f973efc..fa8077746 100644 --- a/redisson/src/main/java/org/redisson/RedissonFairLock.java +++ b/redisson/src/main/java/org/redisson/RedissonFairLock.java @@ -201,22 +201,6 @@ public class RedissonFairLock extends RedissonLock implements RLock { "return nil;" + "end;" + - - // check if the lock is not held, and other queues are not used - "while true do " + - "local firstThreadId = redis.call('lindex', KEYS[2], 0);" + - "if (firstThreadId == false) or (firstThreadId == ARGV[2]) then " + - "break;"+ - "end;" + - "local timeout = tonumber(redis.call('zscore', KEYS[3], firstThreadId));" + - "if (timeout > tonumber(ARGV[4])) and (redis.call('exists', KEYS[1]) == 0) then " + - "redis.call('lpop', KEYS[2]);" + - "redis.call('zrem', KEYS[3], firstThreadId);" + - "else " + - "break;" + - "end;" + - "end;" + - // the lock cannot be acquired // check if the thread is already in the queue "local timeout = redis.call('zscore', KEYS[3], ARGV[2]);" + diff --git a/redisson/src/test/java/org/redisson/RedissonFairLockTest.java b/redisson/src/test/java/org/redisson/RedissonFairLockTest.java index 96a7e9661..922ee84d7 100644 --- a/redisson/src/test/java/org/redisson/RedissonFairLockTest.java +++ b/redisson/src/test/java/org/redisson/RedissonFairLockTest.java @@ -933,62 +933,5 @@ public class RedissonFairLockTest extends BaseConcurrentTest { await().atMost(30, TimeUnit.SECONDS).until(() -> lockedCounter.get() == totalThreads); } - @Test - public void testLockBlock() throws InterruptedException{ - Config cfg = createConfig(); - cfg.setLockWatchdogTimeout(30000); - RedissonClient redisson = Redisson.create(cfg); - int totalExecutorCount = 5; - int totalThreadCount = 100; - int interval = 1000; - Lock lock = redisson.getFairLock("testLockBlock"); - for (int count = 0; count < totalExecutorCount; count++) { - ExecutorService executor = Executors.newFixedThreadPool(totalThreadCount); - for (int i = 0; i < totalThreadCount; i++) { - final int finalI = i; - executor.submit(() -> { - log.info("running " + finalI + " in thread " + Thread.currentThread().getId()); - try { - lock.lock(); - log.info("Thread " + finalI + " got lock"); - } catch (Exception ex) { - log.error("Failed to get lock"); - } finally { - lock.unlock(); - } - }); - } - executor.shutdownNow(); - } - redisson.shutdown(); - - // In case connection closed - redisson = Redisson.create(cfg); - long timeOut = redisson.getConfig().getLockWatchdogTimeout() + interval; - ExecutorService lockExecutor = Executors.newFixedThreadPool(1); - Lock lockSecond = redisson.getFairLock("testLockBlock"); - Future future = lockExecutor.submit(new Callable() { - @Override - public Boolean call() throws Exception { - // check if this lock can be acquired in short time - Thread.sleep(timeOut); - lockSecond.lock(); - return Boolean.TRUE; - } - }); - - Boolean got = Boolean.FALSE; - try{ - got = future.get(timeOut + interval, TimeUnit.MILLISECONDS); - if (got) { - log.info("Got lock immediately after startup"); - }else{ - log.info("Failed to get lock due to blocked"); - } - }catch (Exception e){ - log.info("Failed to get lock due to blocked"); - } - Assert.assertTrue(got); - } } -- GitLab