summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-27 13:59:54 +0200
committerPaul Buetow <paul@buetow.org>2026-03-27 13:59:54 +0200
commitf797489f30e76e8afcd8b8eb1fd16c79e9cd1363 (patch)
tree71b5a2fc02ed67a887e1f2b2f5bf0354664614c7 /src/main/java
parent38643ad8aca76dba2ac71987008d8c79370607cd (diff)
Clarify Raft leader election logs
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/protocols/implementations/VSRaftProtocol.java22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/main/java/protocols/implementations/VSRaftProtocol.java b/src/main/java/protocols/implementations/VSRaftProtocol.java
index bad893c..d359035 100644
--- a/src/main/java/protocols/implementations/VSRaftProtocol.java
+++ b/src/main/java/protocols/implementations/VSRaftProtocol.java
@@ -86,7 +86,7 @@ public class VSRaftProtocol extends VSAbstractProtocol {
* @see protocols.VSAbstractProtocol#onServerStart()
*/
public void onServerStart() {
- becomeLeader();
+ activateStartupLeader();
}
/* (non-Javadoc)
@@ -171,9 +171,25 @@ public class VSRaftProtocol extends VSAbstractProtocol {
}
/**
- * Transitions this process into the leader role and starts heartbeats.
+ * Activates the initial leader role at startup and starts heartbeats.
+ */
+ private void activateStartupLeader() {
+ becomeLeader("Startup leader activated");
+ }
+
+ /**
+ * Transitions this process into the leader role after winning an election.
*/
private void becomeLeader() {
+ becomeLeader("Leader elected by majority vote");
+ }
+
+ /**
+ * Transitions this process into the leader role and starts heartbeats.
+ *
+ * @param logPrefix the prefix to use for the leader transition log message
+ */
+ private void becomeLeader(String logPrefix) {
isLeader = true;
isCandidate = false;
votesReceived = 0;
@@ -182,7 +198,7 @@ public class VSRaftProtocol extends VSAbstractProtocol {
leaderId = process.getProcessID();
lastHeartbeatTime = process.getTime();
isServer(true);
- log("Leader elected: process " + leaderId + " (term " + currentTerm + ")");
+ log(logPrefix + ": process " + leaderId + " (term " + currentTerm + ")");
if (!getLongKeySet().contains("heartbeatInterval")) {
onServerInit();