Documentation
¶
Overview ¶
Package state holds unobin's local state backend and the built-in encrypters.
The Backend interface and Snapshot types live in pkg/sdk/state so provider libraries can implement their own backends without depending on unobin core. This package implements only the local-filesystem backend, which the core library registers as the default.
Index ¶
- type LocalStore
- func (s *LocalStore) Current() (*sdkstate.Snapshot, error)
- func (s *LocalStore) CurrentRev() (string, error)
- func (s *LocalStore) Delete(rev string) error
- func (s *LocalStore) ForceUnlock() error
- func (s *LocalStore) Get(rev string) (*sdkstate.Snapshot, error)
- func (s *LocalStore) List() ([]string, error)
- func (s *LocalStore) Lock(ctx context.Context) (sdkstate.Lock, error)
- func (s *LocalStore) SetCurrent(rev string) error
- func (s *LocalStore) Stack() string
- func (s *LocalStore) Write(snap *sdkstate.Snapshot) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LocalStore ¶
LocalStore reads and writes snapshots under a per-stack directory. Layout is as follows:
<Root>/<Factory>/<Stack>/
current // File containing the SHA of the current snapshot.
snapshots/
<rev>.json.enc // rev is an RFC3339Nano timestamp
...
func NewLocalStore ¶
func NewLocalStore( root, factory, stack string, enc sdkencrypt.Encrypter, ) (*LocalStore, error)
NewLocalStore returns a LocalStore for the given factory and stack under root, creating the directory tree if it doesn't exist. The Encrypter is required, but a pass-through (envencrypt.Noop) can be passed for tests.
func (*LocalStore) Current ¶
func (s *LocalStore) Current() (*sdkstate.Snapshot, error)
Current returns the snapshot named by the current pointer. Returns sdkstate.ErrNoCurrent when no snapshot has been written yet.
func (*LocalStore) CurrentRev ¶
func (s *LocalStore) CurrentRev() (string, error)
CurrentRev returns the rev the current pointer names, or sdkstate.ErrNoCurrent.
func (*LocalStore) Delete ¶
func (s *LocalStore) Delete(rev string) error
Delete removes the snapshot with the given rev. Removing a rev that does not exist is not an error.
func (*LocalStore) ForceUnlock ¶
func (s *LocalStore) ForceUnlock() error
ForceUnlock removes the lock marker without checking who holds it. Operators run this to recover after a leaked lock and must ensure no concurrent run is in progress.
func (*LocalStore) Get ¶
func (s *LocalStore) Get(rev string) (*sdkstate.Snapshot, error)
Get returns the snapshot with the given rev.
func (*LocalStore) List ¶
func (s *LocalStore) List() ([]string, error)
List returns the revs of every stored snapshot in chronological order.
func (*LocalStore) Lock ¶
Lock acquires the deployment's exclusive lock by creating a marker file under the deployment directory. Lock blocks until the marker can be created or ctx is canceled. The marker file holds the holder's pid so an operator can identify a stuck lock.
func (*LocalStore) SetCurrent ¶
func (s *LocalStore) SetCurrent(rev string) error
SetCurrent atomically points "current" at the named rev. The snapshot must already exist.
func (*LocalStore) Stack ¶
func (s *LocalStore) Stack() string
Stack returns the stack name this store was constructed for. Required by the Backend interface.
func (*LocalStore) Write ¶
func (s *LocalStore) Write(snap *sdkstate.Snapshot) (string, error)
Write commits snap to disk and returns its rev. The caller advances the current pointer with SetCurrent. Each rev starts as an RFC3339Nano timestamp; if a snapshot already exists at that path (because two writes share the same nanosecond), a numeric suffix is appended until the path is fresh, so uniqueness does not depend on the clock advancing between writes.