replication

package
v0.2.9-beta.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2026 License: AGPL-3.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package replication provides the push-based replication manager for the registry server and directory-sync support types. The Manager maintains a set of standby subscriber connections and broadcasts snapshots/deltas to all of them. Directory-sync types and helpers used by the server-side handler are also defined here.

## Consistency model

Replication uses an AP (Available / Partition-Tolerant) model: Push() and PushDelta() commit writes locally first, then broadcast snapshots/deltas to all connected standbys on a best-effort basis. The primary does NOT wait for standby acknowledgment — mutations are considered committed once they land in the local WAL.

If the primary crashes before a standby has received the latest deltas (e.g. within the 1 s replicaPushInterval), those mutations are lost. This is an intentional design choice for the AP side of the CAP theorem: the rendezvous remains available under partition at the cost of potential data loss on failover.

Sync-replication mode (where the primary waits for at least one standby ack before returning to the caller) is not yet implemented. See PILOT-280 for discussion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolField

func BoolField(m map[string]interface{}, key string) bool

func CloneSliceString

func CloneSliceString(s []string) []string

CloneSliceString returns a defensive copy. nil-in → nil-out.

func CloneSliceUint16

func CloneSliceUint16(s []uint16) []uint16

CloneSliceUint16 returns a defensive copy. nil-in → nil-out.

func CloneSliceUint32

func CloneSliceUint32(s []uint32) []uint32

CloneSliceUint32 returns a defensive copy. nil-in → nil-out.

func NormalizeExternalID

func NormalizeExternalID(id string) string

NormalizeExternalID normalizes to lowercase so lookups are case-insensitive.

func StrField

func StrField(m map[string]interface{}, key string) string

Types

type DirectoryEntry

type DirectoryEntry struct {
	ExternalID  string   `json:"external_id"` // unique ID from directory (OIDC sub, email, GUID)
	DisplayName string   `json:"display_name,omitempty"`
	Email       string   `json:"email,omitempty"`
	Groups      []string `json:"groups,omitempty"`   // directory groups
	Role        string   `json:"role,omitempty"`     // desired pilot role: "owner", "admin", "member"
	Disabled    bool     `json:"disabled,omitempty"` // deprovisioned users
}

DirectoryEntry represents a user from an enterprise directory (AD, Entra ID, LDAP).

func ParseDirectoryEntries

func ParseDirectoryEntries(raw []interface{}) []DirectoryEntry

ParseDirectoryEntries parses the raw interface{} slice produced by json.Unmarshal into map[string]interface{} — entries missing external_id are dropped.

type DirectorySyncRequest

type DirectorySyncRequest struct {
	NetworkID uint16           `json:"network_id"`
	Entries   []DirectoryEntry `json:"entries"`
	// If true, nodes whose external_id is not in the entries list will be kicked.
	RemoveUnlisted bool `json:"remove_unlisted,omitempty"`
}

DirectorySyncRequest is the protocol payload for directory sync.

type DirectorySyncResult

type DirectorySyncResult struct {
	Updated  int      `json:"updated"`  // roles updated
	Disabled int      `json:"disabled"` // nodes disabled (kicked)
	Mapped   int      `json:"mapped"`   // entries mapped to existing nodes
	Unmapped int      `json:"unmapped"` // entries with no matching node
	Actions  []string `json:"actions"`
}

DirectorySyncResult describes what the sync operation did.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles push-based replication from primary to standbys. Standbys connect to the primary and subscribe; the primary pushes snapshots after every state mutation.

func NewManager

func NewManager() *Manager

NewManager creates a Manager ready to accept subscribers.

func (*Manager) AddSub

func (m *Manager) AddSub(conn net.Conn)

func (*Manager) Push

func (m *Manager) Push(snapJSON []byte)

Push sends a full snapshot to all subscribers. Failed subscribers are removed. Each write is serialized per-connection via connWriter.wmu.

func (*Manager) PushDelta

func (m *Manager) PushDelta(entries []walpkg.DeltaEntry, seqNo uint64)

PushDelta sends delta entries to all subscribers. This is much smaller than a full snapshot. Standbys that fall behind the delta window will be sent a full snapshot on the next Push().

func (*Manager) RemoveSub

func (m *Manager) RemoveSub(conn net.Conn)

func (*Manager) StartHeartbeat

func (m *Manager) StartHeartbeat(done <-chan struct{})

StartHeartbeat sends periodic heartbeat messages to all replication subscribers so standbys can detect primary failure within ~30s. It blocks until done is closed.

func (*Manager) SubCount

func (m *Manager) SubCount() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL