Documentation
¶
Overview ¶
Package state owns gateway state; launch setup must never open this store.
Index ¶
- Constants
- Variables
- func OpenArchive(home string) (*sql.DB, error)
- func ReadArchive(home string) (*sql.DB, error)
- func RememberArchiveClocks(ctx context.Context, tx *sql.Tx, id string) error
- func SchemaVersion() int
- func Transaction(ctx context.Context, db *sql.DB, run func(*sql.Tx) error) error
- func VerifyArchive(home string) error
- type Change
- type ChangeVersionTooLargeError
- type MainState
- type SQLiteValue
- type Store
- func (s *Store) Apply(ctx context.Context, changes []Change) error
- func (s *Store) ApplyPage(ctx context.Context, changes []Change, site []byte, next int64) error
- func (s *Store) ArchiveReady(ctx context.Context, home string, empty bool) error
- func (s *Store) BindNode(ctx context.Context, id string) error
- func (s *Store) Changes(ctx context.Context, since int64, exclude []byte, maxBytes int) ([]Change, int64, error)
- func (s *Store) Close() error
- func (s *Store) Cursor(ctx context.Context, site []byte) (int64, error)
- func (s *Store) DBVersion(ctx context.Context) (int64, error)
- func (s *Store) DrainArchiveEdits(ctx context.Context) (result error)
- func (s *Store) Main(ctx context.Context) (MainState, error)
- func (s *Store) NodeID(ctx context.Context) (string, error)
- func (s *Store) SetCursor(ctx context.Context, site []byte, version int64) error
- func (s *Store) SetMain(ctx context.Context, expected MainState, home string) error
- func (s *Store) SiteID(ctx context.Context) ([]byte, error)
- func (s *Store) WriteVersion(ctx context.Context, version int64, exclude []byte, out io.Writer) error
Constants ¶
const LocalNodeSQL = "(SELECT node_id FROM local_node WHERE id=1)"
LocalNodeSQL reads inside the caller's transaction, including already-running workers.
Variables ¶
var ErrArchivePending = errors.New("newer archived history awaits the main gateway; retry after archive handover")
var ErrChangeVersionTooLarge = errors.New("replicated transaction exceeds the change page byte limit")
var ErrMainChanged = errors.New("main or archive gateway changed; review the current roles before trying again")
Functions ¶
func OpenArchive ¶
OpenArchive is plain SQLite; it never loads cr-sqlite or changes an existing archive's schema.
func ReadArchive ¶
ReadArchive never creates a missing archive or enables writes.
func RememberArchiveClocks ¶
RememberArchiveClocks retains original event clocks before archive pruning creates tombstones.
func SchemaVersion ¶
func SchemaVersion() int
func Transaction ¶
Transaction commits only when every operation succeeds; panics also roll back.
func VerifyArchive ¶
VerifyArchive validates a copied archive without creating or changing it.
Types ¶
type Change ¶
type Change struct {
Table string `json:"table"`
PK []byte `json:"pk"`
Column string `json:"cid"`
Value SQLiteValue `json:"val"`
ColVersion int64 `json:"col_version"`
DBVersion int64 `json:"db_version"`
SiteID []byte `json:"site_id"`
CL int64 `json:"cl"`
Seq int64 `json:"seq"`
TS *string `json:"ts"`
}
type ChangeVersionTooLargeError ¶
func (*ChangeVersionTooLargeError) Error ¶
func (e *ChangeVersionTooLargeError) Error() string
func (*ChangeVersionTooLargeError) Unwrap ¶
func (e *ChangeVersionTooLargeError) Unwrap() error
type SQLiteValue ¶
type SQLiteValue struct {
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
SQLiteValue keeps integers exact and distinguishes an empty blob from NULL.
type Store ¶
func (*Store) ArchiveReady ¶
func (*Store) BindNode ¶
BindNode replaces the offline site identity once, when Tailscale identifies this machine.
func (*Store) Changes ¶
func (s *Store) Changes(ctx context.Context, since int64, exclude []byte, maxBytes int) ([]Change, int64, error)
Changes never splits a source version; next also advances past excluded-only versions.
func (*Store) DBVersion ¶
The persisted counter cannot fall when a newer value supersedes the last row of an older version.
func (*Store) DrainArchiveEdits ¶
DrainArchiveEdits acknowledges a relayed edit only after archive.db has durably committed it.