From f687438f04d5a16b948fbdf0d8111038d3c26dbb Mon Sep 17 00:00:00 2001 From: Myeonghyeon-Lee Date: Mon, 18 Sep 2023 23:39:37 +0900 Subject: [PATCH] GH-8730: Fix isAcquiredInThisProcess to use localLock The `ExpirableLockRegistry.expireUnusedOlderThan()` uses a query to the target store by mistake. The logic of this API is indeed about the local cache for those lock instances. We cannot effect any other processes with this cache. And even if we remove our local instance while it is locked in other process, that doesn't mean that on the next `obtain()` call, when we got a fresh local instance, we will be able to acquire a lock in target store. * Fix `isAcquiredInThisProcess()` to check only `localLock.isLocked()` **Cherry-pick to `6.1.x` & `6.0.x`** # Conflicts: # spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java --- .../integration/jdbc/lock/JdbcLockRegistry.java | 5 +++-- .../integration/redis/util/RedisLockRegistry.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java index f4f01af77a..e5f9b08a71 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/JdbcLockRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,7 @@ import org.springframework.util.Assert; * @author Olivier Hubaut * @author Fran Aranda * @author Unseok Kim + * @author Myeonghyeon Lee * * @since 4.3 */ @@ -310,7 +311,7 @@ public class JdbcLockRegistry implements ExpirableLockRegistry, RenewableLockReg } public boolean isAcquiredInThisProcess() { - return this.mutex.isAcquired(this.path); + return delegate.isLocked(); } public boolean renew() { diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java index ae4f68022a..713c2f17cf 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java @@ -83,6 +83,7 @@ import org.springframework.util.ReflectionUtils; * @author Unseok Kim * @author Anton Gabov * @author Eddie Cho + * @author Myeonghyeon Lee * * @since 4.0 * @@ -503,8 +504,7 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl } public final boolean isAcquiredInThisProcess() { - return RedisLockRegistry.this.clientId.equals( - RedisLockRegistry.this.redisTemplate.boundValueOps(this.lockKey).get()); + return this.localLock.isLocked(); } @Override