[PATCH] Don't try to retrieve term if log is 0
Export this patch
Following ec48c42c add test when a new election is starting
Signed-off-by: Michael Bonfils <mbonfils@scaleway.com>
---
election.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/election.c b/election.c
index ef9bff9..d9db208 100644
--- a/election.c
+++ b/election.c
@@ -45,7 +45,10 @@ void libfloat_election_start(libfloat_ctx_t *ctx)
ctx->election_timeout_rand = ctx->conf.election_timeout + ctx->rand() % ctx->conf.election_timeout;
ctx->timeout_elapsed = 0;
- libfloat_get_last_term(ctx, &last_id, &last_term);
+ if (ctx->persistent.commit_index > 0)
+ {
+ libfloat_get_last_term(ctx, &last_id, &last_term);
+ }
/* Send a vote request to each node of the cluster */
for_every_node(ctx, node, {
--
2.25.1
LG
Nov 16, 2021 08:54:03 Michael Bonfils <mbonfils@scaleway.com>: