adoroszlai commented on code in PR #988:
URL: https://github.com/apache/ratis/pull/988#discussion_r1425870476
##########
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:
Why do we need the `!= null` check? If `currentConf` is replaced with one
that returns `peer == null`, will we use the obsolete one as `currentPeer`?
(I'm not familiar with how this works, just thinking about the effects of
caching the current peer.)
--
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]