From 275348d5240b3c3a7e5246af3aac316441aa1f28 Mon Sep 17 00:00:00 2001 From: Vasil Ilchev Date: Wed, 13 May 2026 11:51:29 +0300 Subject: [PATCH] Fix JdbcLockRegistry ttl (#3080) Signed-off-by: vasilchev --- .../repository/jpa/JpaRepositoryConfiguration.java | 7 +++++-- .../jpa/cluster/DistributedLockRepository.java | 12 ++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRepositoryConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRepositoryConfiguration.java index 9c823e4fa..82d3a5ada 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRepositoryConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRepositoryConfiguration.java @@ -9,6 +9,7 @@ */ package org.eclipse.hawkbit.repository.jpa; +import java.time.Duration; import java.util.List; import java.util.Optional; import java.util.concurrent.locks.Lock; @@ -211,8 +212,10 @@ public class JpaRepositoryConfiguration { @Bean @ConditionalOnMissingBean @SuppressWarnings("java:S1452") // it could be any LockRegistry - public LockRegistry lockRegistry(final Optional lockRepository) { - return lockRepository.> map(JdbcLockRegistry::new).orElseGet(DefaultLockRegistry::new); + public LockRegistry lockRegistry(final Optional lockRepository, final LockProperties lockProperties) { + return lockRepository.> map(repo -> + new JdbcLockRegistry(repo, Duration.ofMillis(lockProperties.getTtl())) + ).orElseGet(DefaultLockRegistry::new); } @Bean diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cluster/DistributedLockRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cluster/DistributedLockRepository.java index 72db9f1e4..b0cefe0b7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cluster/DistributedLockRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cluster/DistributedLockRepository.java @@ -9,6 +9,7 @@ */ package org.eclipse.hawkbit.repository.jpa.cluster; +import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Map; @@ -95,17 +96,16 @@ public class DistributedLockRepository extends DefaultLockRepository { } } + // Spring Integration 7.0 calls acquire(String, Duration) directly; the deprecated acquire(String) is no longer invoked + // by JdbcLockRegistry. Override the new method to populate lockToRefreshTime for the refresh mechanism. @Transactional(propagation = Propagation.NOT_SUPPORTED) @Override - public boolean acquire(final String lock) { + public boolean acquire(final String lock, final Duration ttl) { try { - // real acquisition (made by super.acquire) is made in a new transaction - // because we need to know real (after transaction commit) result Ïto know if it is really successful. - // otherwise the super.acquire will return result before been committed and could be false positive + // run in a new transaction so we know the committed result before updating lockToRefreshTime final boolean acquired = DeploymentHelper.runInNewTransaction( - txManager, "lock-acquire", Isolation.READ_COMMITTED.value(), status -> super.acquire(lock)); + txManager, "lock-acquire", Isolation.READ_COMMITTED.value(), status -> super.acquire(lock, ttl)); if (acquired) { - // update next refresh time refreshAfterMillis.ifPresent(afterMillis -> lockToRefreshTime.put(lock, Instant.now().plus(afterMillis, ChronoUnit.MILLIS))); } return acquired;