~ne02ptzero/libfloat

9e7bac3b1c7805b395dc241683befe53c9d237ee — Louis Solofrizzo 10 months ago 8310a9f
periodic: Trigger an election when a leader has lost its followers

Also fixes some formatting issues in the latest patch.

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

Signed-off-by: Louis Solofrizzo <lsolofrizzo@scaleway.com>
Acked-by: Patrik Cyvoct <pcyvoct@scaleway.com>

 ________________________________________
/ Take what you can use and let the rest \
\ go by. -- Ken Kesey                    /
 ----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
1 files changed, 10 insertions(+), 10 deletions(-)

M periodic.c
M periodic.c => periodic.c +10 -10
@@ 57,7 57,7 @@ void libfloat_periodic(libfloat_ctx_t *ctx, uint32_t time)
                    * Hmmm, we might be partitionned, or at the very least we don't have a quorum anymore.
                    * Time to step down!
                    */
                    libfloat_become_follower(ctx, .reason = "not enough nodes reachable");
                    libfloat_election_start(ctx, .reason = "We have not heard from our nodes, possible split?", .force = true);
                    ERROR(ctx, "Sanity timeout has been reached (%ld seconds), stepping down from leader position: reachable %lu / quorum %lu (%lu)",
                          ctx->conf.sanity_timeout, nodes_reachable, ctx->n_nodes / 2 + 1, ctx->n_nodes);
                    return;


@@ 114,17 114,17 @@ void libfloat_periodic(libfloat_ctx_t *ctx, uint32_t time)
        {
            if (ctx->soft_compact_last_log != ctx->persistent.commit_index)
            {
                /* If soft compact is enabled, let's check if the timing is right */                                         
                /* If soft compact is enabled, let's check if the timing is right */
                if (ctx->last_log_time + ctx->conf.soft_compact_time < ms_to_s(ctx->global_timer))
                {                                                                                                               
                    ctx->soft_compact_last_log = ctx->persistent.commit_index;                                                  
                    if (ctx->persistent.commit_index - ctx->persistent.snapshot.index >= ctx->conf.soft_compact_every_n_log)    
                    {                                                                                                           
                        ctx->append_snapshot_log(ctx, ctx->persistent.commit_index, ctx->persistent.term);                      
                {
                    ctx->soft_compact_last_log = ctx->persistent.commit_index;
                    if (ctx->persistent.commit_index - ctx->persistent.snapshot.index >= ctx->conf.soft_compact_every_n_log)
                    {
                        ctx->append_snapshot_log(ctx, ctx->persistent.commit_index, ctx->persistent.term);
                        ctx->soft_compact_last_log++;
                    }                                                                                                           
                }                                                                                                               
            } 
                    }
                }
            }
        }
    }
    else if (ctx->election_timeout_rand <= ctx->timeout_elapsed)