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


##########
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:
   This is to avoid calling `getRaftConf().getPeer(..)` every time in 
`RaftServer`, even if the conf is not changed.
   ```java
   //RaftServer
       default RaftPeer getPeer() {
         return Optional.ofNullable(getRaftConf().getPeer(getId(), 
RaftPeerRole.FOLLOWER, RaftPeerRole.LISTENER))
           .orElseGet(() -> getRaftServer().getPeer());
       }
   ```
   



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