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): handle linked chunk updates and reload in the sqlite backend #4340

Merged
merged 7 commits into from
Nov 28, 2024

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Nov 27, 2024

So, it's a bit of a chatty PR:

  • because of the tests,
  • because the tests required reading out from the store, I've implemented the full linked chunk reloading; it's using the intermediary raw format at this point, and later we can use the LinkedChunkBuilder to recreate the full thing.

Apart from that, the changes here are somewhat boring, and just running SQL requests.

I've taken the liberty to add a (clear) event id as a column for the events table, so we can add fetch_by_id easily in the future; this avoids a trivial migration.

Part of #3280
Split from #4308.

…lities

This required adding support for *reading* out of the event cache, for
the sqlite backend. This paves the way for the next PR (reload from the
cache), and it should also help with testing at the `EventCacheStore`
trait layer some day.
@bnjbvr bnjbvr requested a review from a team as a code owner November 27, 2024 12:48
@bnjbvr bnjbvr requested review from poljar and removed request for a team November 27, 2024 12:48
@bnjbvr bnjbvr mentioned this pull request Nov 27, 2024
37 tasks
@bnjbvr bnjbvr force-pushed the bnjbvr/sqlite-event-cache-store branch from 31a0a4b to e624870 Compare November 27, 2024 12:52
@Hywan Hywan requested review from Hywan and removed request for poljar November 27, 2024 13:07
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.

Great work! I see no blocker, I just have a couple of questions and one feedback for a possible improvement. Other than that, great!

-- Identifier of the chunk, unique per room.
"id" INTEGER,
-- Which room does this chunk belong to? (hashed key shared with the two other tables)
"room_id" BLOB NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

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

I've just learned the difference between BLOB and TEXT in SQLite, but I wonder if we just not used a TEXT here. According to this forum thread:

BLOBs cannot be searched, compared, or manipulated.

I think we want TEXT here. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uhuh, interesting. That suggests we may have issues when there are multiple rooms, then 👀 I'll do a few experiments and change it, if needs be — pretty sure we've been using that in other places too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pfew, https://sqlite.org/datatype3.html#sort_order says that BLOB are compared with memcmp, so we're fine. I've added a test that used the same chunk identifier in two different rooms, and it passes, so it's all fine as is. We're using BLOB in many many places, so if this should've failed, it would have failed elsewhere too ^^

So now, I do buy it that using TEXT would offer us more, e.g. searching substrings, prefixes, etc. I don't think it's a useful use case for us, to search for a room id substring, be it in the clear or hashed.

Thanks for raising this, though! TIL 😌

"room_id" BLOB NOT NULL,

-- The previous batch token of a gap (encrypted value).
"prev_token" BLOB NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we also want a TEXT here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have a use case in mind where we'd need to search by prev_token?

Copy link
Member Author

Choose a reason for hiding this comment

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

Related to the other comment: no need to specify TEXT unless we think we could need operations specific to a text object, which I don't think we need here either.

crates/matrix-sdk-sqlite/src/event_cache_store.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-sqlite/src/event_cache_store.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-sqlite/src/event_cache_store.rs Outdated Show resolved Hide resolved
@bnjbvr bnjbvr force-pushed the bnjbvr/sqlite-event-cache-store branch from bdefc0c to 4b1e7e2 Compare November 28, 2024 10:12
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 97.17514% with 5 lines in your changes missing coverage. Please review.

Project coverage is 85.08%. Comparing base (3e7d7e8) to head (4b1e7e2).
Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-sqlite/src/event_cache_store.rs 97.12% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4340      +/-   ##
==========================================
+ Coverage   85.01%   85.08%   +0.07%     
==========================================
  Files         275      275              
  Lines       30313    30487     +174     
==========================================
+ Hits        25770    25940     +170     
- Misses       4543     4547       +4     

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

@bnjbvr bnjbvr merged commit daa984f into main Nov 28, 2024
40 checks passed
@bnjbvr bnjbvr deleted the bnjbvr/sqlite-event-cache-store branch November 28, 2024 10:48
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