Contracts (ABCs)¶
Abstract base classes defining the core storage interfaces.
StorageEngine¶
StorageEngine
¶
Bases: ABC
Async key-value store contract.
Any class that provides durable, crash-safe storage of byte key-value pairs should inherit from this ABC and implement all four methods.
put(key, value)
abstractmethod
async
¶
Persist a key-value pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
The lookup key (raw bytes). |
required |
value
|
Value
|
The value to associate with key (raw bytes). |
required |
get(key)
abstractmethod
async
¶
Retrieve the value for key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
The lookup key. |
required |
Returns:
| Type | Description |
|---|---|
Value | None
|
The stored value, or |
Value | None
|
has been deleted. |
delete(key)
abstractmethod
async
¶
close()
abstractmethod
async
¶
Flush pending data and release all resources.
After close() returns, subsequent calls to :meth:put,
:meth:get, or :meth:delete should raise an error.
Serializable¶
Serializable
¶
Bases: ABC
Byte-level serialization contract.
Any class that can round-trip its state through bytes should
inherit from this ABC. The from_bytes class method must
reconstruct an equivalent instance from output of to_bytes.
to_bytes()
abstractmethod
¶
Serialize this instance to a compact byte string.
Returns:
| Type | Description |
|---|---|
bytes
|
A |
bytes
|
to reconstruct an equivalent instance. |
from_bytes(data)
abstractmethod
classmethod
¶
Reconstruct an instance from serialized data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Bytes previously produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new instance equivalent to the one that produced data. |
Source code in app/common/abc.py
MemTable¶
MemTable
¶
Bases: ABC
Mutable in-memory sorted table contract.
Defines the minimal interface that a writable memtable must expose: insert, point lookup, sorted iteration, and freeze-to-snapshot.
put(key, seq, timestamp_ms, value)
abstractmethod
¶
Insert or update key in the table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
The lookup key (raw bytes). |
required |
seq
|
SeqNum
|
Monotonically increasing sequence number. |
required |
timestamp_ms
|
int
|
Wall-clock timestamp in milliseconds. |
required |
value
|
Value
|
The value to store (or |
required |
Source code in app/common/abc.py
get(key)
abstractmethod
¶
Look up key and return its latest value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
The lookup key. |
required |
Returns:
| Type | Description |
|---|---|
tuple[SeqNum, Value] | None
|
A |
tuple[SeqNum, Value] | None
|
present in this table. |
Source code in app/common/abc.py
items()
abstractmethod
¶
Yield all entries in ascending key order.
Yields:
| Type | Description |
|---|---|
tuple[Key, SeqNum, int, Value]
|
Tuples of |
freeze()
abstractmethod
¶
Return a sorted snapshot of all entries and mark the table as frozen.
Returns:
| Type | Description |
|---|---|
list[tuple[Key, SeqNum, int, Value]]
|
A list of |
list[tuple[Key, SeqNum, int, Value]]
|
by key ascending. |
Raises:
| Type | Description |
|---|---|
SnapshotEmptyError
|
If the table contains no entries. |