~ne02ptzero/libfloat

ref: cb70314608dbeef0f66a7692be6101c16414cae9 libfloat/internal.h -rw-r--r-- 3.4 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef LIBFLOAT_INTERNAL_H
#define LIBFLOAT_INTERNAL_H

#include "libfloat.h"

#define for_every_node(ctx, n, ...) kh_foreach_value(ctx->nodes, n, __VA_ARGS__)
# ifndef max
#  define max(x, y) ((x) > (y) ? (x) : (y))
# endif
# ifndef min
#  define min(x, y) ((x) < (y) ? (x) : (y))
# endif

/*!
 *
 * \brief Start an election
 *
 * \param[in] ctx libfloat context
 */
void libfloat_election_start(libfloat_ctx_t *ctx);

/*!
 * \brief Set term to persistent storage
 *
 * \param[in] ctx libfloat context
 * \param[in] term Term to set
 */
void libfloat_set_current_term(libfloat_ctx_t *ctx, libfloat_term_t term);

/*!
 * \brief Set vote to persistent storage
 *
 * \param[in] ctx libfloat context
 * \param[in] id Node ID
 */
void libfloat_vote_for(libfloat_ctx_t *ctx, libfloat_node_id_t id);

/*!
 * \brief Set commit index to persistent storage
 *
 * \param[in] ctx libfloat context
 * \param[in] id Entry ID
 */
void libfloat_set_current_commit_index(libfloat_ctx_t *ctx, libfloat_entry_id_t id);

/*!
 * \brief Become an election candidate
 *
 * \param[in] ctx libfloat context
 */
void libfloat_become_candidate(libfloat_ctx_t *ctx);

/*!
 * \brief Send AE request to a node
 *
 * \param[in] ctx libfloat context
 * \param[in] node Node to send the request to
 * \param[in] heartbeat Force the request to be empty
 */
void libfloat_send_append_entries(libfloat_ctx_t *ctx, libfloat_node_t *node, bool heartbeat);

/*!
 * \brief Send AE requests to every node
 *
 * \param[in] ctx libfloat context
 */
void libfloat_send_append_entries_to_all(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)                      \
            libfloat_debug(c, s, ##__VA_ARGS__);   \
    } while (0)
void libfloat_debug(libfloat_ctx_t *ctx, const char *fmt, ...) __attribute__((format (printf, 2, 3)));

#define ERROR(c, s, ...) do {                      \
        if (c->error != NULL)                      \
            libfloat_error(c, s, ##__VA_ARGS__);   \
    } while (0)
void libfloat_error(libfloat_ctx_t *ctx, const char *fmt, ...) __attribute__((format (printf, 2, 3)));

/*!
 * \brief Set a error to be retrieved by the caller
 *
 * \param[in] str String to set (Constants only)
 */
void libfloat_set_error_str(const char *str);

/*!
 * \brief Count a node towards an acknowledge-replication list
 *
 * \param[in] ctx libfloat context
 * \param[in,out] log Entry to update
 * \param[in] id ID of the node that acked 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);

/*!
 * \brief Free the list of acknowledges of a log
 *
 * \param[in] ctx libfloat context
 * \param[in,out] log Log to free
 */
void libfloat_log_free_acks(libfloat_ctx_t *ctx, libfloat_log_entry_t *log);

/*!
 * \brief Free all log from memory
 *
 * \param[in] ctx libfloat context
 */
void libfloat_log_memory_cleanup(libfloat_ctx_t *ctx);


#endif /* LIBFLOAT_INTERNAL_H */