~ne02ptzero/libfloat

3ffa7ecac2bbef7d2c1210895543348e1ad3aa35 — Louis Solofrizzo 8 days ago d88dcd5
raft: Add stat for elected leader timestamp

Patch: https://lists.sr.ht/~ne02ptzero/libfloat/patches/35442

Signed-off-by : Louis Solofrizzo <lsolofrizzo@scaleway.com>
Acked-by      : Florian Florensa <fflorensa@scaleway.com>
2 files changed, 5 insertions(+), 0 deletions(-)

M libfloat.h
M raft.c
M libfloat.h => libfloat.h +1 -0
@@ 46,6 46,7 @@ struct libfloat_ctx_s {
    struct {
        uint64_t        leader_election;                /*!< Count of leader elections for this cluster */
        uint64_t        orphans_logs;                   /*!< Count of logs that are applied on the leader only */
        time_t          leader_election_time;           /*!< Timestamp of the last leader election */
    } stat;

    struct {

M raft.c => raft.c +4 -0
@@ 23,6 23,7 @@ void libfloat_become_leader(libfloat_ctx_t *ctx)
    });

    ctx->me->is_up_to_date = 1;
    ctx->stat.leader_election_time = ctx->time(NULL);
}

void __libfloat_become_candidate(libfloat_ctx_t *ctx, libfloat_elections_args_t *args)


@@ 30,6 31,7 @@ void __libfloat_become_candidate(libfloat_ctx_t *ctx, libfloat_elections_args_t 
    DEBUG(ctx, "Becoming candidate: reason=%s", args->reason);
    ctx->state = RAFT_STATE_CANDIDATE;
    ctx->election_timeout_rand = ctx->conf.election_timeout + ctx->rand() % ctx->conf.election_timeout;
    ctx->stat.leader_election_time = 0;
}

void __libfloat_become_follower(libfloat_ctx_t *ctx, libfloat_elections_args_t *args)


@@ 38,6 40,7 @@ void __libfloat_become_follower(libfloat_ctx_t *ctx, libfloat_elections_args_t *
    ctx->abort_send_snapshot(ctx);
    ctx->state = RAFT_STATE_FOLLOWER;
    ctx->election_timeout_rand = ctx->conf.election_timeout + ctx->rand() % ctx->conf.election_timeout;
    ctx->stat.leader_election_time = 0;
    libfloat_vote_for(ctx, 0);
}



@@ 49,6 52,7 @@ void libfloat_step_down(libfloat_ctx_t *ctx)
        ctx->leader = NULL;

    ctx->state = RAFT_STATE_NONE;
    ctx->stat.leader_election_time = 0;
}

void libfloat_send_append_entries_to_all(libfloat_ctx_t *ctx, bool heartbeat)