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

refactor: use shard uid in flat state keys #8685

Merged
merged 10 commits into from
Mar 8, 2023

Conversation

Longarithm
Copy link
Member

@Longarithm Longarithm commented Mar 7, 2023

Prepend ShardUId to flat state keys, as motivated in #8670.

Ideally we need to replace shard_id with shard_uid everywhere, including other DB keys and RuntimeAdapter flat storage methods. But this change would be too involved, so let's do it incrementally.

The biggest structural consequence is that FlatStorage now stores shard_uid, which makes sense, and later it will be used for writing deltas as well. It's not a big deal, but because of that changes are scattered throughout the code and may look scary.

Testing

@Longarithm Longarithm marked this pull request as ready for review March 7, 2023 16:58
@Longarithm Longarithm requested a review from a team as a code owner March 7, 2023 16:58
core/store/src/flat/storage.rs Outdated Show resolved Hide resolved
core/store/src/flat/store_helper.rs Outdated Show resolved Hide resolved
///
/// WARNING: flat storage keeps changing, so the results might be inconsistent, unless you're running
/// this method on the shapshot of the data.
// TODO(#8676): Support non-trivial ranges.
pub fn iter_flat_state_entries<'a>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like we also need to chage this method to accept shard_uid instead of shard_id and do a proper prefix-read? or do you please to do that as a separate PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would do it separately. Maybe even outside MVP, because we don't use this logic much.

@pugachAG
Copy link
Contributor

pugachAG commented Mar 7, 2023

also update columns.rs:

- DBCol::FlatState => &[DBKeyType::TrieKey],
+ DBCol::FlatState => &[DBKeyType::ShardUId, DBKeyType::TrieKey],

@akhi3030
Copy link
Collaborator

akhi3030 commented Mar 8, 2023

@pugachAG: please ping me when you are satisfied with this PR and it is ready to be merged.

@Longarithm Longarithm requested a review from pugachAG March 8, 2023 11:48
Copy link
Contributor

@pugachAG pugachAG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! @akhi3030

@near-bulldozer near-bulldozer bot merged commit a8dadbe into near:master Mar 8, 2023
@Longarithm Longarithm deleted the fs-key-shard-uid branch March 8, 2023 13:03
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Mar 15, 2023
Prepend `ShardUId` to flat state keys, as motivated in near#8670.

Ideally we need to replace `shard_id` with `shard_uid` everywhere, including other DB keys and `RuntimeAdapter` flat storage methods. But this change would be too involved, so let's do it incrementally.

The biggest structural consequence is that `FlatStorage` now stores `shard_uid`, which makes sense, and later it will be used for writing deltas as well. It's not a big deal, but because of that changes are scattered throughout the code and may look scary.

## Testing

* `test_flat_storage_iter` checks that new `key_belongs_to_shard` impl is aligned with shard layout; also we can see that the change takes place in this failing test: https://buildkite.com/nearprotocol/nearcore/builds/25676#0186bc8f-12a2-410a-b74c-e326f3b963fa
* https://nayduck.near.org/#/run/2898
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.

3 participants