From 4aa0759594f6da21e747f37f96ece5c3dda0750d Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Tue, 28 Aug 2018 10:54:56 -0500 Subject: [PATCH] Log the reason for any Raft leader step down. --- .../main/java/io/permazen/kv/raft/LeaderRole.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/permazen-kv-raft/src/main/java/io/permazen/kv/raft/LeaderRole.java b/permazen-kv-raft/src/main/java/io/permazen/kv/raft/LeaderRole.java index 1915dd4d6b..5a15e313d0 100644 --- a/permazen-kv-raft/src/main/java/io/permazen/kv/raft/LeaderRole.java +++ b/permazen-kv-raft/src/main/java/io/permazen/kv/raft/LeaderRole.java @@ -147,9 +147,13 @@ public Timestamp getLeaseTimeout() { * @throws IllegalStateException if this role is no longer active or election timer is not running */ public void stepDown() { + this.doStepDown("stepDown() invoked"); + } + + private void doStepDown(String reason) { synchronized (this.raft) { Preconditions.checkState(this.raft.role == this, "role is no longer active"); - this.debug("stepping down as leader due to invocation of stepDown()"); + this.info("stepping down as leader: " + reason); this.raft.changeRole(new FollowerRole(this.raft)); } } @@ -352,11 +356,8 @@ private void updateLeaderCommitIndex() { this.updateAllSynchronizedFollowersNow(); // If we are no longer a member of the cluster, step down after the most recent config change is committed - if (!this.raft.isClusterMember() && this.raft.commitIndex >= this.findMostRecentConfigChange()) { - if (this.log.isDebugEnabled()) - this.log.debug("stepping down as leader of cluster (no longer a member)"); - this.stepDown(); - } + if (!this.raft.isClusterMember() && this.raft.commitIndex >= this.findMostRecentConfigChange()) + this.doStepDown("no longer a member of my own cluster"); } }