sqlite

package
v0.6.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackupDatabase added in v0.6.0

func BackupDatabase(ctx context.Context, source, destination string) (string, error)

BackupDatabase writes a consistent copy of the database file at source to destination, and answers with the path it wrote.

It exists because the documented recovery procedure shelled out to the `sqlite3` CLI, which Mercator does not ship: the daemon is built on modernc.org/sqlite, a pure-Go SQLite with no binary beside it, so the one documented way to take a backup was a command that is absent from the container image and from most hosts. A recovery procedure nobody can run is not a recovery procedure.

VACUUM INTO is SQLite's own online backup. It reads the source inside a single read transaction, so the copy is the database as of one instant even while a server is writing to it, and it writes a defragmented file rather than a byte copy, so the result needs no companion -wal or -shm file to be complete.

It deliberately does not open a Storage. Opening one runs every migration and purges the credentials of deleted connections, which are writes, and a process taking a copy of a live server's database has no business writing to it.

Both paths are resolved to absolute ones before anything opens them, because this process and SQLite both read them and they agree only on that form. SQLite takes a destination beginning with "file:" as a URI, so `mercator backup file:latest.db` used to write the copy over "latest.db" while claiming an empty file literally named "file:latest.db", destroying whatever the real path held and reporting the wrong file as the backup. The source is read by SQLite alone, through the URI below, which renders a relative path with an authority: a deployment served with MERCATOR_SQLITE_DSN=file:mercator.db, which starts and serves normally, was refused every backup with "invalid uri authority: mercator.db".

Types

type ConnectionRepository

type ConnectionRepository struct {
	*eventlog.SQLiteEventLog
	// contains filtered or unexported fields
}

func (*ConnectionRepository) CreateCredential

func (*ConnectionRepository) DeleteCredential

type NodeStore added in v0.6.0

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

NodeStore is the durable node registry. A registry that forgets across a restart cannot promise not to launch twice, so every fact the reconciliation path needs is written here before a command reaches a node.

func (*NodeStore) AppendOperation added in v0.6.0

func (store *NodeStore) AppendOperation(ctx context.Context, operation node.Operation) (node.Operation, bool, error)

func (*NodeStore) AppliedOperationIDs added in v0.6.0

func (store *NodeStore) AppliedOperationIDs(ctx context.Context, nodeID string) ([]string, error)

func (*NodeStore) Enroll added in v0.6.0

func (store *NodeStore) Enroll(
	ctx context.Context,
	nodeID string,
	enrollment node.Enrollment,
) (node.Record, error)

func (*NodeStore) ExpireLeases added in v0.6.0

func (store *NodeStore) ExpireLeases(ctx context.Context, now time.Time) ([]node.Record, error)

func (*NodeStore) Find added in v0.6.0

func (store *NodeStore) Find(ctx context.Context, nodeID string) (node.Record, error)

func (*NodeStore) Get added in v0.6.0

func (store *NodeStore) Get(ctx context.Context, nodeID string) (node.Record, error)

func (*NodeStore) Heartbeat added in v0.6.0

func (store *NodeStore) Heartbeat(
	ctx context.Context,
	nodeID string,
	facts capability.NodeFacts,
	leaseExpires time.Time,
) (node.Record, error)

func (*NodeStore) Invite added in v0.6.0

func (store *NodeStore) Invite(ctx context.Context, record node.Record) error

func (*NodeStore) LatestWorkload added in v0.6.0

func (store *NodeStore) LatestWorkload(
	ctx context.Context,
	nodeID, runID, attemptID string,
) (capability.WorkloadObservation, bool, error)

func (*NodeStore) List added in v0.6.0

func (store *NodeStore) List(ctx context.Context) ([]node.Record, error)

func (*NodeStore) PendingOperations added in v0.6.0

func (store *NodeStore) PendingOperations(ctx context.Context, nodeID string) ([]node.Operation, error)

func (*NodeStore) RecordEvent added in v0.6.0

func (store *NodeStore) RecordEvent(ctx context.Context, event node.Event) (bool, error)

func (*NodeStore) Reinvite added in v0.6.0

func (store *NodeStore) Reinvite(ctx context.Context, nodeID, enrollmentTokenID string, expires time.Time) error

func (*NodeStore) Retire added in v0.6.0

func (store *NodeStore) Retire(ctx context.Context, nodeID string) error

func (*NodeStore) SettleOperation added in v0.6.0

func (store *NodeStore) SettleOperation(ctx context.Context, nodeID string, result node.Result) error

func (*NodeStore) Workloads added in v0.6.0

func (store *NodeStore) Workloads(ctx context.Context, nodeID string) ([]capability.WorkloadObservation, error)

type PreparationClock added in v0.6.0

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

PreparationClock is when this control plane last began preparing content for work it has not admitted. There is one row because the bound it serves is the fleet's: what it protects is a machine's link and this process's own egress, and every Run shares both.

It records a decision Mercator made rather than anything a machine holds, which is what makes it durable state Mercator is allowed to keep. The desired sets stay in process for the opposite reason: they are a cache's contents seen from here, they are derived from the event log, and restating one is answered Duplicate.

func (*PreparationClock) LastBegan added in v0.6.0

func (clock *PreparationClock) LastBegan(ctx context.Context) (time.Time, bool, error)

LastBegan is the moment preparation last started, and whether it ever has.

func (*PreparationClock) RecordBegan added in v0.6.0

func (clock *PreparationClock) RecordBegan(ctx context.Context, at time.Time) error

RecordBegan stamps the moment preparation started. The latest moment wins however two writers reach it, because the bound is about how recently anything began and a stale write must never make a fresh transfer look old.

type RentalScheduleStore added in v0.5.0

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

func (*RentalScheduleStore) Commit added in v0.5.0

func (store *RentalScheduleStore) Commit(
	ctx context.Context,
	event eventlog.AppendRequest,
	expectedVersion uint64,
	next domain.RentalSchedule,
	run domain.RunRecord,
) (eventlog.AppendResult, error)

func (*RentalScheduleStore) List added in v0.5.0

type RentalStore added in v0.6.0

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

RentalStore is the durable record of the capacity Mercator holds. A control plane that forgot a lease across a restart would leave the machine behind it billing with nothing able to name it, which is why every generation is written here before anything acts on it.

func (*RentalStore) Get added in v0.6.0

func (store *RentalStore) Get(ctx context.Context, rentalID string) (domain.Rental, error)

func (*RentalStore) List added in v0.6.0

func (store *RentalStore) List(ctx context.Context) ([]domain.Rental, error)

func (*RentalStore) Save added in v0.6.0

func (store *RentalStore) Save(ctx context.Context, expectedVersion uint64, next domain.Rental) error

type RunStore added in v0.6.0

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

func (*RunStore) Append added in v0.6.0

func (store *RunStore) Append(
	ctx context.Context,
	request eventlog.AppendRequest,
	next domain.RunRecord,
) (eventlog.AppendResult, error)

func (*RunStore) List added in v0.6.0

func (store *RunStore) List(
	ctx context.Context,
	request runprojection.PageRequest,
) (runprojection.Page, error)

func (*RunStore) ListOpenIDs added in v0.6.0

func (store *RunStore) ListOpenIDs(ctx context.Context) ([]string, error)

func (*RunStore) MarkRebuilt added in v0.6.0

func (store *RunStore) MarkRebuilt(ctx context.Context) error

func (*RunStore) Replace added in v0.6.0

func (store *RunStore) Replace(ctx context.Context, records []domain.RunRecord) error

func (*RunStore) RequiresRebuild added in v0.6.0

func (store *RunStore) RequiresRebuild(ctx context.Context) (bool, error)

type Storage

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

func New

func New(ctx context.Context, db *sql.DB) (*Storage, error)

New takes ownership of db.

func Open

func Open(ctx context.Context, dsn string) (*Storage, error)

func (*Storage) Close

func (s *Storage) Close() error

func (*Storage) Connections

func (s *Storage) Connections(sealer credentialSealer) (*ConnectionRepository, error)

func (*Storage) CredentialStore

func (s *Storage) CredentialStore() *credential.SQLiteStore

func (*Storage) EventLog

func (s *Storage) EventLog() *eventlog.SQLiteEventLog

func (*Storage) Nodes added in v0.6.0

func (s *Storage) Nodes() *NodeStore

Nodes is the durable registry of enrolled node identities, the commands they were given, and what they reported back.

func (*Storage) Preparation added in v0.6.0

func (s *Storage) Preparation() *PreparationClock

Preparation is when this control plane last began preparing capacity speculatively, which is the one part of that decision a restart may not forget.

func (*Storage) RentalSchedules added in v0.5.0

func (s *Storage) RentalSchedules() *RentalScheduleStore

func (*Storage) Rentals added in v0.6.0

func (s *Storage) Rentals() *RentalStore

Rentals is the durable record of the capacity Mercator holds: the leases it has taken and the generations each of them has been through.

func (*Storage) Runs added in v0.6.0

func (s *Storage) Runs() *RunStore

Jump to

Keyboard shortcuts

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