canic_core/ops/placement/sharding/
mod.rs

1pub mod assign;
2mod hrw;
3mod metrics;
4pub mod policy;
5
6pub use crate::ops::storage::sharding::ShardingRegistryOps;
7pub use metrics::{PoolMetrics, pool_metrics};
8pub use {assign::*, policy::*};
9
10use crate::{Error, ThisError, cdk::types::Principal, ops::storage::sharding::ShardEntry};
11
12///
13/// ShardingOpsError
14/// Logical or configuration errors that occur during sharding planning.
15///
16
17#[derive(Debug, ThisError)]
18pub enum ShardingOpsError {
19    #[error("shard pool not found: {0}")]
20    PoolNotFound(String),
21
22    #[error("shard cap reached")]
23    ShardCapReached,
24
25    #[error("shard creation blocked: {0}")]
26    ShardCreationBlocked(String),
27
28    #[error("shard full: {0}")]
29    ShardFull(Principal),
30
31    #[error("shard not found: {0}")]
32    ShardNotFound(Principal),
33
34    #[error("sharding disabled")]
35    ShardingDisabled,
36
37    #[error("tenant '{0}' not found")]
38    TenantNotFound(String),
39}
40
41impl From<ShardingOpsError> for Error {
42    fn from(err: ShardingOpsError) -> Self {
43        Self::OpsError(err.to_string())
44    }
45}
46
47///
48/// ShardingRegistryDto
49///
50
51pub type ShardingRegistryDto = Vec<(Principal, ShardEntry)>;