Documentation
¶
Overview ¶
Package clusterhost assembles the cluster side of a voter: join, master key hand-over, the mTLS cluster port with Raft and ClusterService, the CA and the node certificate (ADR 0005, 0006, 0011). The binary and the multi-node tests use the same code.
Index ¶
- Constants
- type Host
- func (h *Host) Addr() string
- func (h *Host) Bootstrap(ctx context.Context) error
- func (h *Host) CaughtUp() bool
- func (h *Host) ClockOffsets() map[string]int64
- func (h *Host) Close() error
- func (h *Host) LeaderID() string
- func (h *Host) PeerSelfChecks() map[string]selfcheck.Remote
- func (h *Host) PeerSignals() map[string]sysalert.Signals
- func (h *Host) PeerViews() map[string]degraded.PeerView
- func (h *Host) ProbeSessionViews() map[string]ProbeSessionView
- func (h *Host) ProbeSessions() map[string]membership.ProbeSessionInfo
- func (h *Host) Run(ctx context.Context)
- func (h *Host) SSRFProtectionByNode() map[string]bool
- func (h *Host) SelfSignals() sysalert.Signals
- type JoinOptions
- type Options
- type Prepared
- type ProbeSessionView
Constants ¶
const ( // RevocationReload bounds how long a revocation takes to reach the // handshakes of every node (FA-PKI-04). RevocationReload = 10 * time.Second )
Intervals of the background jobs.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Host ¶
type Host struct {
Node *cluster.Node
Authority *clusterpki.Authority
Cert *clusterpki.NodeCert
Revocations *clusterpki.Revocations
Manager *membership.Manager
// Replication pushes and repairs heartbeats between the voters (ADR 0006).
Replication *replication.Replicator
// Health turns the heartbeat failures of the leader into the health of
// the nodes in the registry (ADR 0017).
Health *membership.HealthWatcher
// Level raises the cluster command level once all voters support it
// (ADR 0018).
Level *membership.LevelWatcher
// ProbeGW serves connected probes over gRPC/mTLS (ADR 0034).
ProbeGW *probegw.Server
// ProbeHealth updates probe health in the registry from merged voter sessions (ADR 0034).
ProbeHealth *membership.ProbeHealthWatcher
// contains filtered or unexported fields
}
Host is the running cluster side of a voter.
func (*Host) Bootstrap ¶
Bootstrap creates the CA on the leader of a new cluster and gives the leader its certificate (FA-PKI-01); a joined node already has one. It runs after the data keys are loaded.
func (*Host) CaughtUp ¶
CaughtUp reports whether this node has applied the commit index it knows of. It does not check for a leader; the detector does.
func (*Host) ClockOffsets ¶
ClockOffsets returns the clock offset of each peer in milliseconds, positive when the peer is ahead of this node. Only peers with a fresh sample appear (ADR 0020).
func (*Host) PeerSelfChecks ¶
PeerSelfChecks returns the self-check state of each peer voter as the last GetStatus answer reported it, by node ID (ADR 0022). Only peers with an answer in the last clockMaxAge appear.
func (*Host) PeerSignals ¶
PeerSignals returns the signals of each peer voter from its last GetStatus answer, by node ID (ADR 0025). Only answers within clockMaxAge appear.
func (*Host) PeerViews ¶
PeerViews returns the last GetStatus answer of each peer voter, by node ID, for the degraded detector (ADR 0024). Only answers within clockMaxAge appear.
func (*Host) ProbeSessionViews ¶ added in v0.0.4
func (h *Host) ProbeSessionViews() map[string]ProbeSessionView
ProbeSessionViews returns merged active probe sessions including local buffer statistics when the probe is connected to this voter.
func (*Host) ProbeSessions ¶ added in v0.0.4
func (h *Host) ProbeSessions() map[string]membership.ProbeSessionInfo
ProbeSessions returns merged active probe sessions across this voter and its peers (ADR 0034 section 7).
func (*Host) Run ¶
Run starts the background jobs: revocation reload, certificate renewal, resuming promotions on a new leader, address announcement, heartbeat replication, node registration and node health. It returns when ctx ends.
func (*Host) SSRFProtectionByNode ¶
SSRFProtectionByNode returns whether SSRF protection is on for each node, by node ID (ADR 0030). This node reports its own setting; a peer appears only with a GetStatus answer within clockMaxAge.
func (*Host) SelfSignals ¶
SelfSignals returns the signals of this node, as its own GetStatus answer reports them (ADR 0025).
type JoinOptions ¶
type JoinOptions struct {
Seeds []string
Token string
// ExternalKEK is set when MASTER_KEY or MASTER_KEY_FILE is configured;
// then the cluster's key is never installed, only compared.
ExternalKEK bool
// MaxCommandVersion is the command version announced at join. Zero means
// cluster.CommandVersion; a test override (ADR 0018).
MaxCommandVersion uint32
// Clock is the wall clock of the joining node; nil means time.Now (ADR 0020).
Clock func() time.Time
}
JoinOptions describe how this node joins, if it does.
type Options ¶
type Options struct {
NodeID string
ListenAddr string
Advertise string
DataDir string
Timeout time.Duration
State *sqlite.StateStore
// Metrics holds the heartbeats that the replication exchanges (FA-REP-01).
Metrics store.Metrics
// OnHeartbeatsStored is called with the heartbeats that replication stored
// (pushes and anti-entropy pages), see replication.Options.OnStored. It
// must not block (ADR 0021). Nil means no callback.
OnHeartbeatsStored func([]store.Heartbeat)
// ReplicationInterval is the period of the anti-entropy pass per peer.
// Zero means the default of the replication package; tests use short ones.
ReplicationInterval time.Duration
KEK *secrets.KEK
Keyring *secrets.Keyring
Prepared Prepared
Log *slog.Logger
// RaftLogLevel and RaftLogJSON configure the Raft library logger.
RaftLogLevel string
RaftLogJSON bool
// OnFatal stops the node when the FSM halts (FA-CLU-13).
OnFatal func(error)
// Name, Version and Capabilities describe this node in the node registry
// (ADR 0017). Capabilities are sorted and deduplicated on registration.
Name string
Version string
Capabilities []string
// MaxCommandVersion overrides cluster.CommandVersion, the highest command
// version this node applies and announces (ADR 0018). Zero means
// cluster.CommandVersion. Tests use it to simulate an older binary.
MaxCommandVersion uint32
// Clock is the wall clock of this node for certificate validity, command
// timestamps, heartbeat observations and replication decisions. Nil means
// time.Now. The multi-node tests give each node its own skewed clock
// (ADR 0020).
Clock func() time.Time
// ClockInterval is the period of the clock offset measurement; zero means
// clockSampleInterval. Tests shorten it.
ClockInterval time.Duration
// SelfCheck returns the latest result of this node's reference targets
// (ADR 0022); it is reported in GetStatus. Nil means not configured.
SelfCheck func() selfcheck.Status
// DiskFreeRatio returns the free share of the data directory, negative if
// unknown; it is reported in GetStatus (ADR 0025). Nil means unknown.
DiskFreeRatio func() float64
// WALBytes returns the WAL sizes of state.db and metrics.db; it is reported
// in GetStatus (ADR 0025). Nil means unknown.
WALBytes func() (state, metrics int64)
// SSRFProtection is whether SSRF protection is on for this node (ADR 0030);
// it is reported in GetStatus and shown per node in the cluster view.
SSRFProtection bool
// ProbeAssigner, ProbeKeyring and probe timings configure the voter's ProbeService gateway (ADR 0034).
ProbeAssigner scheduler.Assigner
ProbeKeyring configsecret.Keyring
ProbeBufferMaxAge time.Duration
ProbeTickInterval time.Duration
ProbeDebounceInterval time.Duration
ProbeHealthInterval time.Duration
OnProbeRejected func(reason string)
}
Options configure Start.
type Prepared ¶
type Prepared struct {
Cert *clusterpki.NodeCert
// Joining is true if this node must not bootstrap (FA-CLU-02).
Joining bool
// KEKFingerprint is the cluster's key fingerprint received at join.
KEKFingerprint string
}
Prepared is the result of Prepare.
func Prepare ¶
func Prepare(ctx context.Context, dataDir, nodeID, name, advertise, version string, join JoinOptions, log *slog.Logger) (Prepared, error)
Prepare loads the node certificate and, for a new node with join seeds, joins the cluster and installs the generated master key. It runs before the master key is loaded, so a joining node never generates its own.
A node bootstraps only without Raft state, without join seeds and without a cluster certificate: a node that joined before but crashed before Raft stored anything must not found a cluster of its own.
type ProbeSessionView ¶ added in v0.0.4
type ProbeSessionView struct {
ConnectedVoterID string
ConnectedSinceMs int64
LastMessageMs int64
Buffer *pb.ProbeBufferStatus
}
ProbeSessionView describes a live probe session with optional buffer fill status when connected to this voter.