JAkutenshi commented on code in PR #7507:
URL: https://github.com/apache/ignite-3/pull/7507#discussion_r2872738317
##########
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:
Resolved with `leader` and `setLeaderHint`
--
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]