~ne02ptzero/libfloat

ref: cb70314608dbeef0f66a7692be6101c16414cae9 libfloat/libfloat.c -rw-r--r-- 1.6 KiB
cb703146 — Michael Bonfils Ignore snapshot log if it matches current snapshot 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "internal.h"

libfloat_ctx_t *libfloat_ctx_new(void *(*malloc)(size_t), void *(*calloc)(size_t, size_t), void (*free)(void *))
{
    libfloat_ctx_t      *ret = calloc(1, sizeof(*ret));

    if (ret == NULL)
        return NULL;

    ret->malloc = malloc;
    ret->calloc = calloc;
    ret->free = free;

    ret->persistent.log = kh_init(libfloat_entry_id_t);
    ret->nodes = kh_init(libfloat_node_id_t);

    /* Defaults */
    ret->election_timeout_rand = 2000;
    ret->request_timeout = 800;
    ret->conf.election_timeout = 2000;
    ret->conf.log_commit_timeout = 5;
    ret->conf.compact_every_n_log = 10000;
    ret->conf.avoid_congestion = false;
    ret->conf.sanity_timeout = 6;
    ret->conf.optimistic_replication = true;
    ret->conf.max_logs_per_ae = 500;
    ret->conf.do_revert = false;

    /* Init the log list */
    ret->logs.prev = &ret->logs;
    ret->logs.next = &ret->logs;

    return ret;
}

void libfloat_ctx_del(libfloat_ctx_t *ctx)
{
    libfloat_log_entry_t        *log;
    libfloat_node_t             *node;

    kh_foreach_value(ctx->persistent.log, log, {
        if (log->commit != NULL)
        {
            log->commit(log->udata, LIBFLOAT_ENTRY_REFUSED);
        }

        if (log->data != NULL)
        {
            ctx->free(log->data->buf);
            ctx->free(log->data);
        }

        libfloat_log_free_acks(ctx, log);
        ctx->free(log);
    });

    kh_foreach_value(ctx->nodes, node, {
        ctx->free(node);
    });

    kh_destroy(libfloat_entry_id_t, ctx->persistent.log);
    kh_destroy(libfloat_node_id_t, ctx->nodes);
    ctx->free(ctx);
}