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


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java:
##########
@@ -492,14 +492,18 @@ public void close() {
    * @param force Force to start a new {@link FollowerState} even if this 
server is already a follower.
    * @return if the term/votedFor should be updated to the new term
    */
-  private synchronized boolean changeToFollower(long newTerm, boolean force, 
Object reason) {
+  private synchronized boolean changeToFollower(
+      long newTerm,
+      boolean force,
+      boolean allowListener,
+      Object reason) {
     final RaftPeerRole old = role.getCurrentRole();
-    if (old == RaftPeerRole.LISTENER) {
+    final boolean metadataUpdated = state.updateCurrentTerm(newTerm);
+    if (old == RaftPeerRole.LISTENER && !allowListener) {
       throw new IllegalStateException("Unexpected role " + old);
     }
-    final boolean metadataUpdated = state.updateCurrentTerm(newTerm);
 
-    if (old != RaftPeerRole.FOLLOWER || force) {
+    if ((old != RaftPeerRole.FOLLOWER && old != RaftPeerRole.LISTENER) || 
force) {

Review Comment:
   This is better to be
   ```
   if ((old != RaftPeerRole.FOLLOWER || force) && old != RaftPeerRole.LISTENER) 
{
   ```
   Otherwise, `force == true` will change a Listener to a Follower.  
Fortunately, when `force == true`, we always have `allowListener == false` in 
the current code.  Therefore, it won't cause any problems.



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