Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
[Named min timestamp leases] Post merge review #7385
Browse files Browse the repository at this point in the history
  • Loading branch information
ergo14 committed Oct 31, 2024
1 parent 9183a9d commit 4826b68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private AsyncTimelockService getServiceForNamespace(Namespace namespace, @Nullab
}

private static ListenableFuture<TimestampLeaseResponses> acquireTimestampLease(
AsyncTimelockService service, RequestId requestsId, Map<TimestampLeaseName, Integer> numFreshTimestamps) {
return service.acquireTimestampLease(requestsId.get(), numFreshTimestamps);
AsyncTimelockService service, RequestId requestId, Map<TimestampLeaseName, Integer> numFreshTimestamps) {
return service.acquireTimestampLease(requestId.get(), numFreshTimestamps);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ private AsyncResult<HeldLocks> acquireNamedTimestampLocksInternal(
List<AsyncLock> locks = timestampNames.stream()
.map(name -> lockManager.getNamedTimestampLock(name, timestamp))
.collect(Collectors.toList());
// for these locks, each descriptor has a unique timestamp appended to it which means
// the individual locks do not contend with another thus eliminating the risk of deadlock
return lockAcquirer.acquireLocks(requestId, OrderedLocks.fromOrderedList(locks), TimeLimit.zero());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public void unlockingWithRequestIdFromAcquireTimestampLeaseResponseUnlocksForAll

TimestampedInvocation<TimestampLeaseResponses> responses =
acquireTimestampLeaseTimestamped(TIMESTAMP_NAME_1, 10, TIMESTAMP_NAME_2, 20);
assertThatTimestampsIsStrictlyWithinInvocationInterval(getMinLeasedTimestampsFrom(responses.result), responses);
assertThatTimestampsAreStrictlyWithinInvocationInterval(
getMinLeasedTimestampsFrom(responses.result), responses);

unlockForResponse(responses.result);
assertThatTimestampIsStrictlyWithinInvocationInterval(timestamp1MinLeased1.result, timestamp1MinLeased1);
Expand All @@ -90,21 +91,25 @@ public void acquireTimestampLeaseReturnsLeaseGuaranteeIdentifierWithGivenRequest
public void acquireTimestampLeaseReturnsMinLeasedAllThroughout() {
TimestampedInvocation<TimestampLeaseResponses> response1 =
acquireTimestampLeaseTimestamped(TIMESTAMP_NAME_1, 15);
assertThatTimestampsIsStrictlyWithinInvocationInterval(getMinLeasedTimestampsFrom(response1.result), response1);
assertThatTimestampsAreStrictlyWithinInvocationInterval(
getMinLeasedTimestampsFrom(response1.result), response1);

TimestampedInvocation<TimestampLeaseResponses> response2 =
acquireTimestampLeaseTimestamped(TIMESTAMP_NAME_1, 5);
assertThatTimestampsIsStrictlyWithinInvocationInterval(getMinLeasedTimestampsFrom(response2.result), response1);
assertThatTimestampsAreStrictlyWithinInvocationInterval(
getMinLeasedTimestampsFrom(response2.result), response1);

TimestampedInvocation<TimestampLeaseResponses> response3 =
acquireTimestampLeaseTimestamped(TIMESTAMP_NAME_1, 7);
assertThatTimestampsIsStrictlyWithinInvocationInterval(getMinLeasedTimestampsFrom(response3.result), response1);
assertThatTimestampsAreStrictlyWithinInvocationInterval(
getMinLeasedTimestampsFrom(response3.result), response1);

unlockForResponse(response1.result);
unlockForResponse(response3.result);
TimestampedInvocation<TimestampLeaseResponses> response4 =
acquireTimestampLeaseTimestamped(TIMESTAMP_NAME_1, 19);
assertThatTimestampsIsStrictlyWithinInvocationInterval(getMinLeasedTimestampsFrom(response4.result), response2);
assertThatTimestampsAreStrictlyWithinInvocationInterval(
getMinLeasedTimestampsFrom(response4.result), response2);
}

@Test
Expand Down Expand Up @@ -241,7 +246,7 @@ private static List<Long> getMinLeasedTimestampsFrom(TimestampLeaseResponses res
.collect(Collectors.toList());
}

private static void assertThatTimestampsIsStrictlyWithinInvocationInterval(
private static void assertThatTimestampsAreStrictlyWithinInvocationInterval(
List<Long> timestamps, TimestampedInvocation<?> invocation) {
assertThat(timestamps)
.allSatisfy(timestamp -> assertThatTimestampIsStrictlyWithinInvocationInterval(timestamp, invocation));
Expand Down

0 comments on commit 4826b68

Please sign in to comment.