GH-97: wait at least leaseDuration to acquire the lock

Fixes https://github.com/spring-projects/spring-integration-aws/issues/97

This fixes an issue where `additionalTimeToWait` has a negative value
that is subtracted later by the Amazon DynamoDB client to
`leaseDuration`, making it impossible to acquire the lock if expired.

Also allow to use the existing `refreshPeriod` properties in this case.

* Use default refresh period in tryLock()

The 'refreshPeriod' value might not satisfy both tryLock() and lock()
requirements and should probably be used exclusively in the second case.

We can make the value used for tryLock() configurable as well in another
pull request.

* Rollback previous commit and add author name
This commit is contained in:
Karl Lessard
2018-09-21 15:46:04 -04:00
committed by Artem Bilan
parent 857d184cca
commit ed89f1243f

View File

@@ -60,6 +60,7 @@ import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
* Can create table in DynamoDB if an external {@link AmazonDynamoDBLockClient} is not provided.
*
* @author Artem Bilan
* @author Karl Lessard
*
* @since 2.0
*/
@@ -467,11 +468,11 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing
return false;
}
long additionalTimeToWait = TimeUnit.MILLISECONDS.convert(time, unit) - System.currentTimeMillis() + start;
long additionalTimeToWait = Math.max(TimeUnit.MILLISECONDS.convert(time, unit) - System.currentTimeMillis() + start, 0L);
this.acquireLockOptionsBuilder
.withAdditionalTimeToWaitForLock(additionalTimeToWait)
.withRefreshPeriod(0L);
.withRefreshPeriod(DynamoDbLockRegistry.this.refreshPeriod);
boolean acquired = false;
try {