feat: [MR-142] Introduce hot/cold-partitioned CanisterStates#10280
Open
alin-at-dfinity wants to merge 1 commit into
Open
feat: [MR-142] Introduce hot/cold-partitioned CanisterStates#10280alin-at-dfinity wants to merge 1 commit into
CanisterStates#10280alin-at-dfinity wants to merge 1 commit into
Conversation
Lays the foundation for splitting `ReplicatedState::canister_states` into
"hot" (potentially active) and "cold" (definitely idle) pools, so that
per-round operations can skip the long tail of idle canisters.
This PR is intentionally a no-op for the running replica: it only adds
the new types and predicates. The integration into `ReplicatedState` and
the migration of all consumers follow in subsequent PRs.
Specifically:
* `CanisterState::is_cold()` — pure predicate that classifies a canister
as "definitely idle": no input/output, no task queue entries, no
heartbeat method, inactive global timer, not `Stopping`, no
unexpired best-effort callbacks, and no scheduler debits.
* `CallContextManager::has_unexpired_callbacks()` and the matching
`SystemState::has_unexpired_callbacks()` accessor, used by `is_cold`.
* `CanisterStates`, a hot/cold-partitioned container with eager
promotion (mutations land in `hot`) and lazy demotion (via
`try_cool`/`try_cool_all`), plus the common map operations
(`get`/`get_mut`/`insert`/`remove`/`contains_key`/`len`/`is_empty`/
`retain`), per-pool iterators (`hot_iter`/`hot_values`/
`hot_values_mut`), merged iterators in `CanisterId` order
(`all_iter`/`all_keys`/`all_values`), and bulk mutation
(`for_each_mut`/`try_for_each_mut`).
* `CanisterStates::validate_strict_split()` for the canonical-partition
invariant used in checkpoint validation.
* `debug_assert_invariants()` runs on every mutating operation in
debug builds.
`ColdStats` and the aggregate accessors (`total_compute_allocation`,
`total_canister_memory_usage`, `memory_taken`, `callback_count`, ...)
are intentionally **not** part of this PR — they will be added once the
struct is in place.
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lays the foundation for splitting
ReplicatedState::canister_statesinto "hot" (potentially active) and "cold" (definitely idle) pools, so that per-round operations can completely ignore the long tail of idle canisters.This PR is intentionally a no-op for the running replica: it only adds the new types and predicates. The integration into
ReplicatedStateand the migration of all consumers follow in subsequent PRs.Specifically:
CanisterState::is_cold()— pure predicate that classifies a canister as "definitely idle": no input/output, no heartbeat, notStopping, etc.CallContextManager::has_unexpired_callbacks()and the matchingSystemState::has_unexpired_callbacks()accessor, used byis_cold.CanisterStates, a hot/cold-partitioned container with eager promotion (mutations land inhot) and lazy demotion (viatry_cool/try_cool_all); plus the common map operations, per-pool and merged iterators and bulk mutation.CanisterStates::validate_strict_split()for the canonical-partition invariant used in checkpoint validation.debug_assert_invariants()runs on every mutating operation in debug builds.