Documentation
¶
Overview ¶
Package memory is the in-memory store.Store: one map per kind behind a single RWMutex (PoC scale: thousands of objects), JSON deep copies on the way in and out, field indexes, watch fan-out with bounded buffers and a replay history, leased locks, retention and the transcript blobs. A commit hook (WithCommitHook) sees every write before it is applied, which is how store/filestore makes it durable.
Index ¶
- type Change
- type CommitHook
- type Op
- type Option
- type Record
- type Store
- func (s *Store) Create(ctx context.Context, obj store.Object) error
- func (s *Store) Delete(ctx context.Context, k store.Key) error
- func (s *Store) Get(ctx context.Context, k store.Key, out store.Object) error
- func (s *Store) GetTranscript(ctx context.Context, run string) ([]byte, error)
- func (s *Store) List(ctx context.Context, kind string, opts store.ListOptions, out any) (store.ListMeta, error)
- func (s *Store) Lock(ctx context.Context, name string, ttl time.Duration) (store.Unlock, error)
- func (s *Store) PutTranscript(ctx context.Context, run string, data []byte) error
- func (s *Store) Restore(recs []Record, version uint64) error
- func (s *Store) Snapshot() ([]Record, uint64)
- func (s *Store) Sweep(ctx context.Context) (store.SweepResult, error)
- func (s *Store) Update(ctx context.Context, obj store.Object) error
- func (s *Store) Watch(ctx context.Context, kind string, opts store.WatchOptions) (store.Watcher, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
Op Op
Key store.Key
// Version is the store version the change gets (the store's counter after it).
Version uint64
// At is the write's time on the store's clock: the object's last-write time for create
// and update (and its creation time for create), the deletion time for delete.
At time.Time
// Data is the object's JSON exactly as the store keeps it (resourceVersion and createdAt
// set when the kind has them); nil for delete. It is shared with the store: don't modify it.
Data []byte
}
Change is one write as the commit hook sees it, before the store applies it.
type CommitHook ¶
CommitHook is called for every Create, Update and Delete (Sweep's too) once the write has been checked and encoded but before it is applied, under the store's write lock: changes reach it one at a time, in version order. When it returns an error the write fails with it (wrapped) and the store is left exactly as it was: no object, version or watch event. It must not call back into the store. Locks and transcripts don't go through it.
type Option ¶
type Option func(*Store)
Option configures New.
func WithCommitHook ¶
func WithCommitHook(h CommitHook) Option
WithCommitHook makes every write go through h first (a durable store journals there).
type Record ¶
type Record struct {
Key store.Key
// Type is the object's struct type: the object is a *Type.
Type reflect.Type
// Data is the object's JSON as the store keeps it. From Snapshot it is shared with the
// store: don't modify it.
Data []byte
// Version is the object's resourceVersion (kept beside it for kinds without one).
Version uint64
// Created and Updated are its creation and last-write times (Updated drives SinceUpdated
// retention).
Created, Updated time.Time
}
Record is one stored object, as Snapshot returns it and Restore takes it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the in-memory store. Use New.
func (*Store) GetTranscript ¶
GetTranscript implements store.TranscriptStore.
func (*Store) List ¶
func (s *Store) List(ctx context.Context, kind string, opts store.ListOptions, out any) (store.ListMeta, error)
List implements store.Store.
func (*Store) PutTranscript ¶
PutTranscript implements store.TranscriptStore.
func (*Store) Restore ¶
Restore loads recs into an empty store and sets its version counter to version, as a durable store does at start-up. The hook isn't called and watchers aren't told. The watch history starts empty at version: a Watch with an older SinceVersion is ErrWatchExpired, as when the history has been trimmed. The store keeps each record's Data: don't modify it afterwards. Call it before any other use of the store.
func (*Store) Snapshot ¶
Snapshot returns every stored object and the store's version, read at one instant. The version can be above every object's (deletes advance it too).
func (*Store) Sweep ¶
Sweep implements store.Sweeper: it deletes the objects and transcripts past retention (store.RetentionOf), telling watchers, and drops expired locks. Run it with store.RunSweeper.