canic_core/dto/
placement.rs

1use crate::dto::prelude::*;
2
3///
4/// ScalingRegistryEntryView
5///
6
7#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
8pub struct ScalingRegistryEntryView {
9    pub pid: Principal,
10    pub entry: WorkerEntryView,
11}
12
13///
14/// ScalingRegistryView
15///
16
17#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
18pub struct ScalingRegistryView(pub Vec<ScalingRegistryEntryView>);
19
20///
21/// WorkerEntryView
22///
23
24#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
25pub struct WorkerEntryView {
26    pub pool: String,                // which scale pool this belongs to
27    pub canister_role: CanisterRole, // canister role
28    pub created_at_secs: u64,        // timestamp
29}
30
31///
32/// ShardingRegistryEntryView
33///
34
35#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
36pub struct ShardingRegistryEntryView {
37    pub pid: Principal,
38    pub entry: ShardEntryView,
39}
40
41///
42/// ShardingRegistryView
43///
44
45#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
46pub struct ShardingRegistryView(pub Vec<ShardingRegistryEntryView>);
47
48///
49/// ShardingTenantsView
50///
51
52#[derive(CandidType, Clone, Debug, Deserialize, Serialize)]
53pub struct ShardingTenantsView(pub Vec<String>);
54
55///
56/// ShardEntryView
57///
58
59#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
60pub struct ShardEntryView {
61    /// Logical slot index within the pool (assigned deterministically).
62    pub slot: u32,
63    pub capacity: u32,
64    pub count: u32,
65    pub pool: String,
66    pub canister_role: CanisterRole,
67    pub created_at: u64,
68}
69
70///
71/// ShardingPlanStateView
72///
73
74#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
75pub enum ShardingPlanStateView {
76    /// Tenant already has a shard assigned.
77    AlreadyAssigned { pid: Principal },
78
79    /// Tenant can be deterministically assigned to an existing shard (via HRW).
80    UseExisting { pid: Principal },
81
82    /// Policy allows creation of a new shard.
83    CreateAllowed,
84
85    /// Policy forbids creation of a new shard (e.g., capacity reached).
86    CreateBlocked { reason: String },
87}