Documentation
¶
Overview ¶
Package port declares the federation module's store ports: replications, peers and pairing nonces, federated repository membership and full syncs, the platform federation records, and Store, the part of the metadata store the module uses.
Role ¶
federation module, core layer, store ports. The module's adapters implement ReplicationStore, PeerStore, FederationStore, PlatformStore and Store: adapters/sql over the shared SQL unit of work and adapters/inmem over a shared memtx.Store, both held to the contract in adapters/storetest. The ports take and return the module's core/model values and kernel.Page, and join the unit of work of platform/tx: an outbox entry is written in the transaction of the change it records (decision 0021), so these stores run inside the shared unit of work rather than one of their own. The outbox itself, the peers' cursors and the instance identity are platform ports (platform/outbox and platform/instance).
Inputs ¶
- Replications and their runs, peers, pairing nonces, members, full-sync runs, Access Federation targets, platform federations and topologies to store; keys, ids and instance ids to look up; a PeerFilter or a kernel.Page to narrow a listing.
- The context of the caller's transaction, which every call joins.
Outputs ¶
- ReplicationStore: Put, Get, ForRepo, List, Delete and DeleteForRepo; PutRun and LastRun.
- PeerStore: Put, Get, List and Delete; AddNonce, RedeemNonce and PruneNonces.
- FederationStore: SetMembers, Members and MembersWithPeer; CreateFullSync, FullSync, UpdateFullSync and FullSyncs.
- PlatformStore: PutAccessTarget, AccessTarget, AccessTargets and DeleteAccessTarget; PutFederation, Federation, Federations and DeleteFederation; PutTopology, Topology, Topologies and DeleteTopology.
- PeerFilter.
- Store: tx.Runner, Replications, Peers, Federation and Platform.
Invariants ¶
- Errors are the kernel's sentinels, wrapped: kernel.ErrNotFound for a missing record; kernel.ErrConflict for a nonce hash that exists, two members that name one peer or two sites that share a name; and kernel.ErrInvalid for a replication without a key or a member not yet resolved to a peer.
- RedeemNonce redeems a nonce once: an unknown or expired nonce is kernel.ErrNotFound and a redeemed one kernel.ErrConflict, so a pairing token completes one pairing.
- A replication's password is sealed at rest (decision 0017).
References ¶
- Decision 0021: docs/research/decisions/0021-peer-trust-and-sync-protocol.md.
- Decision 0022: docs/research/decisions/0022-federated-repositories.md.
- Decision 0025: docs/research/decisions/0025-platform-federation-and-topology.md.
- Decision 0017: docs/research/decisions/0017-sealed-columns-and-master-key.md.
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md ("Persistence" and "Names the migration introduces", which lists Store).
- Research 15: docs/research/15-data-model.md, lines 689 and 690, 701 and 702, 707 and 708, and 719 to 721 (the tables behind these ports).
- Target layout: docs/research/architecture-options/5-modular-monolith.md, lines 100 to 103 (a storage skeleton holds core/port/store.go and its store adapters), lines 341 and 342 (the federation module's core/port), lines 577 and 578 (each module owns its store ports) and line 1055 (the metadata store split into each module's core/port/store.go).
- Plan: docs/implementation/plan.md#p2-stores, task 1, #p11-projects-webhooks-retention-replication, #p13-peer-trust-and-federated-repositories, #p14-platform-federation-and-topology and #p9d-modular-monolith-migration, epic STO (https://github.com/weaveplatform/artifactweave/issues/939).
- https://github.com/weaveplatform/artifactweave/issues/1053
Status ¶
Implemented P2: ReplicationStore, PeerStore, FederationStore and PlatformStore, with the metadata store's in-memory, SQLite and PostgreSQL stores (pull request 3). Moved here in P9d, where Store is declared. The services that call the ports arrive with P11 (replication), P13 (peer trust and federated repositories) and P14 (platform federation and topology).
Testing ¶
The package declares only ports, so it has no tests of its own. The metadata store's Replications, Peers, PairingNonces, FederationMembers, FullSyncs, AccessTargets, PlatformFederations and Topologies contract subtests run the ports on its in-memory, SQLite and PostgreSQL stores, and compile-time assertions in the in-memory and SQL stores' tests show that both satisfy Store.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FederationStore ¶
type FederationStore interface {
// SetMembers replaces a repository's members; each member's RepoKey is
// set to repoKey. kernel.ErrInvalid when a member has no PeerInstanceID
// (members are resolved to peers first), kernel.ErrConflict when two
// name the same peer.
SetMembers(ctx context.Context, repoKey string, members []model.FederationMember) error
// Members returns a repository's members ordered by peer.
Members(ctx context.Context, repoKey string) ([]model.FederationMember, error)
// MembersWithPeer returns every membership naming peer, ordered by
// repository.
MembersWithPeer(ctx context.Context, peer string) ([]model.FederationMember, error)
// CreateFullSync stores r and returns it with its assigned ID.
CreateFullSync(ctx context.Context, r model.FullSyncRun) (model.FullSyncRun, error)
// FullSync returns the run with id.
FullSync(ctx context.Context, id int64) (model.FullSyncRun, error)
// UpdateFullSync replaces a run.
UpdateFullSync(ctx context.Context, r model.FullSyncRun) error
// FullSyncs returns a repository's runs ("" for all) newest first.
FullSyncs(
ctx context.Context,
repoKey string,
p kernel.Page,
) ([]model.FullSyncRun, string, error)
}
FederationStore persists federated repository membership (decision 0022) and full-sync runs.
type PeerFilter ¶
PeerFilter narrows peer listings.
type PeerStore ¶
type PeerStore interface {
// Put creates or replaces the peer with p.InstanceID. UseCases are a
// set: duplicates are dropped and Get and List return them sorted.
Put(ctx context.Context, p model.Peer) error
// Get returns the peer.
Get(ctx context.Context, instanceID string) (model.Peer, error)
// List returns matching peers ordered by instance ID.
List(ctx context.Context, f PeerFilter) ([]model.Peer, error)
// Delete removes the peer.
Delete(ctx context.Context, instanceID string) error
// AddNonce stores an issued pairing nonce; kernel.ErrConflict when its
// hash exists.
AddNonce(ctx context.Context, n model.PairingNonce) error
// RedeemNonce marks the nonce redeemed at now and returns it. A nonce is
// single-use: kernel.ErrNotFound when unknown or expired at now,
// kernel.ErrConflict when already redeemed.
RedeemNonce(ctx context.Context, hash []byte, now time.Time) (model.PairingNonce, error)
// PruneNonces removes nonces that expired before t and returns how many.
PruneNonces(ctx context.Context, before time.Time) (int64, error)
}
PeerStore persists paired peers and outstanding pairing nonces.
type PlatformStore ¶
type PlatformStore interface {
// PutAccessTarget creates or replaces the target with t.Name.
PutAccessTarget(ctx context.Context, t model.AccessFederationTarget) error
// AccessTarget returns one target.
AccessTarget(ctx context.Context, name string) (model.AccessFederationTarget, error)
// AccessTargets returns every target ordered by name.
AccessTargets(ctx context.Context) ([]model.AccessFederationTarget, error)
// DeleteAccessTarget removes a target.
DeleteAccessTarget(ctx context.Context, name string) error
// PutFederation creates or replaces the federation with f.ID.
PutFederation(ctx context.Context, f model.PlatformFederation) error
// Federation returns one federation.
Federation(ctx context.Context, id string) (model.PlatformFederation, error)
// Federations returns every federation ordered by ID.
Federations(ctx context.Context) ([]model.PlatformFederation, error)
// DeleteFederation removes a federation.
DeleteFederation(ctx context.Context, id string) error
// PutTopology creates or replaces the topology with t.Key and its sites;
// kernel.ErrConflict when two sites share a name.
PutTopology(ctx context.Context, t model.Topology) error
// Topology returns one topology with its sites ordered by site name.
Topology(ctx context.Context, key string) (model.Topology, error)
// Topologies returns every topology ordered by key.
Topologies(ctx context.Context) ([]model.Topology, error)
// DeleteTopology removes a topology and its sites.
DeleteTopology(ctx context.Context, key string) error
}
PlatformStore persists Access Federation targets, platform federations and topologies (decision 0025).
type ReplicationStore ¶
type ReplicationStore interface {
// Put creates or replaces the replication with r.Key; kernel.ErrInvalid
// when the key is empty.
Put(ctx context.Context, r model.Replication) error
// Get returns the replication with key.
Get(ctx context.Context, key string) (model.Replication, error)
// ForRepo returns a repository's replications ordered by key.
ForRepo(ctx context.Context, repoKey string) ([]model.Replication, error)
// List returns every replication ordered by (repository, key).
List(ctx context.Context) ([]model.Replication, error)
// Delete removes a replication and its runs.
Delete(ctx context.Context, key string) error
// DeleteForRepo removes every replication of a repository.
DeleteForRepo(ctx context.Context, repoKey string) error
// PutRun creates or replaces the run (r.ReplicationKey, r.Started);
// kernel.ErrNotFound when the replication does not exist.
PutRun(ctx context.Context, r model.ReplicationRun) error
// LastRun returns a replication's most recent run.
LastRun(ctx context.Context, key string) (model.ReplicationRun, error)
}
ReplicationStore persists replication targets and their run history. The replication key is assigned by the caller; the password is sealed.
type Store ¶
type Store interface {
tx.Runner
Replications() ReplicationStore
Peers() PeerStore
Federation() FederationStore
Platform() PlatformStore
}
Store is the part of the metadata store the federation module uses: replications, peers, federated repository membership and full syncs, and the platform federation records, with the shared unit of work (tx.Runner). Stream positions are assigned in the transaction of the change they record (decision 0021), so the federation stores run inside that unit of work rather than one of their own.