ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
coordinator.h File Reference

Ring consensus coordinator orchestration. More...

Go to the source code of this file.

Typedefs

typedef asciichat_error_t(* consensus_election_func_t) (void *context, consensus_state_t *state)
 Election callback function type.
typedef asciichat_error_t(* consensus_metrics_provider_fn) (void *, const uint8_t[16], participant_metrics_t *)

Functions

asciichat_error_t consensus_coordinator_create (const uint8_t my_id[SESSION_ID_SIZE], const consensus_topology_t *topology, consensus_election_func_t election_func, void *election_context, consensus_coordinator_t **out_coordinator)
 Initialize ring consensus coordinator.
void consensus_coordinator_destroy (consensus_coordinator_t *coordinator)
 Destroy coordinator and free resources.
asciichat_error_t consensus_coordinator_process (consensus_coordinator_t *coordinator, uint32_t timeout_ms)
 Main orchestration loop - call periodically.
asciichat_error_t consensus_coordinator_on_ring_members (consensus_coordinator_t *coordinator, const consensus_topology_t *new_topology)
 Update ring topology when participants change.
asciichat_error_t consensus_coordinator_on_collection_start (consensus_coordinator_t *coordinator, uint32_t round_id, uint64_t deadline_ns)
 Handle STATS_COLLECTION_START packet.
asciichat_error_t consensus_coordinator_on_stats_update (consensus_coordinator_t *coordinator, const uint8_t sender_id[SESSION_ID_SIZE], const participant_metrics_t *metrics, uint8_t num_metrics)
 Handle STATS_UPDATE packet (metrics relayed from another participant).
asciichat_error_t consensus_coordinator_on_election_result (consensus_coordinator_t *coordinator, const uint8_t host_id[SESSION_ID_SIZE], const uint8_t backup_id[SESSION_ID_SIZE])
 Handle ELECTION_RESULT packet.
asciichat_error_t consensus_coordinator_get_current_host (const consensus_coordinator_t *coordinator, uint8_t out_host_id[SESSION_ID_SIZE], uint8_t out_backup_id[SESSION_ID_SIZE])
 Get currently elected host.
consensus_state_machine_t consensus_coordinator_get_state (const consensus_coordinator_t *coordinator)
 Get current coordinator state.
uint64_t consensus_coordinator_time_until_next_round (const consensus_coordinator_t *coordinator)
 Get time until next round is due.
int consensus_coordinator_get_metrics_count (const consensus_coordinator_t *coordinator)
 Get count of metrics collected in current round.
void consensus_coordinator_set_metrics_provider (consensus_coordinator_t *, consensus_metrics_provider_fn, void *)

Detailed Description

Ring consensus coordinator orchestration.

Orchestrates the entire ring consensus flow:

  • Periodic round scheduling (5 minute intervals)
  • Metrics collection and relay around the ring
  • Election computation by leader
  • Result broadcasting and storage

The coordinator manages the state machine and calls appropriate functions based on the current consensus state and participant role.

Definition in file coordinator.h.

Typedef Documentation

◆ consensus_election_func_t

typedef asciichat_error_t(* consensus_election_func_t) (void *context, consensus_state_t *state)

Election callback function type.

Called by coordinator when election needs to be computed by leader. The callback can run the deterministic election algorithm.

Parameters
contextApplication context (passed to create)
stateState machine with collected metrics
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 36 of file coordinator.h.

◆ consensus_metrics_provider_fn

typedef asciichat_error_t(* consensus_metrics_provider_fn) (void *, const uint8_t[16], participant_metrics_t *)

Session-owned observations; this callback must not perform blocking I/O.

Definition at line 191 of file coordinator.h.

Function Documentation

◆ consensus_coordinator_create()

asciichat_error_t consensus_coordinator_create ( const uint8_t my_id[SESSION_ID_SIZE],
const consensus_topology_t * topology,
consensus_election_func_t election_func,
void * election_context,
consensus_coordinator_t ** out_coordinator )

Initialize ring consensus coordinator.

Creates a new coordinator for managing consensus rounds. The coordinator will automatically schedule rounds every 5 minutes.

Parameters
my_idMy 16-byte UUID
topologyTopology handle (not owned, must remain valid during coordinator lifetime)
election_funcCallback to run election algorithm (leader only)
election_contextApplication context passed to election_func
out_coordinatorOutput coordinator handle (caller must destroy)
Returns
ASCIICHAT_OK on success, error code otherwise

Initialize ring consensus coordinator.

Definition at line 56 of file coordinator.c.

59 {
60 if (!my_id || !topology || !election_func || !out_coordinator) {
61 return SET_ERRNO(
62 ERROR_INVALID_PARAM, "Invalid parameter: my_id=%p, topology=%p, election_func=%p, out_coordinator=%p",
63 (const void *)my_id, (const void *)topology, (const void *)election_func, (const void *)out_coordinator);
64 }
65
67 if (!coordinator) {
68 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate coordinator");
69 }
70
71 defer_named(release_coordinator, SAFE_FREE(coordinator));
72 memset(coordinator, 0, sizeof(*coordinator));
73 memcpy(coordinator->my_id, my_id, SESSION_ID_SIZE);
74 coordinator->topology = topology;
75 coordinator->election_func = election_func;
76 coordinator->election_context = election_context;
77
78 /* Initialize state machine */
79 asciichat_error_t err = consensus_state_create(my_id, topology, &coordinator->state);
80 if (err != ASCIICHAT_OK) {
81 return err;
82 }
83
84 /* Initialize round scheduling */
85 coordinator->last_round_start_ns = time_get_ns();
86 coordinator->next_round_id = 1;
87 coordinator->has_stored_result = false;
88
89 /* Register coordinator with named registry */
91 snprintf(coordinator_name, sizeof(coordinator_name), "consensus_coordinator:node_%u", my_id[0]);
92 NAMED_REGISTER(coordinator, coordinator_name, "consensus_coordinator_t", "0x%tx", NULL);
93
94 /* Register child state with coordinator as parent */
95 NAMED_REGISTER(coordinator->state, "state", "consensus_state_t", "0x%tx", (uintptr_t)(const void *)(coordinator));
96
97 log_debug("Coordinator created for node %u, first round in 5 minutes", my_id[0]);
98
99 *out_coordinator = coordinator;
100 defer_cancel(release_coordinator);
101 return ASCIICHAT_OK;
102}
#define SET_ERRNO(code,...)
struct consensus_coordinator consensus_coordinator_t
Coordinates consensus work for a session: it tracks the participant topology, election state,...
#define NETWORK_CONSENSUS_COORDINATOR_COORDINATOR_NAME_BUFFER_SIZE
Definition coordinator.c:7
#define SAFE_FREE(ptr)
Definition common.h:377
#define SAFE_MALLOC(size, cast)
Definition common.h:265
#define NAMED_REGISTER(ptr, name, type, fmt, parent_ptr)
Register any pointer with base name, type, format spec, and location (auto-suffix).
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ERROR_MEMORY
Definition error_codes.h:51
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_INVALID_PARAM
#define SESSION_ID_SIZE
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:595
asciichat_error_t consensus_state_create(const uint8_t my_id[SESSION_ID_SIZE], const consensus_topology_t *topology, consensus_state_t **out_state)
Initialize state machine with topology.
Definition state.c:43
uint64_t last_round_start_ns
Definition coordinator.c:43
const consensus_topology_t * topology
Definition coordinator.c:35
uint8_t my_id[SESSION_ID_SIZE]
Definition coordinator.c:34
consensus_election_func_t election_func
Definition coordinator.c:37
consensus_state_t * state
Definition coordinator.c:36

References ASCIICHAT_OK, consensus_state_create(), consensus_coordinator::election_context, consensus_coordinator::election_func, ERROR_INVALID_PARAM, ERROR_MEMORY, consensus_coordinator::has_stored_result, consensus_coordinator::last_round_start_ns, log_debug, consensus_coordinator::my_id, NAMED_REGISTER, NETWORK_CONSENSUS_COORDINATOR_COORDINATOR_NAME_BUFFER_SIZE, consensus_coordinator::next_round_id, SAFE_FREE, SAFE_MALLOC, SESSION_ID_SIZE, SET_ERRNO, consensus_coordinator::state, and consensus_coordinator::topology.

Referenced by session_consensus_create().

◆ consensus_coordinator_destroy()

void consensus_coordinator_destroy ( consensus_coordinator_t * coordinator)

Destroy coordinator and free resources.

Parameters
coordinatorCoordinator handle (safe to pass NULL)

Destroy coordinator and free resources.

Definition at line 107 of file coordinator.c.

107 {
108 if (!coordinator) {
109 return;
110 }
111 consensus_state_destroy(coordinator->state);
112 SAFE_FREE(coordinator);
113}
void consensus_state_destroy(consensus_state_t *state)
Destroy state machine and free resources.
Definition state.c:67

References consensus_state_destroy(), SAFE_FREE, and consensus_coordinator::state.

Referenced by session_consensus_destroy().

◆ consensus_coordinator_get_current_host()

asciichat_error_t consensus_coordinator_get_current_host ( const consensus_coordinator_t * coordinator,
uint8_t out_host_id[SESSION_ID_SIZE],
uint8_t out_backup_id[SESSION_ID_SIZE] )

Get currently elected host.

Retrieves the host and backup elected in the most recent successful round. If no round has completed yet, returns stored previous result if available, or an error if no result exists.

Parameters
coordinatorCoordinator handle
out_host_idOutput 16-byte host UUID (caller provides buffer)
out_backup_idOutput 16-byte backup UUID (caller provides buffer)
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 393 of file coordinator.c.

395 {
396 if (!coordinator || !out_host_id || !out_backup_id) {
397 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameter");
398 }
399
400 /* Try to get from current state first */
402 if (current_state == CONSENSUS_STATE_ELECTION_COMPLETE) {
403 asciichat_error_t err = consensus_state_get_elected_host(coordinator->state, out_host_id);
404 if (err == ASCIICHAT_OK) {
405 err = consensus_state_get_elected_backup(coordinator->state, out_backup_id);
406 }
407 if (err == ASCIICHAT_OK) {
408 return ASCIICHAT_OK;
409 }
410 }
411
412 /* Fall back to stored result */
413 if (coordinator->has_stored_result) {
414 memcpy(out_host_id, coordinator->stored_host_id, SESSION_ID_SIZE);
415 memcpy(out_backup_id, coordinator->stored_backup_id, SESSION_ID_SIZE);
416 return ASCIICHAT_OK;
417 }
418
419 return SET_ERRNO(ERROR_INVALID_STATE, "No election result available");
420}
@ ERROR_INVALID_STATE
asciichat_error_t consensus_state_get_elected_backup(const consensus_state_t *state, uint8_t out_backup_id[SESSION_ID_SIZE])
Get elected backup host ID from last election.
Definition state.c:202
asciichat_error_t consensus_state_get_elected_host(const consensus_state_t *state, uint8_t out_host_id[SESSION_ID_SIZE])
Get elected host ID from last election.
Definition state.c:188
consensus_state_machine_t consensus_state_get_current_state(const consensus_state_t *state)
Get current state machine state.
Definition state.c:181
consensus_state_machine_t
State machine lifecycle states.
Definition state.h:19
@ CONSENSUS_STATE_ELECTION_COMPLETE
Definition state.h:26
uint8_t stored_backup_id[SESSION_ID_SIZE]
Definition coordinator.c:49
uint8_t stored_host_id[SESSION_ID_SIZE]
Definition coordinator.c:48

References ASCIICHAT_OK, CONSENSUS_STATE_ELECTION_COMPLETE, consensus_state_get_current_state(), consensus_state_get_elected_backup(), consensus_state_get_elected_host(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, consensus_coordinator::has_stored_result, SESSION_ID_SIZE, SET_ERRNO, consensus_coordinator::state, consensus_coordinator::stored_backup_id, and consensus_coordinator::stored_host_id.

Referenced by session_consensus_get_elected_host(), and session_consensus_is_ready().

◆ consensus_coordinator_get_metrics_count()

int consensus_coordinator_get_metrics_count ( const consensus_coordinator_t * coordinator)

Get count of metrics collected in current round.

Used for testing and monitoring. Returns the number of metrics currently collected in the state machine.

Parameters
coordinatorCoordinator handle
Returns
Number of metrics collected, or -1 if invalid

Get count of metrics collected in current round.

Definition at line 453 of file coordinator.c.

453 {
454 if (!coordinator || !coordinator->state) {
455 return -1;
456 }
457 return consensus_state_get_metrics_count(coordinator->state);
458}
int consensus_state_get_metrics_count(const consensus_state_t *state)
Get count of metrics collected in current round.
Definition state.c:223

References consensus_state_get_metrics_count(), and consensus_coordinator::state.

Referenced by session_consensus_get_metrics_count().

◆ consensus_coordinator_get_state()

consensus_state_machine_t consensus_coordinator_get_state ( const consensus_coordinator_t * coordinator)

Get current coordinator state.

Parameters
coordinatorCoordinator handle
Returns
Current state from internal state machine

Definition at line 425 of file coordinator.c.

425 {
426 if (!coordinator || !coordinator->state) {
428 }
429 return consensus_state_get_current_state(coordinator->state);
430}
@ CONSENSUS_STATE_FAILED
Definition state.h:27

References CONSENSUS_STATE_FAILED, consensus_state_get_current_state(), and consensus_coordinator::state.

Referenced by session_consensus_get_state().

◆ consensus_coordinator_on_collection_start()

asciichat_error_t consensus_coordinator_on_collection_start ( consensus_coordinator_t * coordinator,
uint32_t round_id,
uint64_t deadline_ns )

Handle STATS_COLLECTION_START packet.

Called when receiving a collection start message from the previous ring member. Prepares to collect metrics and transitions state machine.

Parameters
coordinatorCoordinator handle
round_idCollection round ID
deadline_nsUnix nanosecond deadline for this round
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 300 of file coordinator.c.

301 {
302 if (!coordinator) {
303 return SET_ERRNO(ERROR_INVALID_PARAM, "Coordinator is NULL");
304 }
305
307 if (current_state != CONSENSUS_STATE_IDLE) {
308 return SET_ERRNO(ERROR_INVALID_STATE, "Cannot start collection, state is %d", current_state);
309 }
310
311 /* Start collection */
313 if (err != ASCIICHAT_OK) {
314 return err;
315 }
316
317 coordinator->next_round_id = round_id;
318 coordinator->collection_deadline_ns = deadline_ns;
319
320 /* Measure and add our metrics */
321 err = measure_and_add_metrics(coordinator);
322 if (err != ASCIICHAT_OK) {
323 log_warn("Failed to measure metrics: %d", err);
324 }
325
326 uint64_t now_ns = time_get_ns();
327 log_dev("Collection started: round_id=%u, deadline in %u seconds", round_id,
328 (unsigned int)((deadline_ns > now_ns ? deadline_ns - now_ns : 0) / NS_PER_SEC_INT));
329
330 return ASCIICHAT_OK;
331}
unsigned long long uint64_t
Definition common.h:63
#define log_warn(...)
Log a WARN message.
Definition log/log.h:621
#define log_dev(...)
Log a DEV message (most verbose, development only).
Definition log/log.h:581
#define NS_PER_SEC_INT
Definition time.h:169
asciichat_error_t consensus_state_start_collection(consensus_state_t *state)
Transition to COLLECTION_START state.
Definition state.c:76
@ CONSENSUS_STATE_IDLE
Definition state.h:20
uint64_t collection_deadline_ns
Definition coordinator.c:45

References ASCIICHAT_OK, consensus_coordinator::collection_deadline_ns, consensus_state_get_current_state(), CONSENSUS_STATE_IDLE, consensus_state_start_collection(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, log_dev, log_warn, consensus_coordinator::next_round_id, NS_PER_SEC_INT, SET_ERRNO, and consensus_coordinator::state.

Referenced by session_consensus_on_collection_start().

◆ consensus_coordinator_on_election_result()

asciichat_error_t consensus_coordinator_on_election_result ( consensus_coordinator_t * coordinator,
const uint8_t host_id[SESSION_ID_SIZE],
const uint8_t backup_id[SESSION_ID_SIZE] )

Handle ELECTION_RESULT packet.

Called when election result is received from leader. Verifies the election, stores the elected host/backup, and stores for fallback.

Parameters
coordinatorCoordinator handle
host_idElected host UUID
backup_idElected backup UUID
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 364 of file coordinator.c.

366 {
367 if (!coordinator || !host_id || !backup_id) {
368 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameter");
369 }
370
371 /* Store the elected host and backup */
372 memcpy(coordinator->stored_host_id, host_id, SESSION_ID_SIZE);
373 memcpy(coordinator->stored_backup_id, backup_id, SESSION_ID_SIZE);
374 coordinator->has_stored_result = true;
375
376 log_info("Election result received: host=%u, backup=%u", host_id[0], backup_id[0]);
377
378 /* Transition state back to IDLE */
380 if (current_state == CONSENSUS_STATE_ELECTION_COMPLETE) {
382 if (err != ASCIICHAT_OK) {
383 log_warn("Failed to reset state to IDLE: %d", err);
384 }
385 }
386
387 return ASCIICHAT_OK;
388}
#define log_info(...)
Log an INFO message.
Definition log/log.h:608
asciichat_error_t consensus_state_reset_to_idle(consensus_state_t *state)
Transition back to IDLE from ELECTION_COMPLETE.
Definition state.c:168

References ASCIICHAT_OK, CONSENSUS_STATE_ELECTION_COMPLETE, consensus_state_get_current_state(), consensus_state_reset_to_idle(), ERROR_INVALID_PARAM, consensus_coordinator::has_stored_result, log_info, log_warn, SESSION_ID_SIZE, SET_ERRNO, consensus_coordinator::state, consensus_coordinator::stored_backup_id, and consensus_coordinator::stored_host_id.

Referenced by session_consensus_on_election_result().

◆ consensus_coordinator_on_ring_members()

asciichat_error_t consensus_coordinator_on_ring_members ( consensus_coordinator_t * coordinator,
const consensus_topology_t * new_topology )

Update ring topology when participants change.

Called when the ring topology changes (participants join/leave). Updates internal topology reference and resets any in-progress round.

Parameters
coordinatorCoordinator handle
new_topologyNew topology handle (not owned, must remain valid)
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 274 of file coordinator.c.

275 {
276 if (!coordinator || !new_topology) {
277 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameter");
278 }
279
280 /* State also borrows the topology while idle. Build a complete replacement
281 * before publishing either pointer so a rejected update leaves both valid. */
282 consensus_state_t *replacement = NULL;
283 asciichat_error_t err = consensus_state_create(coordinator->my_id, new_topology, &replacement);
284 if (err != ASCIICHAT_OK)
285 return err;
287 if (current_state != CONSENSUS_STATE_IDLE)
288 log_warn("Ring topology changed during round, resetting state");
289 consensus_state_destroy(coordinator->state);
290 coordinator->state = replacement;
291 coordinator->topology = new_topology;
292
293 log_info("Ring topology updated");
294 return ASCIICHAT_OK;
295}
struct consensus_state consensus_state_t
State machine instance.

References ASCIICHAT_OK, consensus_state_create(), consensus_state_destroy(), consensus_state_get_current_state(), CONSENSUS_STATE_IDLE, ERROR_INVALID_PARAM, log_info, log_warn, consensus_coordinator::my_id, SET_ERRNO, consensus_coordinator::state, and consensus_coordinator::topology.

Referenced by session_consensus_set_topology().

◆ consensus_coordinator_on_stats_update()

asciichat_error_t consensus_coordinator_on_stats_update ( consensus_coordinator_t * coordinator,
const uint8_t sender_id[SESSION_ID_SIZE],
const participant_metrics_t * metrics,
uint8_t num_metrics )

Handle STATS_UPDATE packet (metrics relayed from another participant).

Called when receiving metrics from previous ring member. Adds metrics to state machine and forwards to next member.

Parameters
coordinatorCoordinator handle
sender_idWho is sending this metrics update
metricsMetrics to relay
num_metricsCount of metrics in packet
Returns
ASCIICHAT_OK on success, error code otherwise

Handle STATS_UPDATE packet (metrics relayed from another participant).

Definition at line 336 of file coordinator.c.

338 {
339 if (!coordinator || !sender_id || !metrics) {
340 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameter");
341 }
342
344 if (current_state != CONSENSUS_STATE_COLLECTING) {
345 return SET_ERRNO(ERROR_INVALID_STATE, "Cannot accept metrics, state is %d", current_state);
346 }
347
348 /* Add all metrics to state */
349 for (int i = 0; i < num_metrics; i++) {
350 asciichat_error_t err = consensus_state_add_metrics(coordinator->state, &metrics[i]);
351 if (err != ASCIICHAT_OK) {
352 log_warn("Failed to add metric %d: %d", i, err);
353 }
354 }
355
356 log_debug("Received %d metrics from sender %u", num_metrics, sender_id[0]);
357
358 return ASCIICHAT_OK;
359}
asciichat_error_t consensus_state_add_metrics(consensus_state_t *state, const participant_metrics_t *metrics)
Add collected metrics from a participant.
Definition state.c:93
@ CONSENSUS_STATE_COLLECTING
Definition state.h:22

References ASCIICHAT_OK, consensus_state_add_metrics(), CONSENSUS_STATE_COLLECTING, consensus_state_get_current_state(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, log_debug, log_warn, SESSION_ID_SIZE, SET_ERRNO, and consensus_coordinator::state.

Referenced by session_consensus_on_stats_update().

◆ consensus_coordinator_process()

asciichat_error_t consensus_coordinator_process ( consensus_coordinator_t * coordinator,
uint32_t timeout_ms )

Main orchestration loop - call periodically.

Checks if a new collection round should start and processes the current state. Should be called regularly (at least once per second) to ensure timely round scheduling.

Handles:

  • Round scheduling (triggers every 5 minutes)
  • Collection deadline enforcement (30 second deadline)
  • Metrics measurement and relay
  • Election computation (leader only)
  • Result storage and broadcasting
Parameters
coordinatorCoordinator handle
timeout_msTimeout for operation in milliseconds
Returns
ASCIICHAT_OK on success, error code otherwise

Main orchestration loop - call periodically.

Definition at line 236 of file coordinator.c.

236 {
237 (void)timeout_ms; /* Currently unused, but kept for future use */
238
239 if (!coordinator) {
240 return SET_ERRNO(ERROR_INVALID_PARAM, "Coordinator is NULL");
241 }
242
243 uint64_t now_ns = time_get_ns();
244
245 /* Check if we should start a new round */
246 if (should_start_new_round(coordinator, now_ns)) {
247 /* Only leader starts rounds */
248 if (consensus_topology_am_leader(coordinator->topology)) {
249 asciichat_error_t err = start_collection_round(coordinator, now_ns);
250 if (err != ASCIICHAT_OK) {
251 log_warn("Failed to start collection round: %d", err);
252 return err;
253 }
254 }
255 }
256
258
259 /* Check for collection timeout */
260 if (current_state == CONSENSUS_STATE_COLLECTING && has_collection_timed_out(coordinator, now_ns)) {
261 log_warn("Collection round timed out, completing early");
262 asciichat_error_t err = complete_collection(coordinator);
263 if (err != ASCIICHAT_OK) {
264 log_error("Failed to complete collection on timeout: %d", err);
265 }
266 }
267
268 return ASCIICHAT_OK;
269}
#define log_error(...)
Log an ERROR message.
Definition log/log.h:634
bool consensus_topology_am_leader(const consensus_topology_t *topology)
Check if I am the ring leader (last position).
Definition topology.c:85

References ASCIICHAT_OK, CONSENSUS_STATE_COLLECTING, consensus_state_get_current_state(), consensus_topology_am_leader(), ERROR_INVALID_PARAM, log_error, log_warn, SET_ERRNO, consensus_coordinator::state, and consensus_coordinator::topology.

Referenced by session_consensus_process().

◆ consensus_coordinator_set_metrics_provider()

void consensus_coordinator_set_metrics_provider ( consensus_coordinator_t * coordinator,
consensus_metrics_provider_fn provider,
void * context )

Definition at line 460 of file coordinator.c.

461 {
462 if (!coordinator)
463 return;
464 coordinator->metrics_provider = provider;
465 coordinator->metrics_context = context;
466}
consensus_metrics_provider_fn metrics_provider
Definition coordinator.c:39

References consensus_coordinator::metrics_context, and consensus_coordinator::metrics_provider.

Referenced by session_consensus_create().

◆ consensus_coordinator_time_until_next_round()

uint64_t consensus_coordinator_time_until_next_round ( const consensus_coordinator_t * coordinator)

Get time until next round is due.

Returns the number of nanoseconds until the next collection round is scheduled.

Parameters
coordinatorCoordinator handle
Returns
Nanoseconds until next round, or 0 if round is due now

Get time until next round is due.

Definition at line 435 of file coordinator.c.

435 {
436 if (!coordinator) {
437 return 0;
438 }
439
440 uint64_t now_ns = time_get_ns();
441 uint64_t next_round_ns = coordinator->last_round_start_ns + CONSENSUS_ROUND_INTERVAL_NS;
442
443 if (now_ns >= next_round_ns) {
444 return 0;
445 }
446
447 return next_round_ns - now_ns;
448}
#define CONSENSUS_ROUND_INTERVAL_NS
Definition coordinator.c:22

References CONSENSUS_ROUND_INTERVAL_NS, and consensus_coordinator::last_round_start_ns.

Referenced by session_consensus_time_until_next_round().