#[non_exhaustive]pub enum Partition {
Namespace(NamespaceKey),
Coordinator(NamespaceKey),
Ref {
ns: NamespaceKey,
repo: RepoName,
shard_ref: String,
},
RepoIndex {
ns: NamespaceKey,
repo: RepoName,
prefix: u16,
},
RefIndex {
ns: NamespaceKey,
repo: RepoName,
bucket: u16,
},
ContentShard(u16),
}Expand description
A storage partition: one D34 shard. Everything that must commit
atomically lives in one partition. The core computes the partition of
every operation; a backend maps partitions to whatever it likes (a
Durable Object each, rows keyed by partition in SQLite, a qmdb
instance each).
Catch-all rule for backends. The enum is #[non_exhaustive]: later
work adds kinds. A backend outside this crate never matches on it. It
stores and names partitions by Partition::encode, which is stable
and injective, so a new kind needs no backend change. Existing
encodings never change; a new kind gets a new tag.
Enumeration. A store is never asked to list its partitions (a Durable Object namespace cannot list its instances). Backup and export enumerate them hierarchically, from bounded or constructible structures only; nothing lists every ref shard in one place (one ref per file can mean millions of them):
- Namespaces (
Namespacein single-partition mode,Coordinatorunder D34) come from deployment configuration and the namespace allowlist. Undernamespace_policy = anythe deployment keeps a namespace list (reserved key classnl,store::keys); a backend MAY keep it in its own metadata instead. - Repos: each coordinator keeps a repo registry, one row per repo
of the namespace (reserved key class
rr; WP-1.22 lays it out). - Repo index shards (
RepoIndex,RefIndex) are enumerable by construction: their object-id-prefix and ref-name-hash fan-outs are fixed deployment constants. - Ref shards are tracked by the coordinator’s active-shard table; WP-5.3a completes GC enumeration, including deleted-ref and ticket-only shards.
- Content shards are enumerable by construction (
INDEX_FANOUT).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Namespace(NamespaceKey)
The whole namespace: single-partition mode. Used by M0 (today’s
single root Durable Object) and by the ssh / fs-layout path for
good; not by D34-sharded deployments.
Coordinator(NamespaceKey)
D34 (M1): the namespace coordinator: config, the grant epoch, the table of currently epoch-leased shards (bounded by active shards) and the repo registry. Rarely written.
Ref
D34 (M1): one per (repo, ref). A branch’s head and packmap share it
(shard_ref is the refs/heads/<x> name). Strongly consistent.
Fields
ns: NamespaceKeyNamespace.
RepoIndex
D34 (M1): repo membership by object-id prefix over the fixed
INDEX_FANOUT (default 4096). Never resharded; eventually
consistent.
RefIndex
D34 (M1): the ref-name index ListRefs reads, hash-sharded over the
fixed REF_INDEX_FANOUT (default 16). Eventually consistent.
ContentShard(u16)
A global ContentIndex shard, by object-id prefix over
INDEX_FANOUT.
Implementations§
Source§impl Partition
impl Partition
Sourcepub const fn kind(&self) -> &'static str
pub const fn kind(&self) -> &'static str
Stable, low-cardinality partition kind for metrics and alerts.
Sourcepub fn encode(&self) -> Result<Bytes, StoreError>
pub fn encode(&self) -> Result<Bytes, StoreError>
The portable encoding: one kind tag byte (n namespace, c
coordinator, r ref, i repo index, x ref index, s content
shard), then each component followed by 0x00. Strings are their
UTF-8 bytes; integers are canonical decimal ASCII. Injective, so a
backend may use it as an opaque name.
§Errors
StoreError::Invalid if a component contains 0x00.
Sourcepub fn decode(bytes: &[u8]) -> Result<Self, StoreError>
pub fn decode(bytes: &[u8]) -> Result<Self, StoreError>
Decode Partition::encode output.
§Errors
StoreError::Corrupt for an unknown tag, a wrong component count,
a missing terminator, invalid UTF-8, an invalid repo name or a
non-canonical integer.