~ne02ptzero/libfloat

internals: Remove last_log from the internal context v1 APPLIED

Louis Solofrizzo: 1
 internals: Remove last_log from the internal context

 4 files changed, 4 insertions(+), 21 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~ne02ptzero/libfloat/patches/36843/mbox | git am -3
Learn more about email & git

[PATCH] internals: Remove last_log from the internal context Export this patch

May cause some bugs, and it is mostly useless anyway. I've reworked
AE response a bit to simplify it. We now do a DB write per log applied,
instead of one write per AE call.

Signed-off-by: Louis Solofrizzo <lsolofrizzo@scaleway.com>
---
 libfloat.h |  1 -
 log.c      | 22 ++++------------------
 raft.c     |  1 -
 snapshot.c |  1 -
 4 files changed, 4 insertions(+), 21 deletions(-)

diff --git a/libfloat.h b/libfloat.h
index e5494b7..fe352d5 100644
--- a/libfloat.h
+++ b/libfloat.h
@@ -67,7 +67,6 @@ struct libfloat_ctx_s {
    khash_t(libfloat_node_id_t) *nodes;                 /*!< Hashtable of nodes */
    libfloat_node_t             *leader;                /*!< Current Leader (can be NULL) */
    libfloat_node_t             *me;                    /*!< My node in the cluster */
    libfloat_log_entry_t        *last_log;              /*!< Last log committed */

    uint32_t                    timeout_elapsed;        /*!< Current time elasped between two heartbeats */
    uint32_t                    election_timeout_rand;  /*!< Randomized election time */
diff --git a/log.c b/log.c
index bd03d67..0c8bcc9 100644
--- a/log.c
+++ b/log.c
@@ -126,7 +126,6 @@ bool libfloat_add_log(libfloat_ctx_t *ctx, libfloat_commit_type_t commit_type, l

    libfloat_log_add_node_ack(ctx, entry, ctx->me->id);
    ctx->timeout_elapsed = 0;
    ctx->last_log = entry;
    libfloat_set_current_commit_index(ctx, entry->id);

    for_every_node(ctx, node, {
@@ -378,7 +377,8 @@ end:

void libfloat_append_entries_receive(libfloat_ctx_t *ctx, libfloat_rpc_append_entries_t *req, libfloat_rpc_append_entries_response_t *resp)
{
    libfloat_node_t *node = libfloat_get_node(ctx, req->leader_id);
    libfloat_node_t             *node = libfloat_get_node(ctx, req->leader_id);
    libfloat_entry_id_t         last_written_entry_id = 0;

    if (ctx->gray_failures.checking == true)
    {
@@ -510,7 +510,6 @@ response:
        if (iterator != kh_end(ctx->persistent.log))
        {
            /* This log was already committed, ignore it */
            resp->current_index = req->entries[i]->id;
            continue;
        }

@@ -549,7 +548,7 @@ response:
                goto end;
            }

            ctx->last_log = log;
            libfloat_set_current_commit_index(ctx, req->entries[i]->id);
        }
        else if (ctx->is_snapshotting)
        {
@@ -563,23 +562,10 @@ response:
            log->data->buf = ctx->malloc(log->data->len);
            memcpy(log->data->buf, req->entries[i]->data->buf, log->data->len);
        }

        resp->current_index = log->id;
    }

end:
    if (!resp->success)
        resp->current_index = ctx->persistent.commit_index;
    else
    {
        if (resp->current_index == 0)
            resp->current_index = ctx->persistent.commit_index;
        else
        {
            if (!ctx->is_snapshotting && ctx->last_log)
                libfloat_set_current_commit_index(ctx, ctx->last_log->id);
        }
    }
    resp->current_index = ctx->persistent.commit_index;

    if (node != NULL && req->n_entries > 0)
    {
diff --git a/raft.c b/raft.c
index 8f10661..2f7415d 100644
--- a/raft.c
+++ b/raft.c
@@ -134,7 +134,6 @@ void libfloat_reload_state(libfloat_ctx_t *ctx)

        iterator = kh_put(libfloat_entry_id_t, ctx->persistent.log, log->id, &absent);
        kh_value(ctx->persistent.log, iterator) = log;
        ctx->last_log = log;
    }
}

diff --git a/snapshot.c b/snapshot.c
index d9025d3..e602ed3 100644
--- a/snapshot.c
+++ b/snapshot.c
@@ -37,7 +37,6 @@ static void libfloat_internal_snapshot_apply_log(libfloat_ctx_t *ctx)
            libfloat_log_add_node_ack(ctx, entry, ctx->me->id);

        ctx->timeout_elapsed = 0;
        ctx->last_log = entry;
        libfloat_set_current_commit_index(ctx, entry->id);

        if (entry->commit_type == LIBFLOAT_EVENTUALLY_CONSISTENT)
-- 
2.38.1