sqlite

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package sqlite keeps one executor's persisted work and terminal results across restarts without silently running stored work again. A failed write cannot provide that persistence guarantee.

The in-memory core owns admission, owners and phases; this package owns the canonical rows behind them. Restoring reads the stored runs and applies the startup eligibility policy: a row whose control binding the new session cannot own is quarantined, which means it stays persisted, is never started under the new binding and is counted so an operator can see it. Terminal results are retained under the binding that chose them, and released, updated or kept as evidence as scheduler.TerminalRetention describes.

Inspecting a stopped executor's database reports that disposition without running, starting or deleting anything.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InspectDisposition

func InspectDisposition(ctx context.Context, path string) (d scheduler.Disposition, err error)

InspectDisposition reads what a stopped executor's database still holds.

It is an inspection, not a recovery: the database is opened read-only, no row is scheduled, finalized or deleted, and nothing here decides what happens to retained work. It is meant for the moment after local ownership has joined and before an operator decides whether the node may be upgraded or rebuilt, so it never opens a database a daemon is still serving on purpose: a caller must prove the join first.

func PreserveDatabaseOwnership added in v0.3.0

func PreserveDatabaseOwnership(path string, operation func() error) error

PreserveDatabaseOwnership gives any newly created SQLite sidecars the database owner's identity. The operation must close all handles before it returns. Existing sidecars are untouched and no locking file is unlinked.

Types

type ArchivedRun added in v0.3.0

type ArchivedRun struct {
	RunID             uuid.UUID              `json:"run_id"`
	OriginalBinding   controlsession.Binding `json:"original_binding"`
	ExecutionRetained bool                   `json:"execution_retained"`
	OutputRetained    bool                   `json:"output_retained"`
	TerminalRetained  bool                   `json:"terminal_retained"`
	StartedAt         *time.Time             `json:"started_at"`
	ArchivedAt        *time.Time             `json:"archived_at"`
	Reason            string                 `json:"reason"`
}

ArchivedRun describes retained evidence and a separate local operator decision. An archive never establishes a remote outcome or a safe retry.

func ArchiveRun added in v0.3.0

func ArchiveRun(ctx context.Context, db *sql.DB, id uuid.UUID, reason string) (ArchivedRun, error)

ArchiveRun requires the caller to hold exclusive database ownership after joined shutdown. Only a separate disposition is written; evidence stays put.

func InspectArchive added in v0.3.0

func InspectArchive(ctx context.Context, db database.DBTX, id uuid.UUID) (ArchivedRun, error)

InspectArchive reads one run's metadata without loading its program or output.

type SqliteStorage

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

SqliteStorage naively uses the memory storage under the hood, but saves all debuglet specs to a SQLite database to persist states across executor restarts.

func NewStorage

func NewStorage(db *sql.DB, output *outputstore.Store, eligibility scheduler.RestoreEligibility, admission scheduler.Admission, queueLimits scheduler.QueueLimits) (*SqliteStorage, error)

NewStorage persists the in-memory core's accepted work. Its admission guards are the ones that core commits new reservations and queue promotion under.

func (*SqliteStorage) Cancel

func (s *SqliteStorage) Cancel(ctx context.Context, id uuid.UUID, cause error) (bool, error)

func (*SqliteStorage) CancelBound

func (s *SqliteStorage) CancelBound(ctx context.Context, id uuid.UUID, binding controlsession.Binding, cause error) (bool, error)

func (*SqliteStorage) Insert

func (s *SqliteStorage) Insert(ctx context.Context, spec scheduler.Spec) error

func (*SqliteStorage) InspectRetainedRun

func (s *SqliteStorage) InspectRetainedRun(ctx context.Context, id uuid.UUID, current controlsession.Binding) (scheduler.RetainedRun, error)

InspectRetainedRun reads one stored row without scheduling, finalizing or deleting anything. Rows belonging to the caller's current binding are excluded, and that exclusion stays distinguishable from an absent row.

func (*SqliteStorage) ListAllRetainedTerminals

func (s *SqliteStorage) ListAllRetainedTerminals(ctx context.Context, limit int64) ([]scheduler.TerminalEvent, error)

ListAllRetainedTerminals reads the oldest unreconciled events whatever their binding or rejection, which is what an operator inspecting the executor sees.

func (*SqliteStorage) ListRetainedTerminals

func (s *SqliteStorage) ListRetainedTerminals(ctx context.Context, binding controlsession.Binding, limit int64) ([]scheduler.TerminalEvent, error)

ListRetainedTerminals reads the oldest events the given binding can still deliver. Filtering happens in the query, so events belonging to replaced sessions and events the dispatcher already rejected cannot occupy the limit.

func (*SqliteStorage) NoteTerminalFailure

func (s *SqliteStorage) NoteTerminalFailure(ctx context.Context, id uuid.UUID, binding controlsession.Binding, attempt scheduler.TerminalAttempt) error

NoteTerminalFailure counts one completed delivery attempt. Only the binding the run was accepted under may write here, so a replacement session cannot touch the events of the session it replaced.

func (*SqliteStorage) QuarantinedCount

func (s *SqliteStorage) QuarantinedCount() int64

QuarantinedCount reports the count observed by the latest serialized restore. Callers serialize RestoreFromDatabase with startup and subsequent restores.

func (*SqliteStorage) RecordTerminal

func (s *SqliteStorage) RecordTerminal(ctx context.Context, event scheduler.TerminalEvent) error

RecordTerminal retains the chosen result under the run's immutable identity. The first write wins, so a repeated report can never change the result a duplicate delivery would confirm.

func (*SqliteStorage) RegisterFailed

func (s *SqliteStorage) RegisterFailed(cb scheduler.FailedFunc)

func (*SqliteStorage) RegisterOnStart

func (s *SqliteStorage) RegisterOnStart(cb scheduler.StartFunc)

func (*SqliteStorage) ReleaseTerminal

func (s *SqliteStorage) ReleaseTerminal(ctx context.Context, id uuid.UUID, binding controlsession.Binding) error

ReleaseTerminal ends retention once an acknowledgement has been observed. Its own commit is the durable record that the result is no longer pending.

func (*SqliteStorage) Remove

func (s *SqliteStorage) Remove(ctx context.Context, debugletID uuid.UUID) (bool, error)

func (*SqliteStorage) RestoreFromDatabase

func (s *SqliteStorage) RestoreFromDatabase(ctx context.Context) error

func (*SqliteStorage) RetainedTerminal

func (s *SqliteStorage) RetainedTerminal(ctx context.Context, id uuid.UUID) (scheduler.TerminalEvent, bool, error)

RetainedTerminal answers whether one run still has an unreconciled result.

func (*SqliteStorage) RetainedTerminalCount

func (s *SqliteStorage) RetainedTerminalCount() int64

RetainedTerminalCount reports the unreconciled events observed by the latest serialized restore, alongside QuarantinedCount.

func (*SqliteStorage) Shutdown

func (s *SqliteStorage) Shutdown(ctx context.Context) error

func (*SqliteStorage) StartLoop

func (s *SqliteStorage) StartLoop(ctx context.Context) error

Jump to

Keyboard shortcuts

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