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

feat(event cache): reload a linked chunk from a store #4362

Merged
merged 4 commits into from
Dec 2, 2024

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Dec 2, 2024

This implements the following:

  • add a new trait method to reload a linked chunk from the store. In particular, we want to distinguish reloading when there's nothing in the store (could happen if we never saved a chunk before) from reloading a non-empty chunk. The reason is, that there's an invariant in the linked chunk code that when it's empty, a linked chunk has a single empty Events chunk; we let the caller maintain that invariant by creating the linked chunk in this case.
  • implement that trait for the sqlite store; it's trivial, since the sqlite store had to implement similar functionality just so as to be tested.
  • implement that trait for the in-memory store; while not complicated, it's a bit unwieldy because the in-memory store keeps one line per item in a chunk, instead of storing the entire items vector. But still, relatively easy to manage :-)
  • adds integration tests at the trait level for the event cache store, for handling and reloading a chunk at the same time. Moves a bit of code from the sqlite testing framework, to help with creating and checking synthetic events.

Part of #3280

@bnjbvr bnjbvr requested a review from Hywan December 2, 2024 10:57
@bnjbvr bnjbvr requested a review from a team as a code owner December 2, 2024 10:57
Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

Looks great to me!

) -> Result<Option<LinkedChunk<DEFAULT_CHUNK_CAPACITY, Event, Gap>>, Self::Error> {
// TODO(hywan)
Copy link
Member

Choose a reason for hiding this comment

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

Good job hywan.

Copy link

codecov bot commented Dec 2, 2024

Codecov Report

Attention: Patch coverage is 89.07563% with 13 lines in your changes missing coverage. Please review.

Project coverage is 85.13%. Comparing base (685386d) to head (771cb00).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...s/matrix-sdk-common/src/linked_chunk/relational.rs 76.19% 10 Missing ⚠️
...rix-sdk-base/src/event_cache/store/memory_store.rs 77.77% 2 Missing ⚠️
crates/matrix-sdk-sqlite/src/event_cache_store.rs 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4362      +/-   ##
==========================================
+ Coverage   85.10%   85.13%   +0.02%     
==========================================
  Files         280      280              
  Lines       30535    30654     +119     
==========================================
+ Hits        25988    26098     +110     
- Misses       4547     4556       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bnjbvr bnjbvr enabled auto-merge (rebase) December 2, 2024 11:25
@bnjbvr bnjbvr disabled auto-merge December 2, 2024 11:43
@bnjbvr
Copy link
Member Author

bnjbvr commented Dec 2, 2024

@Hywan FWIW, I've added a small fix in the last commit (with a regression test). If we added an empty items chunk (which is totally fine, by contract), it would incorrectly lead to an invalid data error. Instead, when we find a chunk with no rows, we have to assume it's an empty events chunk. That's the change happening in the last commit.

@Hywan
Copy link
Member

Hywan commented Dec 2, 2024

All good to me, thanks for the bug fix!

@bnjbvr bnjbvr enabled auto-merge (rebase) December 2, 2024 12:28
@bnjbvr bnjbvr merged commit 5da36d1 into main Dec 2, 2024
40 checks passed
@bnjbvr bnjbvr deleted the bnjbvr/reload-from-event-cache branch December 2, 2024 13:09
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