Skip to content

Commit ff89bb9

Browse files
refactor: [EXC-1752] Remove the parts of old CanisterStateBits after migration (#4335)
This is follow-up on #2254. The plan is to merge this PR after the cutoff for this week's release. --------- Co-authored-by: Dimitris Sarlis <dimitrios.sarlis@dfinity.org>
1 parent c3f0331 commit ff89bb9

File tree

7 files changed

+31
-99
lines changed

7 files changed

+31
-99
lines changed

rs/protobuf/def/state/canister_state_bits/v1/canister_state_bits.proto

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ message CanisterStateBits {
409409
uint64 install_code_debit = 29;
410410
// Contains tasks that need to be executed before processing any input of the
411411
// canister.
412-
// This field will be deprecated after EXC-1752.
413-
repeated ExecutionTask task_queue = 30;
412+
reserved 30;
414413
// Time of last charge for resource allocations.
415414
google.protobuf.UInt64Value time_of_last_allocation_charge_nanos = 31;
416415
// Postponed charges that are not applied to `cycles_balance` yet.
@@ -451,8 +450,7 @@ message CanisterStateBits {
451450
int64 priority_credit = 48;
452451
LongExecutionMode long_execution_mode = 49;
453452
optional uint64 wasm_memory_threshold = 50;
454-
// This field will be deprecated after EXC-1752.
455-
optional OnLowWasmMemoryHookStatus on_low_wasm_memory_hook_status = 53;
453+
reserved 53;
456454
// Contains tasks that need to be executed before processing any input of the
457455
// canister.
458456
TaskQueue tasks = 54;

rs/protobuf/src/gen/state/state.canister_state_bits.v1.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,6 @@ pub struct CanisterStateBits {
602602
/// tracked for the purposes of rate limiting the install_code messages.
603603
#[prost(uint64, tag = "29")]
604604
pub install_code_debit: u64,
605-
/// Contains tasks that need to be executed before processing any input of the
606-
/// canister.
607-
/// This field will be deprecated after EXC-1752.
608-
#[prost(message, repeated, tag = "30")]
609-
pub task_queue: ::prost::alloc::vec::Vec<ExecutionTask>,
610605
/// Time of last charge for resource allocations.
611606
#[prost(message, optional, tag = "31")]
612607
pub time_of_last_allocation_charge_nanos: ::core::option::Option<u64>,
@@ -662,9 +657,6 @@ pub struct CanisterStateBits {
662657
pub long_execution_mode: i32,
663658
#[prost(uint64, optional, tag = "50")]
664659
pub wasm_memory_threshold: ::core::option::Option<u64>,
665-
/// This field will be deprecated after EXC-1752.
666-
#[prost(enumeration = "OnLowWasmMemoryHookStatus", optional, tag = "53")]
667-
pub on_low_wasm_memory_hook_status: ::core::option::Option<i32>,
668660
/// Contains tasks that need to be executed before processing any input of the
669661
/// canister.
670662
#[prost(message, optional, tag = "54")]

rs/replicated_state/src/canister_state/system_state/task_queue.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,6 @@ pub struct TaskQueue {
2828
}
2929

3030
impl TaskQueue {
31-
pub fn from_checkpoint(
32-
queue: VecDeque<ExecutionTask>,
33-
on_low_wasm_memory_hook_status: OnLowWasmMemoryHookStatus,
34-
) -> Self {
35-
let mut mut_queue = queue;
36-
37-
// Extraction of paused_or_aborted_task from queue will be removed in the follow-up EXC-1752 when
38-
// we introduce CanisterStateBits version of TaskQueue, so the conversion will be implicit.
39-
let paused_or_aborted_task = match mut_queue.front() {
40-
Some(ExecutionTask::AbortedInstallCode { .. })
41-
| Some(ExecutionTask::PausedExecution { .. })
42-
| Some(ExecutionTask::PausedInstallCode(_))
43-
| Some(ExecutionTask::AbortedExecution { .. }) => mut_queue.pop_front(),
44-
Some(ExecutionTask::OnLowWasmMemory)
45-
| Some(ExecutionTask::Heartbeat)
46-
| Some(ExecutionTask::GlobalTimer)
47-
| None => None,
48-
};
49-
50-
Self {
51-
paused_or_aborted_task,
52-
on_low_wasm_memory_hook_status,
53-
queue: mut_queue,
54-
}
55-
}
56-
5731
pub fn front(&self) -> Option<&ExecutionTask> {
5832
self.paused_or_aborted_task.as_ref().or_else(|| {
5933
if self.on_low_wasm_memory_hook_status.is_ready() {
@@ -123,20 +97,11 @@ impl TaskQueue {
12397
}
12498
}
12599

126-
/// peek_hook_status will be removed in the follow-up EXC-1752.
100+
/// This function is used only in tests.
127101
pub fn peek_hook_status(&self) -> OnLowWasmMemoryHookStatus {
128102
self.on_low_wasm_memory_hook_status
129103
}
130104

131-
/// get_queue will be removed in the follow-up EXC-1752.
132-
pub fn get_queue(&self) -> VecDeque<ExecutionTask> {
133-
let mut queue = self.queue.clone();
134-
if let Some(task) = self.paused_or_aborted_task.as_ref() {
135-
queue.push_front(task.clone());
136-
}
137-
queue
138-
}
139-
140105
/// `check_dts_invariants` should only be called after round execution.
141106
///
142107
/// It checks that the following properties are satisfied:

rs/state_layout/src/state_layout.rs

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use ic_replicated_state::{
1818
},
1919
},
2020
page_map::{Shard, StorageLayout, StorageResult},
21-
CallContextManager, CanisterStatus, ExecutionTask, ExportedFunctions, NumWasmPages,
21+
CallContextManager, CanisterStatus, ExportedFunctions, NumWasmPages,
2222
};
2323
use ic_sys::{fs::sync_path, mmap::ScopedMmap};
2424
use ic_types::{
@@ -29,7 +29,7 @@ use ic_types::{
2929
use ic_utils::thread::maybe_parallel_map;
3030
use ic_wasm_types::{CanisterModule, WasmHash};
3131
use prometheus::{Histogram, IntCounterVec};
32-
use std::collections::{BTreeMap, BTreeSet, VecDeque};
32+
use std::collections::{BTreeMap, BTreeSet};
3333
use std::convert::{identity, From, TryFrom, TryInto};
3434
use std::ffi::OsStr;
3535
use std::fs::OpenOptions;
@@ -2385,12 +2385,6 @@ impl From<CanisterStateBits> for pb_canister_state_bits::CanisterStateBits {
23852385
heap_delta_debit: item.heap_delta_debit.get(),
23862386
install_code_debit: item.install_code_debit.get(),
23872387
time_of_last_allocation_charge_nanos: Some(item.time_of_last_allocation_charge_nanos),
2388-
task_queue: item
2389-
.task_queue
2390-
.get_queue()
2391-
.iter()
2392-
.map(|v| v.into())
2393-
.collect(),
23942388
global_timer_nanos: item.global_timer_nanos,
23952389
canister_version: item.canister_version,
23962390
consumed_cycles_by_use_cases: item
@@ -2418,12 +2412,6 @@ impl From<CanisterStateBits> for pb_canister_state_bits::CanisterStateBits {
24182412
wasm_memory_limit: item.wasm_memory_limit.map(|v| v.get()),
24192413
next_snapshot_id: item.next_snapshot_id,
24202414
snapshots_memory_usage: item.snapshots_memory_usage.get(),
2421-
on_low_wasm_memory_hook_status: Some(
2422-
pb_canister_state_bits::OnLowWasmMemoryHookStatus::from(
2423-
&item.task_queue.peek_hook_status(),
2424-
)
2425-
.into(),
2426-
),
24272415
tasks: Some((&item.task_queue).into()),
24282416
}
24292417
}
@@ -2479,40 +2467,10 @@ impl TryFrom<pb_canister_state_bits::CanisterStateBits> for CanisterStateBits {
24792467
);
24802468
}
24812469

2482-
let pb_task_queue: Result<pb_canister_state_bits::TaskQueue, ProxyDecodeError> =
2483-
try_from_option_field(value.tasks, "CanisterStateBits::tasks");
2470+
let tasks: pb_canister_state_bits::TaskQueue =
2471+
try_from_option_field(value.tasks, "CanisterStateBits::tasks").unwrap_or_default();
24842472

2485-
let task_queue = match pb_task_queue {
2486-
Ok(tasks) => TaskQueue::try_from(tasks)?,
2487-
Err(_) => {
2488-
let task_queue: VecDeque<ExecutionTask> = value
2489-
.task_queue
2490-
.into_iter()
2491-
.map(|v| v.try_into())
2492-
.collect::<Result<VecDeque<_>, _>>()?;
2493-
if task_queue.len() > 1 {
2494-
return Err(ProxyDecodeError::Other(format!(
2495-
"Expecting at most one task queue entry. Found {:?}",
2496-
task_queue
2497-
)));
2498-
}
2499-
2500-
let on_low_wasm_memory_hook_status: Option<
2501-
pb_canister_state_bits::OnLowWasmMemoryHookStatus,
2502-
> = value.on_low_wasm_memory_hook_status.map(|v| {
2503-
pb_canister_state_bits::OnLowWasmMemoryHookStatus::try_from(v)
2504-
.unwrap_or_default()
2505-
});
2506-
TaskQueue::from_checkpoint(
2507-
task_queue,
2508-
try_from_option_field(
2509-
on_low_wasm_memory_hook_status,
2510-
"CanisterStateBits::on_low_wasm_memory_hook_status",
2511-
)
2512-
.unwrap_or_default(),
2513-
)
2514-
}
2515-
};
2473+
let task_queue = TaskQueue::try_from(tasks)?;
25162474

25172475
Ok(Self {
25182476
controllers,

rs/state_layout/src/state_layout/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use ic_management_canister_types_private::{
44
CanisterChange, CanisterChangeDetails, CanisterChangeOrigin, CanisterInstallMode, IC_00,
55
};
66
use ic_replicated_state::canister_state::system_state::PausedExecutionId;
7+
use ic_replicated_state::ExecutionTask;
78
use ic_replicated_state::{
89
canister_state::system_state::CanisterHistory,
910
metadata_state::subnet_call_context_manager::InstallCodeCallId, page_map::Shard, NumWasmPages,

rs/system_api/tests/system_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ fn helper_test_on_low_wasm_memory(
14561456
let mut state_builder = SystemStateBuilder::default()
14571457
.wasm_memory_threshold(wasm_memory_threshold)
14581458
.wasm_memory_limit(wasm_memory_limit)
1459-
.on_low_wasm_memory_hook_status(start_status)
1459+
.empty_task_queue_with_on_low_wasm_memory_hook_status(start_status)
14601460
.initial_cycles(Cycles::from(10_000_000_000_000_000u128));
14611461

14621462
if let Some(memory_allocation) = memory_allocation {

rs/test_utilities/state/src/lib.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,30 @@ impl SystemStateBuilder {
467467
self
468468
}
469469

470-
pub fn on_low_wasm_memory_hook_status(
470+
pub fn empty_task_queue_with_on_low_wasm_memory_hook_status(
471471
mut self,
472472
on_low_wasm_memory_hook_status: OnLowWasmMemoryHookStatus,
473473
) -> Self {
474-
self.system_state.task_queue =
475-
TaskQueue::from_checkpoint(VecDeque::new(), on_low_wasm_memory_hook_status);
474+
self.system_state.task_queue = TaskQueue::default();
475+
match on_low_wasm_memory_hook_status {
476+
// Default hook status is `ConditionNotSatisfied`.
477+
OnLowWasmMemoryHookStatus::ConditionNotSatisfied => (),
478+
// To make hook status `Ready`, we should enqueue `ExecutionTask::OnLowWasmMemory`.
479+
OnLowWasmMemoryHookStatus::Ready => self
480+
.system_state
481+
.task_queue
482+
.enqueue(ic_replicated_state::ExecutionTask::OnLowWasmMemory),
483+
// To make hook status `Executed`, we should enqueue `ExecutionTask::OnLowWasmMemory`,
484+
// followed by `pop_front()`, which from the standpoint of `TaskQueue` is equivalent to
485+
// executing task.
486+
OnLowWasmMemoryHookStatus::Executed => {
487+
self.system_state
488+
.task_queue
489+
.enqueue(ic_replicated_state::ExecutionTask::OnLowWasmMemory);
490+
self.system_state.task_queue.pop_front();
491+
}
492+
};
493+
476494
self
477495
}
478496

0 commit comments

Comments
 (0)