replicator

package
v0.0.0-...-c46dd35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package replicator is the registrar's cross-region etcd replicator (proposal 006 Phase 2a). Leader-elected (one mirror stream per region), it watches this region's OWN authoritative subtree (<root>/<region>/clusters/<cluster>/…) in the local etcd and replays every change verbatim (Put→Put, Delete→Delete) into each peer region's etcd.

Partitions are origin-first and disjoint, so mirroring is loop-free by construction: a peer's replicator watches only its own subtree and never re-mirrors keys this region wrote into it. Peer registrars see the mirrored keys as read-only foreign endpoints (EDS priority 2, proposal 004 locality).

Every mirrored key is attached to a per-peer origin-heartbeat lease (Phase 2b) that only this replicator's KeepAlive refreshes: if the origin region dies, the lease lapses and the peer drops the whole mirrored subtree together — whole-region failover cleanup without any peer judging the origin dead. Clean shutdown deliberately does NOT revoke the lease (that would wipe the mirror on every leader handoff); the next leader re-syncs under a fresh lease well inside the TTL. See lease.go.

Index

Constants

View Source
const DefaultLeaseTTLSeconds = 30

DefaultLeaseTTLSeconds is the origin-heartbeat lease TTL (proposal 006 Phase 2b). It bounds two windows at once: how long a dead origin's mirror lingers on peers (failover cleanup latency) and how long a leader handoff has to re-sync before the mirror expires mid-roll. 30s comfortably covers registrar leader election while keeping whole-region cleanup prompt.

Variables

This section is empty.

Functions

This section is empty.

Types

type Peer

type Peer struct {
	Region    string
	Endpoints []string
}

Peer is one peer region's etcd, the mirror destination.

func ParsePeers

func ParsePeers(entries []string, ownRegion string) ([]Peer, error)

ParsePeers parses repeated --peer-etcd values of the form <region>=<endpoint>[,<endpoint>...] into Peers. The region is the replication unit, so the own region must be explicit (not the single-region default) and peer regions must be distinct from it and from each other.

type Replicator

type Replicator struct {
	Source Source
	Peers  []Peer
	Log    *slog.Logger

	// DialTimeout bounds each peer dial; ResyncBackoff spaces mirror-loop
	// restarts after an error; LeaseTTLSeconds is the origin-heartbeat lease
	// TTL on each peer (Phase 2b). Zero values take the defaults.
	DialTimeout     time.Duration
	ResyncBackoff   time.Duration
	LeaseTTLSeconds int64
	// contains filtered or unexported fields
}

Replicator mirrors the local own-partition subtree into each peer's etcd. It is a leader-elected manager Runnable: exactly one replica per region holds the mirror streams.

func (*Replicator) NeedLeaderElection

func (r *Replicator) NeedLeaderElection() bool

NeedLeaderElection makes the replicator run only on the elected leader (one mirror stream per origin region; two would double-write peers).

func (*Replicator) Start

func (r *Replicator) Start(ctx context.Context) error

Start runs one independent mirror loop per peer until the context is cancelled. Peers are isolated: a slow or unreachable peer resyncs on its own backoff without stalling the others.

type Source

type Source interface {
	Client() *clientv3.Client
	OwnPrefix() string
}

Source is the local authoritative store the replicator mirrors from: the etcd-backed registry's client plus its own-partition root. Implemented by the etcd-backed registry (registry/internal/etcd); other backends don't, which is what gates the replicator to the etcd backend.

Jump to

Keyboard shortcuts

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