repl

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 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 repl is the hub's end of the one way a machine's data is replicated over the link (hubproto.FeatureRepl, docs/hub/replication.md): batches of a kind, numbered on the link, stored in order and acknowledged, sent again from the oldest one the hub has not stored, and held on the machine while a window of them waits for the hub. It also keeps the one measure of how far the hub's copy of each kind is behind (harnessly_hub_repl_lag_seconds{kind}).

Index

Constants

View Source
const (
	ResultStored    = "stored"    // stored and acknowledged
	ResultRetry     = "retry"     // not stored; the agent sends it again after a pause
	ResultDuplicate = "duplicate" // stored before: acknowledged again
	ResultGap       = "gap"       // one before it is missing: not stored, the agent sends from the missing one
	ResultBad       = "bad"       // can never be stored: acknowledged and skipped
)

Results of a batch, the label of harnessly_hub_repl_batches_total.

View Source
const KindUnknown = "unknown"

KindUnknown is the label of the batches of a kind the hub did not name.

Variables

View Source
var ErrBad = errors.New("batch can never be stored")

ErrBad is what a handler returns for a batch that can never be stored: it is acknowledged and not sent again.

View Source
var Kinds = []Kind{
	{Name: hubproto.ReplHistoryEvents, DataKind: "chat history", Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck, hubproto.OpHistoryAck},
		Legacy: "history.events frames on the bulk queue, dropped when it is full; the channel's own ack and resend"},
	{Name: hubproto.ReplHistoryBackfill, DataKind: "chat history", Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck, hubproto.OpHistoryStart},
		Legacy: "history.backfill frames on the bulk queue, dropped when it is full and never acknowledged; history.start again after a drop"},
	{Name: "usage", DataKind: "spend", Transport: TransportPull, Lag: true,
		Wire: []string{hubproto.EventUsageAvailable, hubproto.OpUsageRead, hubproto.OpUsageAck}},
	{Name: hubproto.EventMetricsSample, DataKind: "what a machine reports about itself", Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck},
		Legacy: "metrics.sample on the event queue; a full queue closes the link"},
	{Name: hubproto.EventEnvState, DataKind: "what a machine reports about itself", Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck},
		Legacy: "env.state on the event queue; a full queue closes the link"},
	{Name: hubproto.EventEnvRun, DataKind: "what a machine reports about itself", Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck},
		Legacy: "env.run on the event queue; a full queue closes the link"},
	{Name: hubproto.EventRestart, DataKind: "what a machine reports about itself", Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck},
		Legacy: "restart on the event queue; a full queue closes the link"},
	{Name: hubproto.EventProjects, DataKind: "what a machine reports about itself", Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck},
		Legacy: "projects on the event queue; a full queue closes the link"},
	{Name: hubproto.EventDocPublish, Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck, hubproto.OpDocResult},
		Legacy: "doc.publish on the event queue; the agent waits for doc.result and the person tries again"},
	{Name: hubproto.EventDocACL, Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck, hubproto.OpDocResult},
		Legacy: "doc.acl on the event queue; the agent waits for doc.result"},
	{Name: hubproto.EventDocBound, Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck},
		Legacy: "docs.bound on the event queue, lost when the link is down"},
	{Name: hubproto.EventDocReply, Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck},
		Legacy: "docs.reply on the event queue, lost when the link is down"},
	{Name: hubproto.EventDesign, DataKind: "designs", Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck, hubproto.OpDesignAccess},
		Legacy: "design on the event queue; the agent tries again only when no link took it"},
	{Name: hubproto.EventAutomationResult, DataKind: "automations", Transport: TransportBatches, Lag: true,
		Wire:   []string{hubproto.EventReplBatch, hubproto.OpReplAck},
		Legacy: "automations.result on the event queue; agents without batches send it to cluster links only"},
	{Name: "memory", DataKind: "agent memory", Transport: TransportHTTP,
		Wire: []string{hubproto.MemoryPullPath, hubproto.MemoryPutPath}},
	{Name: "attachments", DataKind: "chat attachments", Transport: TransportHTTP,
		Wire: []string{"PUT <platform api>/uploads/blobs, /uploads/refs: the page puts the bytes into the hub beside the machine"}},
	{Name: "chat snapshots", DataKind: "chat snapshots shared with the space", Transport: TransportHTTP,
		Wire: []string{"POST, DELETE <platform api>/shares: the hub keeps the page the machine answers a publish with and ends a revoked one itself"}},
	{Name: "machine hello", DataKind: "what a machine reports about itself", Transport: TransportEvent,
		Wire: []string{hubproto.OpHello}},
}

Kinds is the map of what machines replicate to the hub (docs/hub/replication.md). Every data kind of the register that a machine owns is here (the tests check it); a kind that moves to batches changes its Transport here.

Functions

func Batched

func Batched() []string

Batched are the kinds that travel as repl.batch.

func Measured

func Measured() []string

Measured are the kinds written in harnessly_hub_repl_lag_seconds, at 0 while nothing waits.

Types

type Acker

type Acker func(ctx context.Context, ack hubproto.ReplAck) error

Acker sends a repl.ack to the agent of the link. It may be slow: the receiver calls it off the handling of batches.

type Handler

type Handler func(ctx context.Context, data json.RawMessage) error

Handler stores one batch of a kind. An error other than ErrBad has the agent send the batch again after a pause.

type Kind

type Kind struct {
	Name      string
	DataKind  string
	Transport Transport
	// Lag says the kind is in harnessly_hub_repl_lag_seconds.
	Lag  bool
	Wire []string
	// Legacy is how an agent without hubproto.FeatureRepl sends it, for a kind that moved to batches.
	Legacy string
}

Kind is one kind of data a machine sends to the hub: the data kind of the register (store.DataKinds) it fills ("" for a request to the hub rather than a copy of the machine's data: the documents' events), how it travels, and its names on the link (the batch kind or the events and operations).

type Receiver

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

Receiver takes the batches of one link. Batches are handed to it one by one in the order the link read them.

func NewReceiver

func NewReceiver(stats *Stats, machineID string, handlers map[string]Handler, ack Acker, log *slog.Logger) *Receiver

NewReceiver makes the receiver of one link and counts it in stats until Close. handlers name the kinds it takes.

func (*Receiver) Close

func (r *Receiver) Close()

Close takes the receiver out of the measure: its link is gone.

func (*Receiver) Handle

func (r *Receiver) Handle(ctx context.Context, raw json.RawMessage, at time.Time)

Handle stores a repl.batch frame read at `at` and acknowledges it.

func (*Receiver) Kinds

func (r *Receiver) Kinds() []string

Kinds are the kinds the receiver takes, for repl.start.

func (*Receiver) Start

func (r *Receiver) Start() hubproto.ReplStart

Start is the repl.start the agent is told: every kind's numbering begins again.

type Stats

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

Stats is what the receivers of a hub add up to.

func NewStats

func NewStats() *Stats

NewStats makes an empty measure.

func (*Stats) Lag

func (s *Stats) Lag(now time.Time) map[string]time.Duration

Lag is, by kind, how long the oldest batch read and not stored has waited, among the links of this replica.

func (*Stats) Write

func (s *Stats) Write(w *metrics.Writer, now time.Time, kinds []string, other map[string]time.Duration)

Write writes the measure of every kind: the lag (with what the kinds outside the batches measure themselves, by kind in `other`) and the batches by result. Every kind in kinds is written, at 0 while nothing of it waits.

type Transport

type Transport string

Transport is how a kind of a machine's data reaches the hub.

const (
	// TransportBatches: repl.batch over the link (this package): numbered, acknowledged, windowed, sent again.
	TransportBatches Transport = "batches"
	// TransportPull: the hub reads the machine's outbox by a cursor over the link and acknowledges what it stored.
	TransportPull Transport = "pull"
	// TransportEvent: a single event over the link, applied once; nothing is sent again if it is lost.
	TransportEvent Transport = "event"
	// TransportHTTP: the machine calls the hub's HTTP API, signed with its key, and tries again itself.
	TransportHTTP Transport = "http"
)

Jump to

Keyboard shortcuts

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