Skip to main content

mkit_server/pipeline/
shard.rs

1//! Shard routing (PRD ยง5.3, D34; reconciliation R-29). Planners never
2//! hard-code a partition: they ask a [`ShardMap`]. M1 (WP-1.22) adds the
3//! D34 map for configured Connect deployments; the planners stay the same.
4
5mod d34;
6
7use mkit_core::hash::Hash;
8
9pub use d34::D34Shards;
10
11use crate::repo::{NamespaceKey, RepoId};
12use crate::rt::{MaybeSend, MaybeSync};
13use crate::store::{BlobKey, Partition};
14
15/// Maps an operation's rows to the partition that holds them.
16pub trait ShardMap: MaybeSend + MaybeSync {
17    /// The ref shard of `ref_name`: its head, replay records and quota
18    /// counters. A branch head and its packmap MUST map to the same shard,
19    /// so an `AdvanceRefs` commits in one batch.
20    fn ref_shard(&self, repo: &RepoId, ref_name: &str) -> Partition;
21
22    /// The namespace coordinator: configuration and the grant epoch.
23    fn coordinator(&self, ns: &NamespaceKey) -> Partition;
24
25    /// The ref-name index shard that holds `ref_name`.
26    fn ref_index(&self, repo: &RepoId, ref_name: &str) -> Partition;
27
28    /// Every ref-name index shard of `repo`, in bucket order.
29    fn ref_index_partitions(&self, repo: &RepoId) -> Vec<Partition>;
30
31    /// The membership shard of `pack`.
32    fn membership(&self, repo: &RepoId, pack: &BlobKey) -> Partition;
33
34    /// The repository-scoped index shard for an object id.
35    fn object_index(&self, repo: &RepoId, object: &Hash) -> Partition;
36}
37
38/// Every row of a namespace in one partition: M0, and the fs-layout and
39/// ssh path for good.
40#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
41pub struct SinglePartition;
42
43impl ShardMap for SinglePartition {
44    fn ref_shard(&self, repo: &RepoId, _ref_name: &str) -> Partition {
45        Partition::Namespace(repo.namespace.clone())
46    }
47
48    fn coordinator(&self, ns: &NamespaceKey) -> Partition {
49        Partition::Namespace(ns.clone())
50    }
51
52    fn ref_index(&self, repo: &RepoId, _ref_name: &str) -> Partition {
53        Partition::Namespace(repo.namespace.clone())
54    }
55
56    fn ref_index_partitions(&self, repo: &RepoId) -> Vec<Partition> {
57        vec![Partition::Namespace(repo.namespace.clone())]
58    }
59
60    fn membership(&self, repo: &RepoId, _pack: &BlobKey) -> Partition {
61        Partition::Namespace(repo.namespace.clone())
62    }
63
64    fn object_index(&self, repo: &RepoId, _object: &Hash) -> Partition {
65        Partition::Namespace(repo.namespace.clone())
66    }
67}