denis-chudov commented on code in PR #7379:
URL: https://github.com/apache/ignite-3/pull/7379#discussion_r2707661089


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateMetaRocksDbPartitionStorage.java:
##########
@@ -166,6 +167,11 @@ void updateConfiguration(WriteBatch writeBatch, byte[] 
config) throws RocksDBExc
     }
 
     void updateLease(WriteBatch writeBatch, LeaseInfo leaseInfo) throws 
RocksDBException {
+        long currentLeaseStartTime = Optional.ofNullable(this.leaseInfo)
+                .map(LeaseInfo::leaseStartTime).orElse(Long.MIN_VALUE);
+        if (currentLeaseStartTime > leaseInfo.leaseStartTime()) {

Review Comment:
   ```suggestion
           if (leaseInfo.leaseStartTime() <= currentLeaseStartTime) {
   ```
   also skip if equal



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateMetaRocksDbPartitionStorage.java:
##########
@@ -166,6 +167,11 @@ void updateConfiguration(WriteBatch writeBatch, byte[] 
config) throws RocksDBExc
     }
 
     void updateLease(WriteBatch writeBatch, LeaseInfo leaseInfo) throws 
RocksDBException {
+        long currentLeaseStartTime = Optional.ofNullable(this.leaseInfo)
+                .map(LeaseInfo::leaseStartTime).orElse(Long.MIN_VALUE);

Review Comment:
   ```suggestion
           long currentLeaseStartTime = 
ofNullable(this.leaseInfo).map(LeaseInfo::leaseStartTime).orElse(Long.MIN_VALUE);
   ```
   could be one line with static import of method



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/TablePartitionProcessor.java:
##########
@@ -501,8 +505,17 @@ private CommandResult handlePrimaryReplicaChangeCommand(
             long commandIndex,
             long commandTerm
     ) {
+        long storageLastAppliedIndex = storage.lastAppliedIndex();
+        LOG.info("Handling PrimaryReplicaChangeCommand [tableId={}, partId={}, 
commandIndex={}, storageLastAppliedIndex={}, "

Review Comment:
   ```suggestion
           LOG.debug("Handling PrimaryReplicaChangeCommand [tableId={}, 
partId={}, commandIndex={}, storageLastAppliedIndex={}, "
   ```



##########
modules/replicator/src/main/java/org/apache/ignite/internal/replicator/PlacementDriverMessageProcessor.java:
##########
@@ -259,18 +269,128 @@ 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={}]",

Review Comment:
   please move leaseStartTime before expirationTime



##########
modules/replicator/src/main/java/org/apache/ignite/internal/replicator/PlacementDriverMessageProcessor.java:
##########
@@ -259,18 +269,128 @@ 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.timeoutFailedFuture();
         }
 
-        return retryOperationUntilSuccess(raftClient::readIndex, e -> 
currentTimeMillis() > expirationTime, executor)
-                .orTimeout(timeout, TimeUnit.MILLISECONDS)
-                .thenCompose(storageIndexTracker::waitFor);
+        return retryOperationUntilSuccessOrTimeout(raftClient::readIndex, 
readIndexTimeTracker.timeoutMs(), executor)
+                .whenComplete((raftIndex, readIndexError) -> {
+                    if (readIndexError != null) {
+                        LOG.warn("Failed to read index from raft leader {}.",
+                                readIndexError, 
readIndexTimeTracker.timeMessageDetails());
+                    } else {
+                        LOG.debug("Successfully read index from raft leader 
{}.", readIndexTimeTracker.timeMessageDetails());
+                    }
+                })
+                .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.timeoutFailedFuture();
+                    }
+
+                    return storageIndexTracker.waitFor(raftIndex)
+                            
.orTimeout(storageIndexUpdateTimeTracker.timeoutMs(), MILLISECONDS)
+                            .whenComplete((v, storageIndexTrackerError) -> {
+                                if (storageIndexTrackerError != null) {
+                                    LOG.warn("Failed to wait for storage index 
to reach raft leader {}.",
+                                            storageIndexTrackerError, 
storageIndexUpdateTimeTracker.timeMessageDetails());
+                                } else {
+                                    LOG.debug("Successfully waited for storage 
index to reach raft leader {}.",
+                                            
storageIndexUpdateTimeTracker.timeMessageDetails());
+                                }
+                            });
+                });
+    }
+
+    /**
+     * 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:
   its better to move TimeTracker after all methods



##########
modules/replicator/src/main/java/org/apache/ignite/internal/replicator/PlacementDriverMessageProcessor.java:
##########
@@ -259,18 +269,128 @@ 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.timeoutFailedFuture();
         }
 
-        return retryOperationUntilSuccess(raftClient::readIndex, e -> 
currentTimeMillis() > expirationTime, executor)
-                .orTimeout(timeout, TimeUnit.MILLISECONDS)
-                .thenCompose(storageIndexTracker::waitFor);
+        return retryOperationUntilSuccessOrTimeout(raftClient::readIndex, 
readIndexTimeTracker.timeoutMs(), executor)
+                .whenComplete((raftIndex, readIndexError) -> {
+                    if (readIndexError != null) {
+                        LOG.warn("Failed to read index from raft leader {}.",
+                                readIndexError, 
readIndexTimeTracker.timeMessageDetails());
+                    } else {
+                        LOG.debug("Successfully read index from raft leader 
{}.", readIndexTimeTracker.timeMessageDetails());
+                    }
+                })
+                .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.timeoutFailedFuture();
+                    }
+
+                    return storageIndexTracker.waitFor(raftIndex)
+                            
.orTimeout(storageIndexUpdateTimeTracker.timeoutMs(), MILLISECONDS)
+                            .whenComplete((v, storageIndexTrackerError) -> {
+                                if (storageIndexTrackerError != null) {
+                                    LOG.warn("Failed to wait for storage index 
to reach raft leader {}.",

Review Comment:
   please add group id and lease start time to this message to make it useful. 
Same about debug message below.



##########
modules/replicator/src/main/java/org/apache/ignite/internal/replicator/PlacementDriverMessageProcessor.java:
##########
@@ -259,18 +269,128 @@ 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.timeoutFailedFuture();
         }
 
-        return retryOperationUntilSuccess(raftClient::readIndex, e -> 
currentTimeMillis() > expirationTime, executor)
-                .orTimeout(timeout, TimeUnit.MILLISECONDS)
-                .thenCompose(storageIndexTracker::waitFor);
+        return retryOperationUntilSuccessOrTimeout(raftClient::readIndex, 
readIndexTimeTracker.timeoutMs(), executor)
+                .whenComplete((raftIndex, readIndexError) -> {
+                    if (readIndexError != null) {
+                        LOG.warn("Failed to read index from raft leader {}.",

Review Comment:
   please add group id and lease start time to this message to make it useful. 
Same about debug message below.



-- 
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]

Reply via email to