Skip to main content

canic_core/dto/placement/
sharding.rs

1use crate::dto::prelude::*;
2
3//
4// ShardingRegistryEntry
5//
6
7#[derive(CandidType, Clone, Debug, Deserialize)]
8pub struct ShardingRegistryEntry {
9    pub pid: Principal,
10    pub entry: ShardEntry,
11}
12
13//
14// ShardingRegistryResponse
15//
16
17#[derive(CandidType, Clone, Debug, Deserialize)]
18pub struct ShardingRegistryResponse(pub Vec<ShardingRegistryEntry>);
19
20//
21// ShardingPartitionKeysResponse
22//
23
24#[derive(CandidType, Clone, Debug, Deserialize)]
25pub struct ShardingPartitionKeysResponse(pub Vec<String>);
26
27//
28// ShardEntry
29//
30
31#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
32pub struct ShardEntry {
33    // Logical slot index within the pool (assigned deterministically).
34    pub slot: u32,
35    pub capacity: u32,
36    pub count: u32,
37    pub pool: String,
38    pub canister_role: CanisterRole,
39    pub created_at: u64,
40}
41
42//
43// ShardingPlanStateResponse
44//
45
46#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
47pub enum ShardingPlanStateResponse {
48    // Partition key already has a shard assigned.
49    AlreadyAssigned { pid: Principal },
50
51    // Partition key can be deterministically assigned to an existing shard (via HRW).
52    UseExisting { pid: Principal },
53
54    // Policy allows creation of a new shard.
55    CreateAllowed,
56
57    // Policy forbids creation of a new shard (e.g., capacity reached).
58    CreateBlocked { reason: String },
59}