Skip to content

Commit 7a10df1

Browse files
authored
IGNITE-28456 Fix race in NodeImpl.init() causing double electSelf() for single-node Raft groups (#7934)
1 parent cb7c565 commit 7a10df1

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • modules/raft/src/main/java/org/apache/ignite/raft/jraft/core

modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@
5050
import org.apache.ignite.internal.logger.IgniteLogger;
5151
import org.apache.ignite.internal.logger.Loggers;
5252
import org.apache.ignite.internal.metrics.MetricManager;
53-
import org.apache.ignite.internal.metrics.sources.FsmCallerMetricSource;
54-
import org.apache.ignite.internal.metrics.sources.LogManagerMetricSource;
5553
import org.apache.ignite.internal.metrics.sources.NodeMetricSource;
5654
import org.apache.ignite.internal.metrics.sources.RaftMetricSource;
57-
import org.apache.ignite.internal.metrics.sources.ReadOnlyServiceMetricSource;
5855
import org.apache.ignite.internal.raft.JraftGroupEventsListener;
5956
import org.apache.ignite.internal.raft.WriteCommand;
6057
import org.apache.ignite.internal.raft.service.SafeTimeAwareCommandClosure;
@@ -1159,8 +1156,15 @@ public boolean init(final NodeOptions opts) {
11591156
this.writeLock.lock();
11601157
if (this.conf.isStable() && this.conf.getConf().size() == 1 && this.conf.getConf().contains(this.serverId)) {
11611158
// The group contains only this server which must be the LEADER, trigger
1162-
// the timer immediately.
1163-
electSelf();
1159+
// the timer immediately. Skip if already a leader — the election timer may have
1160+
// fired and completed a full election between stepDown() and this lock acquisition,
1161+
// in which case calling electSelf() again would corrupt BallotBox / confCtx state.
1162+
if (this.state != State.STATE_LEADER) {
1163+
electSelf();
1164+
}
1165+
else {
1166+
this.writeLock.unlock();
1167+
}
11641168
}
11651169
else {
11661170
this.writeLock.unlock();

0 commit comments

Comments
 (0)