Skip to main content

Partitioning

Enum Partitioning 

Source
pub enum Partitioning {
    Hash {
        columns: Vec<ColumnId>,
        buckets: u32,
    },
    Range {
        columns: Vec<ColumnId>,
        splits: Vec<Key>,
    },
    Tenant {
        tenant_column: ColumnId,
        buckets_per_tenant: u32,
    },
    TimeRange {
        timestamp_column: ColumnId,
        interval: TimeInterval,
    },
}
Expand description

How one table’s rows map onto tablets (spec section 12.2). Declaration order is frozen; variants are never reused (spec section 4.10).

Variants§

§

Hash

Hash of the declared columns into a fixed bucket space. Tablets own contiguous runs of buckets (see Partitioning::routed_key).

Fields

§columns: Vec<ColumnId>

Partition-key columns, in hash order.

§buckets: u32

Bucket count; positive.

§

Range

Lexicographic ranges over the declared columns, split at splits. splits.len() + 1 partitions cover the key space: partition i owns [splits[i - 1], splits[i]), unbounded at the edges.

Fields

§columns: Vec<ColumnId>

Partition-key columns, in sort order.

§splits: Vec<Key>

Ordered, strictly increasing split points.

§

Tenant

One bucket space per tenant: the tenant column hashes into buckets_per_tenant buckets, so every tenant’s rows spread evenly and tenants can be isolated onto dedicated tablets (spec section 12.5).

Fields

§tenant_column: ColumnId

Column carrying the tenant identifier.

§buckets_per_tenant: u32

Buckets each tenant hashes into; positive.

§

TimeRange

Time-bucketed ranges: partition i owns [i * interval, (i + 1) * interval) of the timestamp column.

Fields

§timestamp_column: ColumnId

Column carrying the row timestamp.

§interval: TimeInterval

Fixed interval width.

Implementations§

Source§

impl Partitioning

Source

pub fn validate(&self) -> Result<(), PartitionError>

Validates the declaration: non-empty column lists, positive bucket counts, strictly increasing splits, positive interval.

Source

pub fn partition_columns(&self) -> Vec<ColumnId>

The declared partition-key columns, in key order (spec section 12.2: every table has a declared partition key).

Source

pub fn partition_key( &self, values: &BTreeMap<ColumnId, KeyValue>, ) -> Result<Key, PartitionError>

Extracts the partition key from a row’s column values: the declared partition-key columns, in declared order, encoded by RowKeyEncoder. A missing declared column fails closed.

The fast path of spec section 12.2 — the primary key includes the partition key — means the caller can usually supply the primary-key components directly; this function does not care where the values came from.

Source

pub fn route(&self, partition_key: &Key) -> Result<u64, PartitionError>

Maps an extracted partition key onto its partition slot (spec section 12.2):

  • Hash: fnv1a64(key) % buckets.
  • Range: index of the first split above the key, 0..=splits.len().
  • Tenant: fnv1a64(tenant key) % buckets_per_tenant; the slot is per tenant, so the full partition address is (tenant, slot) — see Self::routed_key.
  • TimeRange: timestamp / interval (epoch-floored); pre-epoch timestamps fail closed with PartitionError::NegativeSlot.
Source

pub fn routed_key(&self, partition_key: &Key) -> Result<Key, PartitionError>

The canonical routing address of a partition key — the byte string whose ranges the tablet PartitionBounds of this table are allocated over:

  • Range and TimeRange: the partition key itself; bounds range directly over encoded key bytes.
  • Hash: the 8 big-endian bytes of the bucket; the meta plane allocates tablet bounds as contiguous bucket runs, e.g. buckets [lo, hi) via hash_slot_bounds.
  • Tenant: the tenant key encoding followed by the 8 big-endian bytes of the bucket, so bounds range per tenant over the composite.
Source

pub fn range_bounds(&self, index: u64) -> Option<PartitionBounds>

The bounds of range partition index (0..=splits.len()); None for out-of-range indexes and non-range partitioning.

Trait Implementations§

Source§

impl Clone for Partitioning

Source§

fn clone(&self) -> Partitioning

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 Partitioning

Source§

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

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

impl<'de> Deserialize<'de> for Partitioning

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Partitioning

Source§

impl PartialEq for Partitioning

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Partitioning

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Partitioning

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> AppData for T
where T: OptionalSend + OptionalSync + 'static + OptionalSerde,

Source§

impl<T> AppDataResponse for T
where T: OptionalSend + OptionalSync + 'static + OptionalSerde,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

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

Source§

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

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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