Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist Partitions into a thread_local variable and remove PartitionsMaybe #6298

Merged
merged 3 commits into from
Jan 31, 2025

Conversation

jasonz-dfinity
Copy link
Contributor

@jasonz-dfinity jasonz-dfinity commented Jan 31, 2025

Motivation

Partitions is already "global", in the sense that even in unit tests (ic_stable_structures::VectorMemory) is an Rc<RefCell<Vec<u8>>>, and operations to various memory partitions read/write from/to the bytes owned by the Rc. Therefore, it makes sense for Partitions to be a thread_local! variable. On the other hand, PartitionsMaybe is only useful when there can be 2 cases (raw/managed memory), which is no longer the case after the migration.

Changes

  1. Define PARTITIONS thread_local variable and add accessors
  2. Remove everything related to PartitionsMaybe and simplify dead code

Tests

N/A since it's mostly trivial refactoring. Tests under rs/backend/src/state/tests.rs should cover the code changed in this PR.

Related PRs

Previous | Next

github-merge-queue bot pushed a commit that referenced this pull request Jan 31, 2025
# Motivation

2 reasons for this refactoring:

1. The backup/restore of `State` is currently a bit convoluted - it
creates an AccountsStore with `AccountsDbAsMap` and replace it with
`AccountsDbAsUnboundedStableBTreeMap` afterwards. This will be changed
in a future PR. However, the functionalities of reading/writing bytes
from/to managed memory are clear and useful, so they are moved to
separate functions.
2. `PartitionsMaybe` will be removed, and the `Partitions` will be moved
out of `State` in the next PR. When that happens, it makes less sense to
have the logic to read/write managed memory in `State`, but rather
`Partitions`. `State` will mostly care about how itself can be
encoded/decoded


# Changes

Extract reading/writing bytes logic from
`save_heap_to_managed_memory`/`recover_heap_from_managed_memory` to
`Partition` methods

# Tests

Added tests for newly extracted methods

# Todos

- [x] Add entry to changelog (if necessary).

# Related PRs

[Next](#6298)
Base automatically changed from jason/NNS1-3030-1 to main January 31, 2025 18:09
@jasonz-dfinity jasonz-dfinity added this pull request to the merge queue Jan 31, 2025
Merged via the queue into main with commit 9ea54fb Jan 31, 2025
32 checks passed
@jasonz-dfinity jasonz-dfinity deleted the jason/NNS1-3030-2 branch January 31, 2025 19:49
github-merge-queue bot pushed a commit that referenced this pull request Jan 31, 2025
…6301)

# Motivation

`accounts_db_stats_recomputed_on_upgrade` is no longer useful after the
migration of accounts to stable structures. It is always `opt false`,
which can be verified by `dfx canister --ic call
qoctq-giaaa-aaaaa-aaaea-cai get_stats | grep
accounts_db_stats_recomputed_on_upgrade`

# Changes

Remove everything related to `accounts_db_stats_recomputed_on_upgrade`

# Tests

N/A

# Related PRs

[Previous](#6298) |
[Next](#6302)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants