Fix DynamoDbLockRegistry for additionalTimeToWait
Fixes https://github.com/spring-cloud/spring-cloud-stream-binder-aws-kinesis/issues/186 The `DynamoDbLockClient` waits extra `leaseDuration` time in a loop breaking a `tryLock()` contract. * Fix `DynamoDbLockRegistry.tryLock()` to decrease an actual `additionalTimeToWait` by `leaseDuration`, so the target `DynamoDbLockClient` when it adds this `leaseDuration` will wait an actual timeout requested by the `tryLock()` contract. This way a `tryLock(0)` will definitely return immediately since we really are not interested in blocking **cherry-pick to 2.5.x**
This commit is contained in:
@@ -198,7 +198,7 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a period in milliseconds how often send locks renewal requests called heartbeat.
|
||||
* Specify a period in seconds how often send locks renewal requests called heartbeat.
|
||||
* When the value is less than or equal to {@code 0}, the heartbeat is disabled.
|
||||
* @param heartbeatPeriod the heartbeat period for background thread to renew locks in DB
|
||||
*/
|
||||
@@ -501,8 +501,9 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing
|
||||
return false;
|
||||
}
|
||||
|
||||
long additionalTimeToWait = Math
|
||||
.max(TimeUnit.MILLISECONDS.convert(time, unit) - System.currentTimeMillis() + start, 0L);
|
||||
long additionalTimeToWait =
|
||||
TimeUnit.MILLISECONDS.convert(time, unit)
|
||||
- System.currentTimeMillis() + start - DynamoDbLockRegistry.this.leaseDuration;
|
||||
|
||||
this.acquireLockOptionsBuilder.withAdditionalTimeToWaitForLock(additionalTimeToWait);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user