~ne02ptzero/libfloat

16bdbb8abdf702650a63b83ae036e0ab072928b1 — Louis Solofrizzo 7 days ago 3ffa7ec master
ae: Fix libfloat_count and optimize the routine

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

Signed-off-by : Louis Solofrizzo <lsolofrizzo@scaleway.com>
Acked-by      : Patrik Cyvoct <pcyvoct@scaleway.com>
3 files changed, 14 insertions(+), 7 deletions(-)

M externals/list.c
M internal.h
M log.c
M externals/list.c => externals/list.c +4 -1
@@ 34,8 34,11 @@ size_t libfloat_list_count(const libfloat_list_t *head)
    libfloat_list_t *iter;
    size_t      i = 0;

    if (head == NULL || head->next == NULL || head->prev == NULL)
        return 0;

    for(iter = head->next; iter != head; iter = iter->next)
        i++;

    return i;
}
\ No newline at end of file
}

M internal.h => internal.h +3 -1
@@ 105,10 105,12 @@ void libfloat_set_error_str(const char *str);
 * \param[in,out] log Entry to update
 * \param[in] id ID of the node that acked this log
 *
 * \return The total number of acknowledges on this log
 *
 * \note This function is replay-safe, eg; If a node tells us twice that a log
 * X is replicated, we only count it once.
 */
void libfloat_log_add_node_ack(libfloat_ctx_t *ctx, libfloat_log_entry_t *log, libfloat_node_id_t id);
size_t libfloat_log_add_node_ack(libfloat_ctx_t *ctx, libfloat_log_entry_t *log, libfloat_node_id_t id);

/*!
 * \brief Free the list of acknowledges of a log

M log.c => log.c +7 -5
@@ 1,6 1,6 @@
#include "internal.h"

void libfloat_log_add_node_ack(libfloat_ctx_t *ctx, libfloat_log_entry_t *log, libfloat_node_id_t id)
size_t libfloat_log_add_node_ack(libfloat_ctx_t *ctx, libfloat_log_entry_t *log, libfloat_node_id_t id)
{
    bool                found = false;
    libfloat_node_ack_t *ptr, *tmp;


@@ 20,6 20,8 @@ void libfloat_log_add_node_ack(libfloat_ctx_t *ctx, libfloat_log_entry_t *log, l
        ptr->id = id;
        libfloat_list_add_tail(&ptr->next, &log->node_acks);
    }

    return libfloat_list_count(&log->node_acks);
}

void libfloat_log_free_acks(libfloat_ctx_t *ctx, libfloat_log_entry_t *log)


@@ 597,6 599,7 @@ void libfloat_append_entries_response(libfloat_ctx_t *ctx, libfloat_rpc_append_e
{
    libfloat_node_t             *node = libfloat_get_node(ctx, resp->node);
    libfloat_log_entry_t        *log = NULL;
    size_t                      acks = 0;

    if (node == NULL)
    {


@@ 722,10 725,9 @@ void libfloat_append_entries_response(libfloat_ctx_t *ctx, libfloat_rpc_append_e

            log = kh_value(ctx->persistent.log, iterator);

            acks = libfloat_log_add_node_ack(ctx, log, node->id);

            libfloat_log_add_node_ack(ctx, log, node->id);

            if (libfloat_list_count(&log->node_acks) >= ctx->n_nodes)
            if (acks >= ctx->n_nodes)
            {
                if (log->commit_type == LIBFLOAT_ABSOLUTELY_CONSISTENT)
                {


@@ 746,7 748,7 @@ void libfloat_append_entries_response(libfloat_ctx_t *ctx, libfloat_rpc_append_e
                    log->data = NULL;
                }
            }
            else if (libfloat_list_count(&log->node_acks) >= ctx->n_nodes / 2 + 1)
            else if (acks >= ctx->n_nodes / 2 + 1)
            {
                if (log->commit_type <= LIBFLOAT_STRONGLY_CONSISTENT)
                {