Documentation
¶
Overview ¶
Package records defines the ordered record store an IndexedDB object store provides, with a memory implementation that simulates power loss.
Every call is one IndexedDB transaction and one round trip. A commit is atomic. A durable commit maps to the strict durability hint and returns once it and every earlier commit are durable; any other commit maps to the relaxed hint, and a crash may lose it along with every later commit.
Index ¶
- Variables
- type Memory
- func (m *Memory) Calls() int
- func (m *Memory) Commit(ctx context.Context, ops []Op, durable bool) error
- func (m *Memory) CrashAfter(n int)
- func (m *Memory) Get(ctx context.Context, keys [][]byte) ([][]byte, error)
- func (m *Memory) Has(ctx context.Context, keys [][]byte) ([]bool, error)
- func (m *Memory) PowerLoss(rng *rand.Rand)
- func (m *Memory) Scan(ctx context.Context, prefix []byte, fn func(key, value []byte) error) error
- func (m *Memory) Stats() Stats
- type Op
- type Stats
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrCrashed = errors.New("record store crashed")
ErrCrashed reports a call on a memory store after its injected crash.
Functions ¶
This section is empty.
Types ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is an in-memory Store that simulates power loss. It keeps the durable records as of the last durable commit and the commits made since, so PowerLoss can keep any prefix of them.
func NewMemory ¶
func NewMemory() *Memory
NewMemory returns an empty memory store that never crashes.
func (*Memory) Commit ¶
Commit applies ops atomically, injecting the crash when it is due. The crashing commit joins the pending ones, so PowerLoss may keep it.
func (*Memory) CrashAfter ¶
CrashAfter crashes the store after n further commits succeed. The crashing commit may or may not apply, and every later call fails with ErrCrashed until PowerLoss. A negative n never crashes.
func (*Memory) PowerLoss ¶
PowerLoss replaces the records with an image a power loss could leave: the durable records and a prefix of the later commits, as rng chooses. The store then accepts calls again.
type Op ¶
type Op struct {
// Key is the record key.
Key []byte
// Value is the record a put stores.
Value []byte
// Delete deletes the record.
Delete bool
}
Op is one change of a commit.
type Stats ¶
type Stats struct {
// Reads counts Get, Has, and Scan calls.
Reads int
// Commits counts Commit calls.
Commits int
// Durable counts durable Commit calls.
Durable int
// Bytes counts the key and value bytes committed.
Bytes int64
}
Stats counts a store's transactions.
type Store ¶
type Store interface {
// Get reads the records of keys, nil for an absent key.
Get(ctx context.Context, keys [][]byte) ([][]byte, error)
// Has reports which keys have records without reading them.
Has(ctx context.Context, keys [][]byte) ([]bool, error)
// Scan calls fn with each record whose key has prefix, in key order. fn
// may retain the key and value.
Scan(ctx context.Context, prefix []byte, fn func(key, value []byte) error) error
// Commit applies ops atomically in order, durably if durable is set. The
// store does not retain ops.
Commit(ctx context.Context, ops []Op, durable bool) error
}
Store is an ordered record store.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package recordstest checks a records.Store against its contract, so native tests and browser fixtures run the same checks on every implementation.
|
Package recordstest checks a records.Store against its contract, so native tests and browser fixtures run the same checks on every implementation. |