Skip to content

Commit 178fb97

Browse files
feat: EXC-1527: Add canister snapshots to ReplicatedState
1 parent 7bb428f commit 178fb97

File tree

8 files changed

+47
-6
lines changed

8 files changed

+47
-6
lines changed

rs/http_endpoints/public/src/read_state/canister.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ mod test {
430430
use hyper::StatusCode;
431431
use ic_crypto_tree_hash::{Digest, Label, MixedHashTree, Path};
432432
use ic_registry_subnet_type::SubnetType;
433-
use ic_replicated_state::{CanisterQueues, ReplicatedState, SystemMetadata};
433+
use ic_replicated_state::{
434+
canister_snapshots::CanisterSnapshots, CanisterQueues, ReplicatedState, SystemMetadata,
435+
};
434436
use ic_test_utilities::{
435437
state::insert_dummy_canister,
436438
types::ids::{canister_test_id, subnet_test_id, user_test_id},
@@ -558,6 +560,7 @@ mod test {
558560
metadata,
559561
CanisterQueues::default(),
560562
RawQueryStats::default(),
563+
CanisterSnapshots::default(),
561564
);
562565
assert_eq!(
563566
verify_paths(

rs/http_endpoints/public/src/state_reader_executor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ mod tests {
8080
use ic_crypto_tree_hash::{flatmap, Label, LabeledTree};
8181
use ic_interfaces_state_manager_mocks::MockStateManager;
8282
use ic_registry_subnet_type::SubnetType;
83-
use ic_replicated_state::{CanisterQueues, ReplicatedState, SystemMetadata};
83+
use ic_replicated_state::{
84+
canister_snapshots::CanisterSnapshots, CanisterQueues, ReplicatedState, SystemMetadata,
85+
};
8486
use ic_test_utilities::{state::ReplicatedStateBuilder, types::ids::subnet_test_id};
8587
use ic_test_utilities_time::mock_time;
8688
use ic_types::{
@@ -111,6 +113,7 @@ mod tests {
111113
metadata,
112114
CanisterQueues::default(),
113115
RawQueryStats::default(),
116+
CanisterSnapshots::default(),
114117
)),
115118
)
116119
});

rs/http_endpoints/public/tests/common/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ use ic_registry_keys::{
3434
use ic_registry_provisional_whitelist::ProvisionalWhitelist;
3535
use ic_registry_routing_table::{CanisterMigrations, RoutingTable};
3636
use ic_registry_subnet_type::SubnetType;
37-
use ic_replicated_state::{CanisterQueues, NetworkTopology, ReplicatedState, SystemMetadata};
37+
use ic_replicated_state::{
38+
canister_snapshots::CanisterSnapshots, CanisterQueues, NetworkTopology, ReplicatedState,
39+
SystemMetadata,
40+
};
3841
use ic_test_utilities::{
3942
crypto::{temp_crypto_component_with_fake_registry, CryptoReturningOk},
4043
state::ReplicatedStateBuilder,
@@ -211,6 +214,7 @@ pub fn default_get_latest_state() -> Labeled<Arc<ReplicatedState>> {
211214
metadata,
212215
CanisterQueues::default(),
213216
RawQueryStats::default(),
217+
CanisterSnapshots::default(),
214218
)),
215219
)
216220
}

rs/ingress_manager/benches/handle_ingress.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ use ic_registry_client::client::RegistryClientImpl;
3232
use ic_registry_keys::make_subnet_record_key;
3333
use ic_registry_proto_data_provider::ProtoRegistryDataProvider;
3434
use ic_registry_subnet_type::SubnetType;
35-
use ic_replicated_state::{CanisterQueues, ReplicatedState, SystemMetadata};
35+
use ic_replicated_state::{
36+
canister_snapshots::CanisterSnapshots, CanisterQueues, ReplicatedState, SystemMetadata,
37+
};
3638
use ic_test_utilities::{
3739
crypto::temp_crypto_component_with_fake_registry,
3840
cycles_account_manager::CyclesAccountManagerBuilder,
@@ -189,6 +191,7 @@ where
189191
metadata,
190192
CanisterQueues::default(),
191193
RawQueryStats::default(),
194+
CanisterSnapshots::default(),
192195
)),
193196
)
194197
});

rs/replicated_state/src/canister_snapshots.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ impl CanisterSnapshots {
8080
pub fn take_unflushed_changes(&mut self) -> Vec<SnapshotOperation> {
8181
std::mem::take(&mut self.unflushed_changes)
8282
}
83+
84+
/// Returns true if unflushed changes list is empty.
85+
pub fn is_unflushed_changes_empty(&self) -> bool {
86+
self.unflushed_changes.is_empty()
87+
}
8388
}
8489

8590
/// Contains all information related to a canister snapshot.

rs/replicated_state/src/replicated_state.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::{
33
metadata_state::{IngressHistoryState, Stream, Streams, SystemMetadata},
44
};
55
use crate::{
6+
canister_snapshots::CanisterSnapshots,
67
canister_state::queues::CanisterQueuesLoopDetector,
78
canister_state::system_state::{push_input, CanisterOutputQueuesIterator},
89
metadata_state::{subnet_call_context_manager::SignWithEcdsaContext, StreamMap},
@@ -406,6 +407,9 @@ pub struct ReplicatedState {
406407
/// Temporary query stats received during the current epoch.
407408
/// Reset during the start of each epoch.
408409
pub epoch_query_stats: RawQueryStats,
410+
411+
/// Manages the canister snapshots.
412+
pub canister_snapshots: CanisterSnapshots,
409413
}
410414

411415
impl ReplicatedState {
@@ -417,6 +421,7 @@ impl ReplicatedState {
417421
subnet_queues: CanisterQueues::default(),
418422
consensus_queue: Vec::new(),
419423
epoch_query_stats: RawQueryStats::default(),
424+
canister_snapshots: CanisterSnapshots::default(),
420425
}
421426
}
422427

@@ -426,13 +431,15 @@ impl ReplicatedState {
426431
metadata: SystemMetadata,
427432
subnet_queues: CanisterQueues,
428433
epoch_query_stats: RawQueryStats,
434+
canister_snapshots: CanisterSnapshots,
429435
) -> Self {
430436
let mut res = Self {
431437
canister_states,
432438
metadata,
433439
subnet_queues,
434440
consensus_queue: Vec::new(),
435441
epoch_query_stats,
442+
canister_snapshots,
436443
};
437444
res.update_stream_responses_size_bytes();
438445
res
@@ -923,6 +930,7 @@ impl ReplicatedState {
923930
mut subnet_queues,
924931
consensus_queue,
925932
epoch_query_stats: _,
933+
canister_snapshots,
926934
} = self;
927935

928936
// Consensus queue is always empty at the end of the round.
@@ -958,6 +966,7 @@ impl ReplicatedState {
958966
subnet_queues,
959967
consensus_queue,
960968
epoch_query_stats: RawQueryStats::default(), // Don't preserve query stats during subnet splitting.
969+
canister_snapshots,
961970
})
962971
}
963972

@@ -980,6 +989,7 @@ impl ReplicatedState {
980989
ref mut subnet_queues,
981990
consensus_queue: _,
982991
epoch_query_stats: _,
992+
canister_snapshots: _,
983993
} = self;
984994

985995
// Reset query stats after subnet split
@@ -1140,6 +1150,8 @@ pub mod testing {
11401150
subnet_queues: Default::default(),
11411151
consensus_queue: Default::default(),
11421152
epoch_query_stats: Default::default(),
1153+
// TODO(EXC-1527): Handle canister snapshots during a subnet split.
1154+
canister_snapshots: CanisterSnapshots::default(),
11431155
};
11441156
}
11451157
}

rs/state_manager/src/checkpoint.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use ic_base_types::{subnet_id_try_from_protobuf, CanisterId};
77
use ic_config::flag_status::FlagStatus;
88
use ic_logger::error;
99
use ic_registry_subnet_type::SubnetType;
10+
use ic_replicated_state::canister_snapshots::CanisterSnapshots;
1011
use ic_replicated_state::page_map::PageAllocatorFileDescriptor;
1112
use ic_replicated_state::{
1213
canister_state::execution_state::WasmBinary, page_map::PageMap, CanisterMetrics, CanisterState,
@@ -258,8 +259,15 @@ pub fn load_checkpoint<P: ReadPolicy + Send + Sync>(
258259
canister_states
259260
};
260261

261-
let state =
262-
ReplicatedState::new_from_checkpoint(canister_states, metadata, subnet_queues, query_stats);
262+
// TODO(EXC-1539): Load canister snapshots from checkpoint.
263+
let canister_snapshots = CanisterSnapshots::default();
264+
let state = ReplicatedState::new_from_checkpoint(
265+
canister_states,
266+
metadata,
267+
subnet_queues,
268+
query_stats,
269+
canister_snapshots,
270+
);
263271

264272
Ok(state)
265273
}

rs/state_manager/src/tip.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ fn serialize_to_tip(
788788
metrics: &StorageMetrics,
789789
lsmt_storage: FlagStatus,
790790
) -> Result<(), CheckpointError> {
791+
//TODO(MR-530): Implement serializing canister snapshots.
792+
debug_assert!(state.canister_snapshots.is_unflushed_changes_empty());
793+
791794
// Serialize ingress history separately. The `SystemMetadata` proto does not
792795
// encode it.
793796
//

0 commit comments

Comments
 (0)