[PATCH] Don't try to retrieve term if log is 0
Export this patch
Also use DEBUG instead of ERROR for information log
Signed-off-by: Michael Bonfils <mbonfils@scaleway.com>
---
election.c | 2 +-
snapshot.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/election.c b/election.c
index 663ee99..ef9bff9 100644
--- a/election.c
+++ b/election.c
@@ -79,7 +79,7 @@ static bool libfloat_can_i_grant_vote(libfloat_ctx_t *ctx, libfloat_rpc_request_
return false;
}
- if (libfloat_get_last_term(ctx, NULL, &last_term) == false)
+ if (ctx->persistent.commit_index > 0 && libfloat_get_last_term(ctx, NULL, &last_term) == false)
{
/* We have failed to retrieve last_ferm from log */
return false;
diff --git a/snapshot.c b/snapshot.c
index 34db6ff..2ca1ab2 100644
--- a/snapshot.c
+++ b/snapshot.c
@@ -189,7 +189,7 @@ void libfloat_snapshot_done(libfloat_ctx_t *ctx, bool success)
/* Write the current snapshot in persistent storage */
ctx->write_current_snapshot(ctx, ctx->persistent.commit_index, ctx->persistent.term);
- ERROR(ctx, "Writing snapshot with index=%d and term=%d", ctx->persistent.commit_index, ctx->persistent.term);
+ DEBUG(ctx, "Writing snapshot with index=%d and term=%d", ctx->persistent.commit_index, ctx->persistent.term);
ctx->persistent.snapshot.index = ctx->persistent.commit_index;
ctx->persistent.snapshot.term = ctx->persistent.term;
--
2.25.1
LG
Oct 15, 2021 17:41:38 Michael Bonfils <mbonfils@scaleway.com>:
LG
--
Louis Solofrizzo
Team Storage