Lalant commented on code in PR #7379:
URL: https://github.com/apache/ignite-3/pull/7379#discussion_r2698028958
##########
modules/replicator/src/main/java/org/apache/ignite/internal/replicator/PlacementDriverMessageProcessor.java:
##########
@@ -259,18 +272,137 @@ private CompletableFuture<LeaseGrantedMessageResponse>
proposeLeaseRedirect(Inte
* @return Future that is completed when local storage catches up the
index that is actual for leader on the moment of request.
*/
private CompletableFuture<Void> waitForActualState(HybridTimestamp
startTime, long expirationTime) {
- LOG.info("Waiting for actual storage state, group=" + groupId);
+ LOG.info("Waiting for actual storage state [groupId={},
expirationTime={}, timeoutMs={}, leaseStartTime={}]",
+ groupId, expirationTime, expirationTime -
currentTimeMillis(), startTime);
replicaReservationClosure.accept(groupId, startTime);
- long timeout = expirationTime - currentTimeMillis();
- if (timeout <= 0) {
- return failedFuture(new TimeoutException());
+ TimeTracker readIndexTimeTracker = new TimeTracker(
+ expirationTime,
+ groupId,
+ "Timeout is expired before raft index reading started");
+ if (readIndexTimeTracker.isExpired()) {
+ return readIndexTimeTracker.getFailedFuture();
+ }
+
+ return retryOperationUntilSuccessOrTimeout(raftClient::readIndex,
readIndexTimeTracker.getTimeoutMs(), executor)
+ .whenComplete((raftIndex, readIndexError) -> {
+ if (readIndexError != null) {
+ LOG.warn("Failed to read index from raft leader"
+ + " [groupId={}, , expirationTime={},
timeoutMs={}, durationMs={}]", readIndexError,
+ groupId, expirationTime,
readIndexTimeTracker.getTimeoutMs(), readIndexTimeTracker.getDurationMs());
+ } else {
+ LOG.info("Successfully read index from raft leader "
+ + "[groupId={}, expirationTime={},
timeoutMs={}, durationMs={}]",
+ groupId, expirationTime,
readIndexTimeTracker.getTimeoutMs(), readIndexTimeTracker.getDurationMs());
+ }
+ })
+ .thenCompose(raftIndex -> {
+ // Recalculate remaining time after readIndex completes.
+ TimeTracker storageIndexUpdateTimeTracker = new
TimeTracker(
+ expirationTime,
+ groupId,
+ "Timeout is expired before storage index tracking
started");
+ if (storageIndexUpdateTimeTracker.isExpired()) {
+ return storageIndexUpdateTimeTracker.getFailedFuture();
+ }
+
+ return storageIndexTracker.waitFor(raftIndex)
+
.orTimeout(storageIndexUpdateTimeTracker.getTimeoutMs(), MILLISECONDS)
+ .whenComplete((v, storageIndexTrackerError) -> {
+ if (storageIndexTrackerError != null) {
+ LOG.warn("Failed to wait for storage index
to reach raft leader"
+ + " [groupId={},
expirationTime={}, timeoutMs={}, durationMs={}]",
+ storageIndexTrackerError, groupId,
expirationTime,
+
storageIndexUpdateTimeTracker.getTimeoutMs(),
+
storageIndexUpdateTimeTracker.getDurationMs());
+ } else {
+ LOG.info("Successfully waited for storage
index to reach raft leader"
+ + " [groupId={},
expirationTime={}, timeoutMs={}, durationMs={}]",
+ groupId, expirationTime,
+
storageIndexUpdateTimeTracker.getTimeoutMs(),
+
storageIndexUpdateTimeTracker.getDurationMs());
+ }
+ });
+ });
+ }
+
+ /**
+ * Tracks time for timeout operations. Calculates remaining time based on
expiration time and provides utilities
+ * for checking expiration and creating timeout exceptions with detailed
messages.
+ */
+ private static class TimeTracker {
Review Comment:
Do you think moving this class to utils is appropriate? It is highly
specific to this use case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]