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: remove majority of as_caching_storage calls #9006

Merged
merged 7 commits into from
May 11, 2023

Conversation

Longarithm
Copy link
Member

@Longarithm Longarithm commented May 4, 2023

TrieStorage::as_caching_storage is a bad design because it requires all implementations of TrieStorage to know about TrieCachingStorage. We needed it to expose storage metrics and caches, see .

Here we remove majority of such calls, except two:

Testing

Existing tests. We can't test shard cache in test_repeated_values_count anymore, but this makes sense, as caches are hidden implementation detail of TrieCachingStorage.

@Longarithm Longarithm self-assigned this May 11, 2023
@Longarithm Longarithm marked this pull request as ready for review May 11, 2023 11:24
@Longarithm Longarithm requested a review from a team as a code owner May 11, 2023 11:24
@Longarithm Longarithm mentioned this pull request May 11, 2023
10 tasks
Copy link
Contributor

@jakmeier jakmeier left a comment

Choose a reason for hiding this comment

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

Nice, seems like a good trade-off to remove those assertions but make our code cleaner!

Regarding the prefetcher: I don' remember the details anymore. But looking at the code, I beleive we only use it to access pub fn prefetch_api(&self) -> &Option<PrefetchApi>. Maybe that should become part of the TrieStorage trait?

And once we use it in a test to clear caches. This is a bit annoying because for the prefetcher it is a correctness issue whether something is in the cache or not. Maybe the test can be rewritten somehow.
Or we could also put a clear_cache on the TrieStorage trait. But that seems only slightly better than having as_caching_storage on the trait.

@Longarithm
Copy link
Member Author

Nice, seems like a good trade-off to remove those assertions but make our code cleaner!

These assertions are even not needed because now we can create recording storage over any trie storage.

Maybe that should become part of the TrieStorage trait?

Maybe, I'll try.

And once we use it in a test to clear caches. This is a bit annoying because for the prefetcher it is a correctness issue whether something is in the cache or not. Maybe the test can be rewritten somehow.

Now I think the right way is to add method ShardTries::clear_cache. It has update_cache method anyway.

@near-bulldozer near-bulldozer bot merged commit 5339995 into near:master May 11, 2023
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