Skip to main content

Partition

Enum Partition 

Source
#[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):

  1. Namespaces (Namespace in single-partition mode, Coordinator under D34) come from deployment configuration and the namespace allowlist. Under namespace_policy = any the deployment keeps a namespace list (reserved key class nl, store::keys); a backend MAY keep it in its own metadata instead.
  2. Repos: each coordinator keeps a repo registry, one row per repo of the namespace (reserved key class rr; WP-1.22 lays it out).
  3. Repo index shards (RepoIndex, RefIndex) are enumerable by construction: their object-id-prefix and ref-name-hash fan-outs are fixed deployment constants.
  4. Ref shards are tracked by the coordinator’s active-shard table; WP-5.3a completes GC enumeration, including deleted-ref and ticket-only shards.
  5. Content shards are enumerable by construction (INDEX_FANOUT).

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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: NamespaceKey

Namespace.

§repo: RepoName

Repository.

§shard_ref: String

The ref whose shard this is.

§

RepoIndex

D34 (M1): repo membership by object-id prefix over the fixed INDEX_FANOUT (default 4096). Never resharded; eventually consistent.

Fields

§ns: NamespaceKey

Namespace.

§repo: RepoName

Repository.

§prefix: u16

Object-id prefix bucket.

§

RefIndex

D34 (M1): the ref-name index ListRefs reads, hash-sharded over the fixed REF_INDEX_FANOUT (default 16). Eventually consistent.

Fields

§ns: NamespaceKey

Namespace.

§repo: RepoName

Repository.

§bucket: u16

Ref-name hash bucket.

§

ContentShard(u16)

A global ContentIndex shard, by object-id prefix over INDEX_FANOUT.

Implementations§

Source§

impl Partition

Source

pub const fn kind(&self) -> &'static str

Stable, low-cardinality partition kind for metrics and alerts.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Partition

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Partition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Partition

Source§

impl Hash for Partition

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Partition

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Partition

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Partition

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Partition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more