diff --git a/backend/canisters/group/impl/src/lifecycle/post_upgrade.rs b/backend/canisters/group/impl/src/lifecycle/post_upgrade.rs index 29223325a3..1dab174e16 100644 --- a/backend/canisters/group/impl/src/lifecycle/post_upgrade.rs +++ b/backend/canisters/group/impl/src/lifecycle/post_upgrade.rs @@ -23,11 +23,6 @@ fn post_upgrade(args: Args) { // Only proceed with removing events from the heap if the stable memory migration is complete assert!(data.stable_memory_event_migration_complete); - // Set the migration flag to false if threads need to be updated, but this can be done purely - // in stable memory so no need to abort the upgrade - if data.chat.events.thread_messages_to_update_in_stable_memory_len() > 0 { - data.stable_memory_event_migration_complete = false; - } data.chat.events.init_maps(); canister_logger::init_with_logs(data.test_mode, errors, logs, traces); diff --git a/backend/canisters/local_group_index/CHANGELOG.md b/backend/canisters/local_group_index/CHANGELOG.md index c729c1b6e4..49437d5b6f 100644 --- a/backend/canisters/local_group_index/CHANGELOG.md +++ b/backend/canisters/local_group_index/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +## [[2.0.1449](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1449-local_group_index)] - 2024-11-13 + ### Added - Run job to trigger migrating events in all Groups to stable memory ([#6810](https://github.com/open-chat-labs/open-chat/pull/6810)) diff --git a/backend/canisters/local_group_index/impl/src/jobs/migrate_events_to_stable_memory.rs b/backend/canisters/local_group_index/impl/src/jobs/migrate_events_to_stable_memory.rs deleted file mode 100644 index c43276d99d..0000000000 --- a/backend/canisters/local_group_index/impl/src/jobs/migrate_events_to_stable_memory.rs +++ /dev/null @@ -1,57 +0,0 @@ -use crate::{mutate_state, RuntimeState}; -use ic_cdk_timers::TimerId; -use rand::Rng; -use std::cell::Cell; -use std::time::Duration; -use tracing::trace; -use types::{CanisterId, Empty}; - -thread_local! { - static TIMER_ID: Cell> = Cell::default(); -} - -pub(crate) fn start_job_if_required(state: &RuntimeState) -> bool { - if TIMER_ID.get().is_none() && !state.data.canisters_pending_events_migration_to_stable_memory.is_empty() { - let timer_id = ic_cdk_timers::set_timer_interval(Duration::ZERO, run); - TIMER_ID.set(Some(timer_id)); - trace!("'migrate_events_to_stable_memory' job started"); - true - } else { - false - } -} - -fn run() { - if let Some(canister_id) = mutate_state(next) { - ic_cdk::spawn(migrate_events(canister_id)); - } else if let Some(timer_id) = TIMER_ID.take() { - ic_cdk_timers::clear_timer(timer_id); - trace!("'migrate_events_to_stable_memory' job stopped"); - } -} - -fn next(state: &mut RuntimeState) -> Option { - if state.data.canisters_pending_events_migration_to_stable_memory.is_empty() { - return None; - } - - let len = state.data.canisters_pending_events_migration_to_stable_memory.len(); - let random: usize = state.env.rng().gen_range(0..len); - - state - .data - .canisters_pending_events_migration_to_stable_memory - .get(random) - .copied() -} - -async fn migrate_events(canister_id: CanisterId) { - if let Ok(true) = group_canister_c2c_client::c2c_migrate_events_to_stable_memory(canister_id, &Empty {}).await { - mutate_state(|state| { - state - .data - .canisters_pending_events_migration_to_stable_memory - .retain(|c| *c != canister_id); - }); - } -} diff --git a/backend/canisters/local_group_index/impl/src/jobs/mod.rs b/backend/canisters/local_group_index/impl/src/jobs/mod.rs index cf455678d1..1f3eb45d61 100644 --- a/backend/canisters/local_group_index/impl/src/jobs/mod.rs +++ b/backend/canisters/local_group_index/impl/src/jobs/mod.rs @@ -1,13 +1,11 @@ use crate::RuntimeState; -pub mod migrate_events_to_stable_memory; pub mod topup_canister_pool; pub mod topup_canisters; pub mod upgrade_communities; pub mod upgrade_groups; pub(crate) fn start(state: &RuntimeState) { - migrate_events_to_stable_memory::start_job_if_required(state); topup_canister_pool::start_job_if_required(state, None); topup_canisters::start_job(); upgrade_communities::start_job_if_required(state); diff --git a/backend/canisters/local_group_index/impl/src/lifecycle/post_upgrade.rs b/backend/canisters/local_group_index/impl/src/lifecycle/post_upgrade.rs index 453ba8b248..45e0149e2c 100644 --- a/backend/canisters/local_group_index/impl/src/lifecycle/post_upgrade.rs +++ b/backend/canisters/local_group_index/impl/src/lifecycle/post_upgrade.rs @@ -7,7 +7,6 @@ use ic_cdk::post_upgrade; use local_group_index_canister::post_upgrade::Args; use stable_memory::get_reader; use tracing::info; -use types::CanisterId; use utils::cycles::init_cycles_dispenser_client; #[post_upgrade] @@ -16,12 +15,9 @@ fn post_upgrade(args: Args) { let memory = get_upgrades_memory(); let reader = get_reader(&memory); - let (mut data, errors, logs, traces): (Data, Vec, Vec, Vec) = + let (data, errors, logs, traces): (Data, Vec, Vec, Vec) = msgpack::deserialize(reader).unwrap(); - data.canisters_pending_events_migration_to_stable_memory = - data.local_groups.iter().map(|(g, _)| CanisterId::from(*g)).collect(); - canister_logger::init_with_logs(data.test_mode, errors, logs, traces); let env = init_env(data.rng_seed);