Cyrill commented on code in PR #7507:
URL: https://github.com/apache/ignite-3/pull/7507#discussion_r2853108710


##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/client/RaftCommandExecutor.java:
##########
@@ -879,20 +1060,27 @@ public boolean trackNoLeaderSeparately() {
      *     <li>When all peers are exhausted, waits for leader notification</li>
      * </ul>
      */
-    private class LeaderWaitRetryStrategy implements RetryExecutionStrategy {
-        private final CompletableFuture<ActionResponse> fut;
-        private final Command cmd;
+    private class LeaderWaitRetryStrategy<R extends NetworkMessage> implements 
RetryExecutionStrategy {

Review Comment:
   Extracted some of them, the others (the strategy implementations) left 
intact - there are too many dependencies to do that cleanly



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/client/RaftCommandExecutor.java:
##########
@@ -203,74 +272,133 @@ void shutdown(Throwable stopException) {
     }
 
     /**
-     * Resolves initial target peer for a command execution.
+     * Marks the executor as stopping. After this call, operations will fail 
with an exception from the
+     * stopping exception factory instead of TimeoutException.
+     */
+    void markAsStopping() {
+        stopping = true;
+    }
+
+    /**
+     * Returns the current leader.
+     *
+     * @return Current leader or {@code null} if unknown.
+     */
+    @Nullable Peer leader() {
+        return leader;
+    }
+
+    /**
+     * Sets the current leader. Used by PhysicalTopologyAwareRaftGroupService 
to update state from response.
      *
-     * <p>Tries the known leader first, falling back to a random peer if no 
leader is known.
+     * @param leader New leader.
+     */
+    void setLeader(@Nullable Peer leader) {
+        this.leader = leader;
+    }
+
+    /**
+     * Updates the leader only if the given term is newer than the currently 
known term.
      *
+     * <p>This prevents stale leader information from overwriting fresher 
information
+     * that may have been received via leader election notifications or 
previous refresh calls.
+     *
+     * @param leader New leader (can be {@code null}).
+     * @param term Term associated with this leader.
+     * @return {@code true} if the leader was updated (term is newer), {@code 
false} otherwise.
+     */
+    boolean setLeaderIfTermNewer(@Nullable Peer leader, long term) {
+        // Compare against the highest known term from either source:
+        // - leaderAvailabilityState.currentTerm(): term from leader election 
notifications
+        // - cachedLeaderTerm: term from previous setLeaderIfTermNewer calls
+        long highestKnownTerm = 
Math.max(leaderAvailabilityState.currentTerm(), cachedLeaderTerm);

Review Comment:
   done



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