~ne02ptzero/libfloat

cb70314608dbeef0f66a7692be6101c16414cae9 — Michael Bonfils a month ago cf75af5
Ignore snapshot log if it matches current snapshot

Signed-off-by: Michael Bonfils <mbonfils@scaleway.com>
Ack-by       : Louis Solofrizzo <lsolofrizzo@scaleway.com>
3 files changed, 19 insertions(+), 4 deletions(-)

M internal.h
M log.c
M snapshot.c
M internal.h => internal.h +10 -1
@@ 66,7 66,16 @@ void libfloat_send_append_entries(libfloat_ctx_t *ctx, libfloat_node_t *node, bo
 */
void libfloat_send_append_entries_to_all(libfloat_ctx_t *ctx);

void libfloat_internal_snapshot_begin(libfloat_ctx_t *ctx);
/*!
 * \brief Start a snapshot
 *
 * \param[in] ctx libfloat context
 * \param[in] id ID of log that trigger snapshot
 * \param[in] term term of log
 *
 * \note snapshot will be ignored if current snapshot matches trigger log
 */
void libfloat_internal_snapshot_begin(libfloat_ctx_t *ctx, libfloat_entry_id_t id, libfloat_term_t term);

#define DEBUG(c, s, ...) do {                      \
        if (c->debug != NULL)                      \

M log.c => log.c +2 -2
@@ 105,7 105,7 @@ bool libfloat_add_log(libfloat_ctx_t *ctx, libfloat_commit_type_t commit_type, l
        ctx->snapshot_to_commit = entry->id;

        if (entry->data->type == LIBFLOAT_SNAPSHOT_LOG)
            libfloat_internal_snapshot_begin(ctx);
            libfloat_internal_snapshot_begin(ctx, entry->id, entry->term);
        return true;
    }



@@ 535,7 535,7 @@ response:
            log->data->buf = ctx->malloc(log->data->len);
            memcpy(log->data->buf, req->entries[i]->data->buf, log->data->len);

            libfloat_internal_snapshot_begin(ctx);
            libfloat_internal_snapshot_begin(ctx, log->id, log->term);
        }
        else if (!ctx->is_snapshotting)
        {

M snapshot.c => snapshot.c +7 -1
@@ 108,7 108,7 @@ static void libfloat_internal_snapshot_apply_log(libfloat_ctx_t *ctx)
    }
}

void libfloat_internal_snapshot_begin(libfloat_ctx_t *ctx)
void libfloat_internal_snapshot_begin(libfloat_ctx_t *ctx, libfloat_entry_id_t id, libfloat_term_t term)
{
    if (ctx->snapshot == NULL)
    {


@@ 118,6 118,12 @@ void libfloat_internal_snapshot_begin(libfloat_ctx_t *ctx)
        return;
    }

    if (id == ctx->persistent.snapshot.index + 1 && term == ctx->persistent.snapshot.term)
    {
        DEBUG(ctx, "libfloat_internal_snapshot_begin: A snapshot already exists with previous commit id, skip it");
        return;
    }

    /* First, let's block all writes and init variables */
    ctx->is_snapshotting = true;
    if (ctx->snapshot_to_commit < ctx->persistent.commit_index)