Documentation
¶
Overview ¶
Package syncservice owns the exact-key synchronization operation and receipt contract between ARM's leased SSH worker, syncreconcile, and syncfs. It does not open SSH channels, reserve Manager resources, or mutate selected files.
Index ¶
- Constants
- Variables
- func ConfirmBaselineTx(ctx context.Context, tx *sql.Tx, key string, side syncreconcile.Side) (syncreconcile.ConfirmedBaseline, error)
- func InstallSchemaTx(ctx context.Context, tx *sql.Tx) error
- func LoadBaseline(ctx context.Context, db *sql.DB, binding syncreconcile.Binding, ...) (*syncreconcile.ConfirmedBaseline, error)
- func NewIntent(key, workerCommandSHA256, sshControlSHA256, reason string, ...) (Intent, []ManifestRow, error)
- func PreparationFootprint(ctx context.Context, p Preparation, admission DecodeAdmission) (int64, error)
- func ReconcileIntent(i Intent, rows []ManifestRow, baseline *syncreconcile.ConfirmedBaseline) (syncreconcile.Plan, error)
- func ReserveTx(ctx context.Context, tx *sql.Tx, i Intent, rows []ManifestRow, ...) error
- func VerifyDurableSQLite(ctx context.Context, db *sql.DB) error
- func WritePreparation(w io.Writer, p Preparation) error
- type DecodeAdmission
- type Intent
- type Ledger
- func (l *Ledger) CompleteOwnSide(ctx context.Context) (SideReceipt, error)
- func (l *Ledger) ConfirmBaseline(ctx context.Context) (syncreconcile.ConfirmedBaseline, error)
- func (l *Ledger) Lookup(ctx context.Context) (Lookup, error)
- func (l *Ledger) Outcome(ctx context.Context, r syncfs.Receipt) error
- func (l *Ledger) Prepare(ctx context.Context, r syncfs.Receipt) error
- func (l *Ledger) RecordNonexecution(ctx context.Context, seal model.SSHKeyFence) error
- func (l *Ledger) RecordPeerReceipt(ctx context.Context, r SideReceipt) error
- func (l *Ledger) RecordWorkspace(ctx context.Context, role string, selected, parent *syncfs.Root, ...) error
- func (l *Ledger) Workspaces(ctx context.Context) ([]WorkspaceRecord, error)
- type Lookup
- type ManifestRow
- type PairRecovery
- type Preparation
- type SideReceipt
- type WorkspaceRecord
Constants ¶
const ( // FixedWorkerCommand is the exact versioned SSH exec commitment shared by // Manager admission and the private worker. It does not enable a CLI entry. FixedWorkerCommand = "arm sync-worker --protocol=1" Schema = 1 MaxRecordBytes = 64 << 20 MaxManifestBytes = 64 << 20 )
const BaselinesSchema = `CREATE TABLE sync_baselines (pair TEXT PRIMARY KEY,generation INTEGER NOT NULL,seal TEXT NOT NULL,record BLOB NOT NULL)`
const ChargedScopeFinalIndex = `CREATE UNIQUE INDEX sync_charged_scopes_final ON sync_charged_scopes(final_lease)`
const ChargedScopePreparationIndex = `CREATE UNIQUE INDEX sync_charged_scopes_preparation ON sync_charged_scopes(preparation_lease)`
const ChargedScopeProjectIndex = `CREATE UNIQUE INDEX sync_charged_scopes_project ON sync_charged_scopes(provider,mount_id,project_id)`
const ChargedScopeSchema = `` /* 944-byte string literal not displayed */
ChargedScopeSchema is the immutable version-3 original-scope row shape. It is installed only in a fresh, dedicated sync namespace. A row is evidence for recovery, never a reconstructed execution capability.
const EffectsSchema = `` /* 197-byte string literal not displayed */
const MaxPreparationBytes = MaxRecordBytes + MaxManifestBytes + 1<<20
const OpenGenerationSchema = `CREATE UNIQUE INDEX sync_open_generation ON sync_operations(pair,side,generation) WHERE state!='sealed'`
const OperationsSchema = `` /* 285-byte string literal not displayed */
These tables belong to the Manager's proven state schema. The Manager must install and prove them, and must reserve destination sync intent in the same transaction that admits the exact leased SSH execution. No lazy schema creation is permitted after an operation namespace has been used.
const WorkspacesSchema = `` /* 241-byte string literal not displayed */
Variables ¶
Functions ¶
func ConfirmBaselineTx ¶
func ConfirmBaselineTx(ctx context.Context, tx *sql.Tx, key string, side syncreconcile.Side) (syncreconcile.ConfirmedBaseline, error)
ConfirmBaselineTx must run after matching dual receipts are durable. The generation update is compare-and-swap against the prior baseline seal. The source and destination each call it locally; a lost reply is lookup-only.
func LoadBaseline ¶
func LoadBaseline(ctx context.Context, db *sql.DB, binding syncreconcile.Binding, side syncreconcile.Side) (*syncreconcile.ConfirmedBaseline, error)
LoadBaseline is read-only and returns nil only when the exact ordered pair has no confirmed generation. A missing row for a previously used pair must be treated as lost evidence by the Manager, not declared a first run.
func NewIntent ¶
func NewIntent(key, workerCommandSHA256, sshControlSHA256, reason string, side syncreconcile.Side, req syncreconcile.Request, reviewed syncreconcile.Plan, local, remote model.Resources, created time.Time) (Intent, []ManifestRow, error)
NewIntent recalculates the reviewed plan, so an unrelated Plan cannot be paired with different observations. A caller supplies the native snapshots, reviewed resource promises, and one exact SSH execution key.
func PreparationFootprint ¶
func PreparationFootprint(ctx context.Context, p Preparation, admission DecodeAdmission) (int64, error)
PreparationFootprint checks the canonical byte/structure allowance while the original preparation is still charged. This is a conservative policy check for handoff at either endpoint, not an allocation or RSS guarantee.
func ReconcileIntent ¶
func ReconcileIntent(i Intent, rows []ManifestRow, baseline *syncreconcile.ConfirmedBaseline) (syncreconcile.Plan, error)
ReconcileIntent reconstructs the exact reviewed plan on the destination from the selected manifest and its locally confirmed baseline. It refuses a changed generation, resolution, native name key, or proposed result.
func ReserveTx ¶
func ReserveTx(ctx context.Context, tx *sql.Tx, i Intent, rows []ManifestRow, observed syncreconcile.Snapshot) error
ReserveTx is the sole dispatch gate. A returned error, including a commit uncertainty in the caller's transaction, never authorizes SSH dispatch.
func VerifyDurableSQLite ¶
VerifyDurableSQLite checks the connection's durability setting before any intent or effect journal is trusted as a crash fence.
func WritePreparation ¶
func WritePreparation(w io.Writer, p Preparation) error
Types ¶
type DecodeAdmission ¶
DecodeAdmission must be backed by the Manager's live, charged memory hold. A resource value copied from the untrusted preparation request is not an admission. The worker supplies this before reading a preparation frame.
type Intent ¶
type Intent struct {
Schema int `json:"schema"`
Key string `json:"key"`
SSHKey string `json:"ssh_key"`
WorkerCommandSHA256 string `json:"worker_command_sha256"`
SSHControlSHA256 string `json:"ssh_control_sha256"`
Reason string `json:"reason"`
Side syncreconcile.Side `json:"side"`
Binding syncreconcile.Binding `json:"binding"`
Direction syncreconcile.Direction `json:"direction"`
LocalPolicy syncreconcile.Policy `json:"local_policy"`
RemotePolicy syncreconcile.Policy `json:"remote_policy"`
PlanDigest string `json:"plan_digest"`
Generation uint64 `json:"generation"`
PriorSeal string `json:"prior_seal,omitempty"`
ManifestDigest string `json:"manifest_digest"`
LocalResources model.Resources `json:"local_resources"`
RemoteResources model.Resources `json:"remote_resources"`
Actions []syncreconcile.Action `json:"actions"`
Resolutions []syncreconcile.Resolution `json:"resolutions,omitempty"`
Proposal syncreconcile.ConfirmedBaseline `json:"proposal"`
Created time.Time `json:"created"`
}
Intent is reserved durably at the source before SSH dispatch and at the destination in the same transaction as leased SSH admission. Local is the initiating endpoint; remote is the SSH destination.
type Ledger ¶
type Ledger struct {
DB *sql.DB
Key string
Side syncreconcile.Side
// contains filtered or unexported fields
}
Ledger is bound to one endpoint's original operation key. Its Prepare and Outcome methods implement syncfs.Journal with committed SQLite transactions. Manager must use a durable SQLite connection and rollback/WAL journal.
func (*Ledger) CompleteOwnSide ¶
func (l *Ledger) CompleteOwnSide(ctx context.Context) (SideReceipt, error)
CompleteOwnSide records one exact completion only after every expected effect has an applied durable outcome. The caller must recheck the held root and resource obligations before invoking it. It never treats a process exit or missing effect row as successful publication.
func (*Ledger) ConfirmBaseline ¶
func (l *Ledger) ConfirmBaseline(ctx context.Context) (syncreconcile.ConfirmedBaseline, error)
func (*Ledger) RecordNonexecution ¶
RecordNonexecution preserves a destination's exact SSH seal only when this source operation has no native effect or endpoint receipt. It releases the pair's first-run generation for a separately reviewed new key, while the original sealed record remains durable and lookup-only.
func (*Ledger) RecordPeerReceipt ¶
func (l *Ledger) RecordPeerReceipt(ctx context.Context, r SideReceipt) error
RecordPeerReceipt must be called only after the Manager authenticates the opposite endpoint over the leased SSH control channel. A duplicate exact receipt is harmless; it never repeats a native effect.
func (*Ledger) RecordWorkspace ¶
func (l *Ledger) RecordWorkspace(ctx context.Context, role string, selected, parent *syncfs.Root, work *syncfs.Workspace) error
RecordWorkspace binds a newly created marked workspace to the original operation before staging. Failure retains the charged obligation and native workspace; no mutation or cleanup may follow an uncertain commit.
func (*Ledger) Workspaces ¶
func (l *Ledger) Workspaces(ctx context.Context) ([]WorkspaceRecord, error)
Workspaces lists only bounded, shaped durable locators. The caller must reopen native roots to inspect them; rows alone never grant cleanup.
type Lookup ¶
type Lookup struct {
Intent Intent
Manifest []ManifestRow
State string
Effects []syncfs.Receipt
LocalReceipt *SideReceipt
RemoteReceipt *SideReceipt
Nonexecution *model.SSHKeyFence
}
type ManifestRow ¶
type ManifestRow struct {
Side syncreconcile.Side `json:"side"`
Path string `json:"path"`
NameKey string `json:"name_key"`
Entry *syncreconcile.Entry `json:"entry,omitempty"`
}
ManifestRow records either an observed selected entry or an absent candidate name. The latter binds native case/Unicode and exclusion checks at both ends.
type PairRecovery ¶
type PairRecovery struct {
Key string
PlanDigest string
Generation uint64
LocalState string
RemoteState string
LocalReceipt *SideReceipt
RemoteReceipt *SideReceipt
JointlyConfirmed bool
NeedsAttention bool
}
PairRecovery is a read-only comparison of the two original endpoint keys. NeedsAttention never authorizes a replay, cleanup, or allocation release. A caller must obtain each Ledger through its authenticated endpoint route; this comparison does not authenticate a supplied database connection.
func InspectPair ¶
func InspectPair(ctx context.Context, local, remote *Ledger) (PairRecovery, error)
InspectPair compares exact durable intent, manifest, receipts and confirmed baselines at both endpoints. Each endpoint is read independently, so a concurrent state change can cause a conservative error or attention result. It never starts a worker or writes a baseline.
type Preparation ¶
type Preparation struct {
Version int `json:"version"`
Intent Intent `json:"intent"`
Manifest []ManifestRow `json:"manifest"`
}
Preparation is the first length-framed control message on the fixed arm sync-worker SSH stream. Binary rsync payload follows only after the destination has authenticated, reconstructed, and durably reserved it.
func ReadPreparation ¶
func ReadPreparation(ctx context.Context, r io.Reader, admission DecodeAdmission) (Preparation, error)
ReadPreparation refuses oversized wire bodies before allocation, then streams manifest rows through an explicit count limit before building the decoded slice. The caller must call ReserveTx against its local baseline before acknowledging preparation or accepting any transfer payload.
func ReadPreparationWithFootprint ¶
func ReadPreparationWithFootprint(ctx context.Context, r io.Reader, admission DecodeAdmission) (Preparation, int64, error)
ReadPreparationWithFootprint returns the same conservative byte/structure budget checked during decoding. This is policy accounting, not measured RSS or a new admission: the caller still needs the original charged decoder.
type SideReceipt ¶
type SideReceipt struct {
Key string `json:"key"`
PlanDigest string `json:"plan_digest"`
Generation uint64 `json:"generation"`
Side syncreconcile.Side `json:"side"`
RootID string `json:"root_id"`
ManifestDigest string `json:"manifest_digest"`
BaselineSeal string `json:"baseline_seal"`
EffectCount int `json:"effect_count"`
EffectsDigest string `json:"effects_digest"`
}
SideReceipt is emitted only after all of one endpoint's expected native effects have durable applied outcomes and its selected root is rechecked. The receiving Manager must authenticate the peer carrying the other side's receipt; this struct is not itself a signature.
type WorkspaceRecord ¶
WorkspaceRecord is a durable locator, not authority to delete files or release a disk promise. Native roots must be reopened and checked separately.