szetszwo commented on PR #1050:
URL: https://github.com/apache/ratis/pull/1050#issuecomment-1997986077

   @symious , thanks for working on this!  It actually should store the 
`peerId` but not `peer`.  Then, the code can be simplified as below:
   ```java
   +++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/FollowerInfoImpl.java
   @@ -32,7 +32,7 @@ import java.util.function.LongUnaryOperator;
    class FollowerInfoImpl implements FollowerInfo {
      private final String name;
    
   -  private final AtomicReference<RaftPeer> peer;
   +  private final RaftPeerId peerId;
      private final Function<RaftPeerId, RaftPeer> getPeer;
      private final AtomicReference<Timestamp> lastRpcResponseTime;
      private final AtomicReference<Timestamp> lastRpcSendTime;
   @@ -47,9 +47,8 @@ class FollowerInfoImpl implements FollowerInfo {
    
      FollowerInfoImpl(RaftGroupMemberId id, RaftPeer peer, 
Function<RaftPeerId, RaftPeer> getPeer,
          Timestamp lastRpcTime, long nextIndex, boolean caughtUp) {
   -    this.name = id + "->" + peer.getId();
   -
   -    this.peer = new AtomicReference<>(peer);
   +    this.peerId = peer.getId();
   +    this.name = id + "->" + peerId;
        this.getPeer = getPeer;
        this.lastRpcResponseTime = new AtomicReference<>(lastRpcTime);
        this.lastRpcSendTime = new AtomicReference<>(lastRpcTime);
   @@ -183,18 +182,12 @@ class FollowerInfoImpl implements FollowerInfo {
    
      @Override
      public RaftPeerId getId() {
   -    return peer.get().getId();
   +    return peerId;
      }
    
      @Override
      public RaftPeer getPeer() {
   -    final RaftPeer newPeer = getPeer.apply(getId());
   -    if (newPeer != null) {
   -      peer.set(newPeer);
   -      return newPeer;
   -    } else {
   -      return peer.get();
   -    }
   +    return getPeer.apply(getId());
      }
    
      @Override
   ```


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