state

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package state stores Ramen resources, revisions, runs, events, locks, and audit records in a local SQLite database.

The state package is part of Ramen's supported v0.1 core API.

Index

Constants

View Source
const (
	ExportVersion = "ramen.state.export.v1"
	AuditVersion  = "ramen.audit.v1"
)
View Source
const SchemaVersion = 4

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath(configDir string) string

func Init

func Init(ctx context.Context, path string) error

func Restore

func Restore(ctx context.Context, statePath, fromPath string, force bool) error

func WorkspacePath

func WorkspacePath(configDir, workspace string) (string, error)

Types

type AsyncEvidenceFilter

type AsyncEvidenceFilter struct {
	RunID           int64
	ResourceAddress string
	RecordKind      string
}

type AsyncEvidenceRecord

type AsyncEvidenceRecord struct {
	ID                int64     `json:"id,omitempty"`
	RunID             int64     `json:"run_id,omitempty"`
	ResourceAddress   string    `json:"resource_address,omitempty"`
	Action            string    `json:"action,omitempty"`
	OperationID       string    `json:"operation_id,omitempty"`
	RecordKind        string    `json:"record_kind"`
	Phase             string    `json:"phase,omitempty"`
	EvidenceID        string    `json:"evidence_id"`
	AttemptID         string    `json:"attempt_id,omitempty"`
	RequestEvidenceID string    `json:"request_evidence_id,omitempty"`
	Sequence          int64     `json:"sequence,omitempty"`
	RecordJSON        string    `json:"record_json"`
	CreatedAt         time.Time `json:"created_at,omitempty"`
}

type AuditDocument

type AuditDocument struct {
	Version       string                `json:"version"`
	SchemaVersion int                   `json:"schemaVersion"`
	ExportedAt    time.Time             `json:"exportedAt"`
	Digest        string                `json:"digest"`
	Counts        map[string]int        `json:"counts"`
	Migrations    []MigrationRecord     `json:"migrations,omitempty"`
	Runs          []Run                 `json:"runs,omitempty"`
	RunEvents     []RunEvent            `json:"run_events,omitempty"`
	AsyncEvidence []AsyncEvidenceRecord `json:"async_evidence,omitempty"`
	Locks         []Lock                `json:"locks,omitempty"`
}

type ExportDocument

type ExportDocument struct {
	Version       string                `json:"version"`
	SchemaVersion int                   `json:"schemaVersion"`
	ExportedAt    time.Time             `json:"exportedAt"`
	Migrations    []MigrationRecord     `json:"migrations"`
	Resources     []ResourceSnapshot    `json:"resources"`
	Revisions     []Revision            `json:"revisions"`
	Runs          []Run                 `json:"runs"`
	RunEvents     []RunEvent            `json:"run_events,omitempty"`
	AsyncEvidence []AsyncEvidenceRecord `json:"async_evidence,omitempty"`
	Locks         []Lock                `json:"locks"`
}

type Lock

type Lock struct {
	Name        string
	Holder      string
	Host        string
	PID         int
	RunID       int64
	AcquiredAt  time.Time
	ExpiresAt   time.Time
	HeartbeatAt time.Time
}

type LockHeldError

type LockHeldError struct {
	Name        string
	Holder      string
	Host        string
	PID         int
	RunID       int64
	AcquiredAt  time.Time
	ExpiresAt   time.Time
	HeartbeatAt time.Time
}

func (LockHeldError) Error

func (e LockHeldError) Error() string

type LockHolderMismatchError

type LockHolderMismatchError struct {
	Name        string
	Holder      string
	Expected    string
	Host        string
	PID         int
	RunID       int64
	AcquiredAt  time.Time
	ExpiresAt   time.Time
	HeartbeatAt time.Time
}

func (LockHolderMismatchError) Error

func (e LockHolderMismatchError) Error() string

type LockNotFoundError

type LockNotFoundError struct {
	Name string
}

func (LockNotFoundError) Error

func (e LockNotFoundError) Error() string

type LockOptions

type LockOptions struct {
	Name   string
	Holder string
	TTL    time.Duration
	Host   string
	PID    int
	RunID  int64
}

type MigrationRecord

type MigrationRecord struct {
	Version   int       `json:"version"`
	AppliedAt time.Time `json:"appliedAt"`
}

type ResourceSnapshot

type ResourceSnapshot struct {
	Address             string
	Type                string
	Provider            string
	DesiredHash         string
	IdentityJSON        string
	AttributesJSON      string
	IdentitySecretRef   string
	AttributesSecretRef string
	Status              string
	SourceKind          string
	SourceID            string
	OperationID         string
	UpdatedRunID        int64
	UpdatedAt           time.Time
}

type Revision

type Revision struct {
	ID              int64
	ResourceAddress string
	RunID           int64
	Action          string
	BeforeJSON      string
	AfterJSON       string
	DiffJSON        string
	CreatedAt       time.Time
}

type Run

type Run struct {
	ID          int64
	Command     string
	StartedAt   time.Time
	FinishedAt  time.Time
	Status      string
	SummaryJSON string
}

type RunEvent

type RunEvent struct {
	ID              int64     `json:"id,omitempty"`
	RunID           int64     `json:"run_id,omitempty"`
	ResourceAddress string    `json:"resource_address,omitempty"`
	Action          string    `json:"action,omitempty"`
	OperationID     string    `json:"operation_id,omitempty"`
	Phase           string    `json:"phase"`
	Message         string    `json:"message,omitempty"`
	MetadataJSON    string    `json:"metadata_json,omitempty"`
	CreatedAt       time.Time `json:"created_at,omitempty"`
}

type Store

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

func Open

func Open(ctx context.Context, path string) (*Store, error)

func OpenReadOnly

func OpenReadOnly(ctx context.Context, path string) (*Store, error)

func (*Store) AcquireLock

func (s *Store) AcquireLock(ctx context.Context, name, holder string, ttl time.Duration) error

func (*Store) AcquireLockWithOptions

func (s *Store) AcquireLockWithOptions(ctx context.Context, opts LockOptions) error

func (*Store) AttachLockRun

func (s *Store) AttachLockRun(ctx context.Context, name, holder string, runID int64) error

func (*Store) Audit

func (s *Store) Audit(ctx context.Context) (AuditDocument, error)

func (*Store) Backup

func (s *Store) Backup(ctx context.Context, outPath string) error

func (*Store) CheckIntegrity

func (s *Store) CheckIntegrity(ctx context.Context) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) CurrentLock

func (s *Store) CurrentLock(ctx context.Context, name string) (*Lock, error)

func (*Store) CurrentResource

func (s *Store) CurrentResource(ctx context.Context, address string) (*ResourceSnapshot, error)

func (*Store) DeleteResource

func (s *Store) DeleteResource(ctx context.Context, address string) error

func (*Store) Export

func (s *Store) Export(ctx context.Context) (ExportDocument, error)

func (*Store) FinishRun

func (s *Store) FinishRun(ctx context.Context, id int64, status, summaryJSON string) error

func (*Store) ForceUnlock

func (s *Store) ForceUnlock(ctx context.Context, name, holder string) (*Lock, error)

func (*Store) ListAsyncEvidence

func (s *Store) ListAsyncEvidence(ctx context.Context, filter AsyncEvidenceFilter) ([]AsyncEvidenceRecord, error)

func (*Store) ListCurrentResources

func (s *Store) ListCurrentResources(ctx context.Context) ([]ResourceSnapshot, error)

func (*Store) ListLocks

func (s *Store) ListLocks(ctx context.Context) ([]Lock, error)

func (*Store) ListMigrationRecords

func (s *Store) ListMigrationRecords(ctx context.Context) ([]MigrationRecord, error)

func (*Store) ListRevisions

func (s *Store) ListRevisions(ctx context.Context, address string) ([]Revision, error)

func (*Store) ListRunEvents

func (s *Store) ListRunEvents(ctx context.Context, runID int64) ([]RunEvent, error)

func (*Store) ListRuns

func (s *Store) ListRuns(ctx context.Context, status string) ([]Run, error)

func (*Store) MarkAbandonedRuns

func (s *Store) MarkAbandonedRuns(ctx context.Context, olderThan time.Duration) ([]Run, error)

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

func (*Store) RecordAsyncEvidence

func (s *Store) RecordAsyncEvidence(ctx context.Context, record AsyncEvidenceRecord) error

func (*Store) RecordResource

func (s *Store) RecordResource(ctx context.Context, snap ResourceSnapshot) error

func (*Store) RecordRevision

func (s *Store) RecordRevision(ctx context.Context, rev Revision) error

func (*Store) RecordRunEvent

func (s *Store) RecordRunEvent(ctx context.Context, event RunEvent) error

func (*Store) ReleaseLock

func (s *Store) ReleaseLock(ctx context.Context, name, holder string) error

func (*Store) RenewLock

func (s *Store) RenewLock(ctx context.Context, name, holder string, ttl time.Duration) error

func (*Store) SchemaReady

func (s *Store) SchemaReady(ctx context.Context) error

func (*Store) StartLockRenewal

func (s *Store) StartLockRenewal(ctx context.Context, name, holder string, ttl, interval time.Duration) func()

func (*Store) StartRun

func (s *Store) StartRun(ctx context.Context, command string) (int64, error)

func (*Store) Vacuum

func (s *Store) Vacuum(ctx context.Context) error

func (*Store) WithTx

func (s *Store) WithTx(ctx context.Context, fn func(*Tx) error) error

type Tx

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

func (*Tx) CurrentResource

func (tx *Tx) CurrentResource(ctx context.Context, address string) (*ResourceSnapshot, error)

func (*Tx) DeleteResource

func (tx *Tx) DeleteResource(ctx context.Context, address string) error

func (*Tx) RecordResource

func (tx *Tx) RecordResource(ctx context.Context, snap ResourceSnapshot) error

func (*Tx) RecordRevision

func (tx *Tx) RecordRevision(ctx context.Context, rev Revision) error

Jump to

Keyboard shortcuts

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