adoroszlai commented on code in PR #988:
URL: https://github.com/apache/ratis/pull/988#discussion_r1425909242


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/ConfigurationManager.java:
##########
@@ -31,17 +34,29 @@
  * entries.
  */
 public class ConfigurationManager {
+  private final RaftPeerId id;
   private final RaftConfigurationImpl initialConf;
   private final NavigableMap<Long, RaftConfigurationImpl> configurations = new 
TreeMap<>();
   /**
    * The current raft configuration. If configurations is not empty, should be
    * the last entry of the map. Otherwise is initialConf.
    */
   private volatile RaftConfigurationImpl currentConf;
+  /** Cache the peer corresponding to {@link #id}. */
+  private volatile RaftPeer currentPeer;
 
-  ConfigurationManager(RaftConfigurationImpl initialConf) {
+  ConfigurationManager(RaftPeerId id, RaftConfigurationImpl initialConf) {
+    this.id = id;
     this.initialConf = initialConf;
-    this.currentConf = initialConf;
+    setCurrentConf(initialConf);
+  }
+
+  private void setCurrentConf(RaftConfigurationImpl currentConf) {
+    this.currentConf = currentConf;
+    final RaftPeer peer = currentConf.getPeer(id, RaftPeerRole.FOLLOWER, 
RaftPeerRole.LISTENER);
+    if (peer != null) {
+      this.currentPeer = peer;
+    }

Review Comment:
   Previously if the current conf did not have the peer, we'd fallback to 
`getRaftServer().getPeer()`.  But with the new code, `getCurrentPeer()` would 
return the leftover `currentPeer` value.
   
   Sorry if I'm misunderstanding something.



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