Documentation
¶
Overview ¶
Package store is the DynamoDB storage engine: tables and items in bbolt, GSI/LSI entries maintained in the same transaction as every write, range queries via order-preserving key encodings (keyenc), single-node transactions with real atomicity, and TTL enforcement.
bbolt layout:
tables name -> Table JSON
d:<table> keyenc(pk[,sk]) -> item wire JSON
x:<table>/<index> keyenc(ipk[,isk]) ++ keyenc(pk[,sk]) -> primary key bytes
tx: ClientRequestToken -> {hash, expiry} (idempotency)
Index entries are key references (no projected copies): reads chase the reference to the base item and apply the index projection — microseconds locally, and index consistency is free.
Index ¶
- func RequestHash(body []byte) string
- type CancellationReason
- type Cond
- type ErrTransactionCanceled
- type Index
- type KeyPart
- type QueryInput
- type QueryOutput
- type ScanInput
- type Store
- func (s *Store) CountItems(table string) int64
- func (s *Store) CreateTable(t Table) (*Table, error)
- func (s *Store) DB() *bolt.DB
- func (s *Store) DeleteItem(table string, rawKey json.RawMessage, cond *Cond, _ string) (old item.Item, err error)
- func (s *Store) DeleteTable(name string) (*Table, error)
- func (s *Store) GetItem(table string, rawKey json.RawMessage) (item.Item, error)
- func (s *Store) GetTable(name string) (*Table, error)
- func (s *Store) KeyFromWire(t *Table, raw json.RawMessage) ([]byte, item.Item, *awshttp.APIError)
- func (s *Store) LatestStreamSeq(table string) uint64
- func (s *Store) ListTables() ([]string, error)
- func (s *Store) PutItem(table string, rawItem json.RawMessage, cond *Cond) (old item.Item, err error)
- func (s *Store) Query(in QueryInput) (*QueryOutput, error)
- func (s *Store) Scan(in ScanInput) (*QueryOutput, error)
- func (s *Store) SetClock(fn func() time.Time)
- func (s *Store) StreamRecords(table string, afterSeq uint64, limit int) ([]StreamRecord, uint64, error)
- func (s *Store) StreamViewType(table string) (string, bool)
- func (s *Store) SweepTTL()
- func (s *Store) TransactGet(keys []struct{ ... }) ([]item.Item, error)
- func (s *Store) TransactWrite(ops []TxWriteOp, token string, requestHash string) error
- func (s *Store) UpdateItem(table string, rawKey json.RawMessage, upd *expr.Update, cond *Cond) (old, new item.Item, err error)
- func (s *Store) UpdateTable(name string, fn func(*Table) error) (*Table, error)
- type StreamRecord
- type Table
- type TxWriteOp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestHash ¶
RequestHash fingerprints a transaction body for idempotency comparison.
Types ¶
type CancellationReason ¶
type CancellationReason struct {
Code string `json:"Code"`
Message string `json:"Message,omitempty"`
Item json.RawMessage `json:"Item,omitempty"`
}
CancellationReason mirrors DynamoDB's per-item transaction outcome.
type Cond ¶
type Cond struct {
Expr *expr.Cond
Env *expr.Env
// ReturnOld controls ReturnValuesOnConditionCheckFailure.
ReturnOld bool
}
Cond wraps an optional parsed condition.
type ErrTransactionCanceled ¶
type ErrTransactionCanceled struct {
Reasons []CancellationReason
}
ErrTransactionCanceled carries the reasons; the service layer renders it.
func (*ErrTransactionCanceled) Error ¶
func (e *ErrTransactionCanceled) Error() string
type Index ¶
type Index struct {
Name string `json:"name"`
Hash KeyPart `json:"hash"`
Range *KeyPart `json:"range,omitempty"`
Projection string `json:"projection"` // ALL | KEYS_ONLY | INCLUDE
NonKeyAttrs []string `json:"non_key_attrs,omitempty"`
Local bool `json:"local"`
}
Index describes a GSI or LSI.
type QueryInput ¶
type QueryInput struct {
Table string
Index string // optional
KeyCond *expr.KeyCondition
Filter *expr.Cond
Forward bool // ScanIndexForward (default true)
Limit int
StartKey json.RawMessage // ExclusiveStartKey (item key attrs, incl. index keys)
}
QueryInput drives Query.
type QueryOutput ¶
type QueryOutput struct {
Items []item.Item
Count int
ScannedCount int
LastEvaluatedKey item.Item // nil when the page completes the result set
}
QueryOutput is a page of results.
type ScanInput ¶
type ScanInput struct {
Table string
Index string
Filter *expr.Cond
Limit int
StartKey json.RawMessage
Segment int
TotalSegments int
}
ScanInput drives Scan.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the bbolt-backed DynamoDB engine.
func (*Store) CountItems ¶
CountItems reports a table's item count (DescribeTable convenience).
func (*Store) CreateTable ¶
CreateTable registers a table.
func (*Store) DeleteItem ¶
func (s *Store) DeleteItem(table string, rawKey json.RawMessage, cond *Cond, _ string) (old item.Item, err error)
DeleteItem removes an item, returning the previous one.
func (*Store) DeleteTable ¶
DeleteTable removes a table and its data.
func (*Store) KeyFromWire ¶
keyFromWire decodes a request's Key map and encodes it.
func (*Store) LatestStreamSeq ¶ added in v0.2.0
LatestStreamSeq returns the highest stored sequence for a table's stream (0 if none) — the position a LATEST shard iterator starts after.
func (*Store) ListTables ¶
ListTables returns table names in order.
func (*Store) PutItem ¶
func (s *Store) PutItem(table string, rawItem json.RawMessage, cond *Cond) (old item.Item, err error)
PutItem stores an item, returning the previous one (for ReturnValues).
func (*Store) Query ¶
func (s *Store) Query(in QueryInput) (*QueryOutput, error)
Query runs a key-condition query against the table or one of its indexes.
func (*Store) Scan ¶
func (s *Store) Scan(in ScanInput) (*QueryOutput, error)
Scan walks a table (or index) with optional segment partitioning.
func (*Store) StreamRecords ¶ added in v0.2.0
func (s *Store) StreamRecords(table string, afterSeq uint64, limit int) ([]StreamRecord, uint64, error)
StreamRecords returns records with sequence > afterSeq (afterSeq 0 = from the trim horizon), up to limit, plus the highest sequence currently stored.
func (*Store) StreamViewType ¶ added in v0.2.0
StreamViewType (on Store) resolves a table by name first.
func (*Store) SweepTTL ¶
func (s *Store) SweepTTL()
SweepTTL removes expired items across every TTL-enabled table, through the normal delete path so indexes stay consistent.
func (*Store) TransactGet ¶
func (s *Store) TransactGet(keys []struct { Table string Key json.RawMessage }) ([]item.Item, error)
TransactGet reads up to 100 items with a consistent view (one bbolt View).
func (*Store) TransactWrite ¶
TransactWrite runs up to 100 write ops atomically.
type StreamRecord ¶ added in v0.2.0
type StreamRecord struct {
Seq uint64
EventName string
Keys json.RawMessage
Old json.RawMessage
New json.RawMessage
CreatedNs int64
SizeBytes int
}
StreamRecord is one change record handed to the Streams API / poller.
type Table ¶
type Table struct {
Name string `json:"name"`
Hash KeyPart `json:"hash"`
Range *KeyPart `json:"range,omitempty"`
Indexes []Index `json:"indexes,omitempty"`
Created int64 `json:"created"`
TTLAttribute string `json:"ttl_attribute,omitempty"`
TTLEnabled bool `json:"ttl_enabled,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
// Cosmetic round-trips.
BillingMode string `json:"billing_mode,omitempty"`
DeletionProtection bool `json:"deletion_protection,omitempty"`
StreamSpec string `json:"stream_spec,omitempty"` // stored, inert (streams post-1.0)
ItemCount int64 `json:"item_count"`
}
Table is a table definition.
func (*Table) StreamLabel ¶ added in v0.2.0
StreamLabel is the stable per-table stream label (derived from creation time), and StreamARN the corresponding ARN.
func (*Table) StreamViewType ¶ added in v0.2.0
StreamViewType (on Table) returns the stream view type and whether streaming is enabled.
type TxWriteOp ¶
type TxWriteOp struct {
Table string
// Put stores an item.
Put json.RawMessage
// UpdateKey + Update applies an update expression.
UpdateKey json.RawMessage
Update *expr.Update
// DeleteKey removes an item.
DeleteKey json.RawMessage
// CheckKey asserts a condition without writing.
CheckKey json.RawMessage
Cond *Cond
ReturnOld bool // ReturnValuesOnConditionCheckFailure
}
TxWriteOp is one TransactWriteItems operation (exactly one field set).