-
Notifications
You must be signed in to change notification settings - Fork 91
Add a withClockSkewUpperBound option when acquiring a lock #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tso
wants to merge
2
commits into
awslabs:master
Choose a base branch
from
tso:tso.0309.add-new-option-for-non-blocking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ public class AcquireLockOptions { | |
| private final Boolean acquireReleasedLocksConsistently; | ||
| private final Optional<SessionMonitor> sessionMonitor; | ||
| private final Boolean reentrant; | ||
| private final Optional<Long> clockSkewUpperBound; | ||
|
|
||
| /** | ||
| * Setting this flag to true will prevent the thread from being blocked (put to sleep) for the lease duration and | ||
|
|
@@ -72,6 +73,7 @@ public static class AcquireLockOptionsBuilder { | |
| private Boolean updateExistingLockRecord; | ||
| private Boolean acquireReleasedLocksConsistently; | ||
| private Boolean reentrant; | ||
| private Optional<Long> clockSkewUpperBound; | ||
|
|
||
| private long safeTimeWithoutHeartbeat; | ||
| private Optional<Runnable> sessionMonitorCallback; | ||
|
|
@@ -90,6 +92,7 @@ public static class AcquireLockOptionsBuilder { | |
| this.shouldSkipBlockingWait = false; | ||
| this.acquireReleasedLocksConsistently = false; | ||
| this.reentrant = false; | ||
| this.clockSkewUpperBound = Optional.empty();; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -256,6 +259,22 @@ public AcquireLockOptionsBuilder withReentrant(final boolean reentrant) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * In combination with withShouldSkipBlockingWait(true) this allows a node to rely on a lastTouchedAt value on the DynamoDb | ||
| * entry to take over locks which have expired but have not been deleted or marked as released within DynamoDb (which can occur | ||
| * due to an ungraceful shutdown of the owning node). | ||
| * | ||
| * It's critically important that this error bound is accurate to the nodes that are relying on the lock client. If not, | ||
| * correctness problems can occur. | ||
| * | ||
| * @param clockSkewUpperBound the upper error bound of clock skew across the nodes running this client | ||
|
||
| * @return a reference to this builder for fluent method chaining | ||
| */ | ||
| public AcquireLockOptionsBuilder withClockSkewUpperBound(final Long clockSkewUpperBound) { | ||
| this.clockSkewUpperBound = Optional.ofNullable(clockSkewUpperBound); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * Registers a "SessionMonitor." | ||
|
|
@@ -333,7 +352,7 @@ public AcquireLockOptions build() { | |
| } | ||
| return new AcquireLockOptions(this.partitionKey, this.sortKey, this.data, this.replaceData, this.deleteLockOnRelease, this.acquireOnlyIfLockAlreadyExists, | ||
| this.refreshPeriod, this.additionalTimeToWaitForLock, this.timeUnit, this.additionalAttributes, sessionMonitor, | ||
| this.updateExistingLockRecord, this.shouldSkipBlockingWait, this.acquireReleasedLocksConsistently, this.reentrant); | ||
| this.updateExistingLockRecord, this.shouldSkipBlockingWait, this.acquireReleasedLocksConsistently, this.reentrant, this.clockSkewUpperBound); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -342,7 +361,8 @@ public String toString() { | |
| + this.replaceData + ", deleteLockOnRelease=" + this.deleteLockOnRelease + ", refreshPeriod=" + this.refreshPeriod + ", additionalTimeToWaitForLock=" | ||
| + this.additionalTimeToWaitForLock + ", timeUnit=" + this.timeUnit + ", additionalAttributes=" + this.additionalAttributes + ", safeTimeWithoutHeartbeat=" | ||
| + this.safeTimeWithoutHeartbeat + ", sessionMonitorCallback=" + this.sessionMonitorCallback + ", acquireReleasedLocksConsistently=" | ||
| + this.acquireReleasedLocksConsistently + ", reentrant=" + this.reentrant+ ")"; | ||
| + this.acquireReleasedLocksConsistently + ", reentrant=" + this.reentrant+ ", this.clockSkewUpperBound=" + this.clockSkewUpperBound | ||
| + ")"; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -360,7 +380,8 @@ public static AcquireLockOptionsBuilder builder(final String partitionKey) { | |
| private AcquireLockOptions(final String partitionKey, final Optional<String> sortKey, final Optional<ByteBuffer> data, final Boolean replaceData, | ||
| final Boolean deleteLockOnRelease, final Boolean acquireOnlyIfLockAlreadyExists, final Long refreshPeriod, final Long additionalTimeToWaitForLock, | ||
| final TimeUnit timeUnit, final Map<String, AttributeValue> additionalAttributes, final Optional<SessionMonitor> sessionMonitor, | ||
| final Boolean updateExistingLockRecord, final Boolean shouldSkipBlockingWait, final Boolean acquireReleasedLocksConsistently, Boolean reentrant) { | ||
| final Boolean updateExistingLockRecord, final Boolean shouldSkipBlockingWait, final Boolean acquireReleasedLocksConsistently, Boolean reentrant, | ||
| final Optional<Long> clockSkewUpperBound) { | ||
| this.partitionKey = partitionKey; | ||
| this.sortKey = sortKey; | ||
| this.data = data; | ||
|
|
@@ -376,6 +397,7 @@ private AcquireLockOptions(final String partitionKey, final Optional<String> sor | |
| this.shouldSkipBlockingWait = shouldSkipBlockingWait; | ||
| this.acquireReleasedLocksConsistently = acquireReleasedLocksConsistently; | ||
| this.reentrant = reentrant; | ||
| this.clockSkewUpperBound = clockSkewUpperBound; | ||
| } | ||
|
|
||
| String getPartitionKey() { | ||
|
|
@@ -424,6 +446,8 @@ Boolean getReentrant() { | |
| return this.reentrant; | ||
| } | ||
|
|
||
| Optional<Long> getClockSkewUpperBound() { return this.clockSkewUpperBound; } | ||
|
|
||
| Map<String, AttributeValue> getAdditionalAttributes() { | ||
| return this.additionalAttributes; | ||
| } | ||
|
|
@@ -460,15 +484,16 @@ public boolean equals(final Object other) { | |
| && Objects.equals(this.updateExistingLockRecord, otherOptions.updateExistingLockRecord) | ||
| && Objects.equals(this.shouldSkipBlockingWait, otherOptions.shouldSkipBlockingWait) | ||
| && Objects.equals(this.acquireReleasedLocksConsistently, otherOptions.acquireReleasedLocksConsistently) | ||
| && Objects.equals(this.reentrant, otherOptions.reentrant); | ||
| && Objects.equals(this.reentrant, otherOptions.reentrant) | ||
| && Objects.equals(this.clockSkewUpperBound, otherOptions.clockSkewUpperBound); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(this.partitionKey, this.sortKey, this.data, this.replaceData, this.deleteLockOnRelease, | ||
| this.acquireOnlyIfLockAlreadyExists, this.refreshPeriod, this.additionalTimeToWaitForLock, this.timeUnit, | ||
| this.additionalAttributes, this.sessionMonitor, this.updateExistingLockRecord, | ||
| this.shouldSkipBlockingWait, this.acquireReleasedLocksConsistently, this.reentrant); | ||
| this.shouldSkipBlockingWait, this.acquireReleasedLocksConsistently, this.reentrant, this.clockSkewUpperBound); | ||
|
|
||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra
;