Documentation
¶
Overview ¶
Package storage manages global and local storage layers with caching and version tracking.
Index ¶
- Constants
- Variables
- type Global
- func (s Global) Delete(ctx context.Context, key string) error
- func (s Global) DeleteIf(ctx context.Context, key string, expected backend.Version) error
- func (s Global) GetMetadata(ctx context.Context, key string) (backend.Metadata, error)
- func (s Global) Read(ctx context.Context, key string) (GlobalRead, error)
- func (s Global) SetTagsIf(ctx context.Context, key string, expected backend.Version, t backend.Tags) (backend.Metadata, error)
- func (s Global) Write(ctx context.Context, key string, value []byte, t backend.Tags) (backend.Metadata, error)
- func (s Global) WriteIf(ctx context.Context, key string, value []byte, expected backend.Version, ...) (backend.Metadata, error)
- func (s Global) WriteIfNotExists(ctx context.Context, key string, value []byte, t backend.Tags) (backend.Metadata, error)
- type GlobalRead
- type Local
- func (c Local) Delete(key string)
- func (c Local) GetMeta(key string, maxStale time.Duration) (LocalMetadata, bool)
- func (c Local) MarkDeleted(key string, v Version)
- func (c Local) MarkValueOutated(key string, v Version)
- func (c Local) Read(key string, maxStale time.Duration) (LocalRead, bool)
- func (c Local) SetMeta(key string, meta backend.Metadata)
- func (c Local) Write(key string, value []byte, v Version)
- func (c Local) WriteWithMeta(key string, value []byte, meta backend.Metadata)
- type LocalMetadata
- type LocalRead
- type LockInfo
- type LockOps
- type LockRequest
- type LockType
- type LockUpdate
- type Locker
- type PathLock
- type TLogger
- func (t TLogger) CommitStatus(ctx context.Context, id data.TxID) (TxStatus, error)
- func (t TLogger) Delete(ctx context.Context, id data.TxID) error
- func (t TLogger) Get(ctx context.Context, id data.TxID) (TxLog, error)
- func (t TLogger) Set(ctx context.Context, l TxLog) (backend.Version, error)
- func (t TLogger) SetIf(ctx context.Context, l TxLog, expected backend.Version) (backend.Version, error)
- type TValue
- type TxCommitStatus
- type TxLog
- type TxPathState
- type TxStatus
- type TxWrite
- type Version
Constants ¶
const MaxStaleness = time.Duration(math.MaxInt64)
MaxStaleness is the maximum duration a cached value can be stale, effectively meaning that any cached value is acceptable regardless of age.
Variables ¶
var ErrKeyNotFound = errors.New("key not found in committed transaction")
ErrKeyNotFound is returned when a key is not found in a committed transaction log.
Functions ¶
This section is empty.
Types ¶
type Global ¶
type Global struct {
// contains filtered or unexported fields
}
Global wraps a backend with a local cache, performing read-through and write-through caching of storage objects and metadata.
func NewGlobal ¶
NewGlobal returns a Global that reads and writes through the given backend, using l as a local cache.
func (Global) DeleteIf ¶
DeleteIf conditionally deletes the object if its version matches expected, and removes it from the local cache on success.
func (Global) GetMetadata ¶
GetMetadata fetches the object metadata from the backend and updates the local cache.
func (Global) SetTagsIf ¶
func (s Global) SetTagsIf( ctx context.Context, key string, expected backend.Version, t backend.Tags, ) (backend.Metadata, error)
SetTagsIf conditionally sets tags on the object if its current version matches expected, and updates the local metadata cache.
type GlobalRead ¶
GlobalRead holds the result of reading a value from global storage.
type Local ¶
type Local struct {
// contains filtered or unexported fields
}
Local provides a local in-memory cache for storage objects, including both values and metadata with staleness tracking.
func (Local) GetMeta ¶
GetMeta returns the cached metadata for the given key, if it exists and is not staler than maxStale.
func (Local) MarkDeleted ¶
MarkDeleted marks the given key as deleted in the cache with the given version.
func (Local) MarkValueOutated ¶
MarkValueOutated annotates the given key value as outdated, only if it's currently set at the given version.
type LocalMetadata ¶
type LocalMetadata struct {
M backend.Metadata
// Outdated is true if the metadata is certainly outdated.
Outdated bool
}
LocalMetadata holds cached metadata along with its freshness status.
type LocalRead ¶
type LocalRead struct {
Value []byte
Version Version
Deleted bool
// Outdated is true if the value read is certainly outdated.
Outdated bool
}
LocalRead holds the result of reading a value from the local cache.
type LockInfo ¶
LockInfo describes the current lock state of a storage object.
func TagsLockInfo ¶
TagsLockInfo parses tags managing locks on an object.
type LockOps ¶
type LockOps struct {
// Update is the possible next update on the lock. If nothing should be
// updated, HasUpdate will be false.
Update LockUpdate
HasUpdate bool
// WaitFor is the list of transactions that need to unlock before any
// operation can be performed.
WaitFor []data.TxID
// What effect these operations will have.
LockedFor []data.TxID
UnlockedFor []data.TxID
}
LockOps represents what possible next update can be done to a lock.
This includes the update, what transactions need to unlock before this can done and what effects the operation will have.
func ComputeLockUpdate ¶
func ComputeLockUpdate(curr LockInfo, req LockRequest, txs []TxPathState) (LockOps, error)
ComputeLockUpdate determines the next lock operation to perform given the current lock state, a lock request, and the status of relevant transactions.
type LockRequest ¶
LockRequest specifies the transactions that want to acquire or release a lock.
type LockUpdate ¶
type LockUpdate struct {
Type LockType
PrevType LockType
Lockers []data.TxID
Writer data.TxID
Value TValue
}
LockUpdate describes the desired state of a lock after an update operation.
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker applies lock updates to storage objects by writing lock state into backend tags and conditionally updating values.
func (Locker) UnlockCreateUncommitted ¶
func (l Locker) UnlockCreateUncommitted( ctx context.Context, key string, expected backend.Version, ) error
UnlockCreateUncommitted releases a create-lock on an object whose transaction was not committed, deleting the object.
func (Locker) UpdateLock ¶
func (l Locker) UpdateLock( ctx context.Context, key string, expected backend.Version, update LockUpdate, ) error
UpdateLock applies the given lock update to the object at key, using conditional writes to ensure the object's version matches expected.
type TLogger ¶
type TLogger struct {
// contains filtered or unexported fields
}
TLogger provides tools to deal with transaction logs.
func NewTLogger ¶
NewTLogger returns a TLogger that stores transaction logs under the given prefix.
func (TLogger) CommitStatus ¶
CommitStatus returns the commit status of the transaction with the given ID, reading from the local cache when possible.
func (TLogger) Delete ¶
Delete removes the transaction log for the given ID, ignoring not-found errors.
type TValue ¶
type TValue struct {
Value []byte
Deleted bool
// NotWritten is true when the transaction was committed but the value
// was not written to (e.g. when only locked in read).
NotWritten bool
}
TValue holds a value written by a transaction, including whether it was a deletion or was not written at all.
type TxCommitStatus ¶
type TxCommitStatus int
TxCommitStatus represents the commit state of a transaction.
const ( TxCommitStatusUnknown TxCommitStatus = iota TxCommitStatusOK TxCommitStatusAborted TxCommitStatusPending )
Possible values for TxCommitStatus.
func (TxCommitStatus) IsFinal ¶
func (s TxCommitStatus) IsFinal() bool
IsFinal reports whether the status represents a terminal state (committed or aborted).
type TxLog ¶
type TxLog struct {
ID data.TxID
Timestamp time.Time
Status TxCommitStatus
Writes []TxWrite
Locks []PathLock
}
TxLog holds the full contents of a transaction log entry, including its writes and acquired locks.
type TxPathState ¶
type TxPathState struct {
Tx data.TxID
Status TxCommitStatus
Value TValue
}
TxPathState describes a transaction's commit status and the value it wrote for a particular path.
type TxStatus ¶
type TxStatus struct {
Status TxCommitStatus
LastUpdate time.Time
Version backend.Version
}
TxStatus holds the commit status of a transaction along with its timestamp and backend version.
type Version ¶
Version represents a storage object's version, combining a backend version with an optional local transaction writer.
func VersionFromMeta ¶
VersionFromMeta constructs a Version from backend metadata, extracting the last writer from the metadata tags.
func (Version) EqualContents ¶
EqualContents reports whether v and other refer to the same version content, comparing backend contents or writer IDs as appropriate.
func (Version) EqualMetaContents ¶
EqualMetaContents reports whether v matches the version described by the given backend metadata.