1/* @ajax/mesh-abi-host-fleet: The fleet region: leader, term, versions, members' reconcile status, the lockstep group.
2 *
3 * Part of alpha-c-mesh, a C port of alpha-rust-mesh (README.md says from where). */
4#ifndef MESH_ABI_HOST_FLEET_H
5#define MESH_ABI_HOST_FLEET_H
67#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10#include "mesh/abi/fields.h"
1112/* The fleet (plan F3; 0x1400..0x1800): this member's view of the leader, the */
13/* desired state and every member's reconcile status (from their F_BEATs), and */
14/* its lockstep group. Written by the fleet thread every tick. */
15#define MESH_S_FLEET 0x1400
16#define MESH_S_LEADER 0x1400 /* u32 the leader's system id, PEER_NONE: none reachable (no majority) */
17#define MESH_S_ROLE 0x1404 /* u32 ROLE_* */
18#define MESH_S_TERM 0x1408 /* u64 */
19#define MESH_S_STATE_VER 0x1410 /* u64 the committed desired state's version (as this member knows it) */
20#define MESH_S_APPLIED_VER 0x1418 /* u64 the version this member reconciled to */
21#define MESH_S_UP_MASK 0x1420 /* u32 bit k: system k is up (linked and heard within the dead time), this one included */
22#define MESH_S_SUSPECT_MASK 0x1424 /* u32 bit k: up but silent for a third of the dead time */
23#define MESH_S_QUORUM 0x1428 /* u32 votes a majority needs (1: the fixed pair) */
24#define MESH_S_FLEET_FLAGS 0x142c /* u32 FF_* */
25/* 0x1430..0x1438: free (the F3 partition's words; F5's job chunks replaced the partition) */
26#define MESH_S_DEAD_MS 0x1438 /* u32 the dead time in use */
27#define MESH_S_COMMIT_TERM 0x143c /* u32 the committed document's term (low 32 bits) */
28#define MESH_ROLE_SINGLE 0u
29#define MESH_ROLE_FOLLOWER 1u
30#define MESH_ROLE_PRECANDIDATE 2u
31#define MESH_ROLE_CANDIDATE 3u
32#define MESH_ROLE_LEADER 4u
33#define MESH_ROLE_NAMES_LEN 5
34extern const char *const MESH_ROLE_NAMES[5];
35#define MESH_FF_QUORUM 1u /* this member hears a majority */
36#define MESH_FF_FIXED 2u /* a pair: system 0 coordinates, no failover */
37/* Per member k at fmember(k), FMEMBER_BYTES: its reconcile status as its last F_BEAT said. */
38#define MESH_S_FMEMBERS 0x1440
39#define MESH_FMEMBER_BYTES 0x40
40#define MESH_FM_STATUS 0x00 /* u32 RS_* */
41#define MESH_FM_GROUP 0x04 /* u32 GL_* of its lockstep group */
42#define MESH_FM_APPLIED 0x08 /* u64 the version it reconciled to */
43#define MESH_FM_HEARD_MS 0x10 /* u64 this meshd's uptime ms when it was last heard (0: never) */
44#define MESH_FM_REASON 0x18 /* 40 bytes NUL padded: what failed / is pending */
45/* This member's lockstep group (the one the document gives the loaded lockstep program). */
46#define MESH_S_GROUP 0x1640
47#define MESH_SG_NAME 0x1640 /* 16 bytes */
48#define MESH_SG_EPOCH 0x1650 /* u32 */
49#define MESH_SG_CYCLE 0x1654 /* u32 */
50#define MESH_SG_MASK 0x1658 /* u32 the epoch's members */
51#define MESH_SG_ORDER 0x165c /* 8 bytes: rank r's system id (0xff past the end) */
52#define MESH_SG_STATE 0x1664 /* u32 the document's: 1 running, 2 paused (0: no group) */
53#define MESH_SG_LOCAL 0x1668 /* u32 GL_*: how this member's data plane runs it */
54#define MESH_SG_RANK 0x166c /* u32 this member's rank (PEER_NONE: not in the epoch) */
55#define MESH_SG_ON_LOSS 0x1670 /* u32 0 pause, 1 reform */
56#define MESH_SG_AUTO_MS 0x1674 /* u32 */
57#define MESH_S_FLEET_END 0x1680
58#define MESH_GS_NAMES_LEN 3
59extern const char *const MESH_GS_NAMES[3];
60#define MESH_FMEMBER_FIELDS_LEN 5
61extern const mesh_field MESH_FMEMBER_FIELDS[5];
6263/* Member k's fleet record. */
64static inline size_t mesh_fmember(uint32_t k) { return MESH_S_FMEMBERS + MESH_FMEMBER_BYTES * (size_t)k; }
6566/* The Rust const asserts that only involve this package. */
67_Static_assert(MESH_SG_AUTO_MS + 4 <= MESH_S_FLEET_END, "SG_AUTO_MS + 4 <= S_FLEET_END");
68_Static_assert((MESH_S_TERM % 8 == 0), "S_TERM.is_multiple_of(8)");
69_Static_assert((MESH_S_STATE_VER % 8 == 0), "S_STATE_VER.is_multiple_of(8)");
70_Static_assert((MESH_S_APPLIED_VER % 8 == 0), "S_APPLIED_VER.is_multiple_of(8)");
71_Static_assert((MESH_FM_APPLIED % 8 == 0), "FM_APPLIED.is_multiple_of(8)");
72_Static_assert((MESH_FMEMBER_BYTES % 8 == 0), "FMEMBER_BYTES.is_multiple_of(8)");
73_Static_assert((MESH_S_FMEMBERS % 8 == 0), "S_FMEMBERS.is_multiple_of(8)");
7475#endif