Documentation
¶
Overview ¶
Package reload computes what changes when a health-check configuration is re-read, and what must be carried across.
The point is what is *kept*, not what changes ¶
A naive reload tears the IPVS table down and rebuilds it. That works, and it drops every established connection through every virtual server on the box, including the ones whose configuration did not change at all. keepalived instead diffs the old and new configurations and touches only the difference (`clear_diff_services`, keepalived/check/ipwrapper.c:1128-1177).
Two things are carried across for every surviving backend and both matter:
- **The alive state.** A real server that passed its checks before the reload is still passing them; re-checking from scratch would take it out of rotation for a whole check interval for no reason.
- **The quorum state.** Recomputing it from a table that is momentarily half-built would install the sorry server and immediately remove it, which clients see.
The exception is a backend that is *new*. C marks the survivors `reloaded` and puts every new alpha-mode checker down (`check_new_rs_state`, ipwrapper.c:1180-1198), because a backend nobody has checked yet must not receive traffic on the strength of a default.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
Kind ActionKind
// VS and RS name the affected entries.
VS Identity
RS Identity
// Reason is a short description for the log.
Reason string
}
Action is one thing the reload must do.
type ActionKind ¶
type ActionKind uint8
ActionKind enumerates what a reload can do.
const ( // RemoveVirtualServer takes a whole service out. RemoveVirtualServer ActionKind = iota // AddVirtualServer installs a new one. AddVirtualServer // EditVirtualServer changes a surviving service's scheduling // parameters in place, which IPVS supports without disturbing its // connections. EditVirtualServer // RemoveRealServer and AddRealServer change the backend set. RemoveRealServer AddRealServer // EditRealServer changes a surviving backend's weight. EditRealServer // SetSorryServer installs or replaces the fallback. SetSorryServer // RemoveSorryServer takes it away. RemoveSorryServer )
func (ActionKind) String ¶
func (k ActionKind) String() string
type Identity ¶
type Identity string
Identity is what makes two configuration entries "the same thing" across a reload.
It is deliberately not the whole configuration: a real server whose *weight* changed is the same real server and keeps its state, while one whose address changed is a different one and does not. Getting this boundary wrong in either direction is expensive — too narrow and every reload drops connections, too wide and a retargeted backend inherits a health verdict that was never about it.
type Plan ¶
type Plan struct {
Actions []Action
// Carried is the state that survives, keyed by the entries that still
// exist in the new configuration.
Carried *State
// NewServers are the real servers that did not exist before. Their
// alpha-mode checkers start down: a backend nobody has checked must not
// receive traffic on the strength of a default.
NewServers []Identity
}
Plan is the result of a diff.
func Diff ¶
func Diff(old, new map[Identity]VirtualServer, state *State) *Plan
Diff computes what changes between two configurations.
The action order is: removals first, then edits, then additions. Removing first is what keeps the IPVS table from briefly holding both an old and a new definition of the same service, which is visible to clients as connections scheduled to a backend that is about to disappear.
func (*Plan) StartsDown ¶
StartsDown reports whether a real server should begin the reload in the down state (check_new_rs_state, ipwrapper.c:1180-1198).
Only a *new* backend with alpha-mode checkers does. A survivor keeps whatever it was, and a new backend without alpha keeps keepalived's optimistic default — which is C's behaviour and is worth noticing: a new non-alpha backend receives traffic before anything has checked it.
type RealServer ¶
type RealServer struct {
ID Identity
// Weight and Inhibit can change without the server being a different
// server.
Weight int
Inhibit bool
// Alpha reports whether this backend's checkers start down.
Alpha bool
}
RealServer is the subset of a real server's configuration the diff needs.
type State ¶
type State struct {
// Alive is each real server's last verdict.
Alive map[Identity]bool
// QuorumUp is each virtual server's last quorum state.
QuorumUp map[Identity]bool
}
State is what survives a reload.
type VirtualServer ¶
type VirtualServer struct {
// ID identifies the service: address and port, or firewall mark.
ID Identity
// Scheduler, LBKind and the persistence settings are the fields whose
// change requires an IPVS *edit* rather than a rebuild
// (ipwrapper.c:1163-1169).
Scheduler string
LBKind string
Persistence int
Quorum int
Hysteresis int
RealServers map[Identity]RealServer
// SorryServer is the fallback, or the empty identity.
SorryServer Identity
}
VirtualServer is the subset of a virtual server's configuration that the diff needs.