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(sqlite): Run VACUUM operation after removing a room #4651

Merged
merged 5 commits into from
Feb 11, 2025

Conversation

zecakeh
Copy link
Collaborator

@zecakeh zecakeh commented Feb 11, 2025

A room can be associated to a lot of data, depending on the number of members in the room.
So freeing space on the filesystem should be worth it in some cases.

An (extreme) example: I have a test account that is in ~60 rooms, a few of those big public rooms, including Matrix HQ. The size of the matrix-sdk-state.sqlite3 file is 542 MB. Using this PR and leaving, then forgetting Matrix HQ brings the DB down to 255 MB.

A room can be associated to a lot of data, depending on the number of members in the room.
So freeing space on the filesystem should be worth it in some cases.

Signed-off-by: Kévin Commaille <[email protected]>
@zecakeh zecakeh requested a review from a team as a code owner February 11, 2025 13:18
@zecakeh zecakeh requested review from bnjbvr and removed request for a team February 11, 2025 13:18
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 85.69%. Comparing base (69588d5) to head (cc4a26c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-sqlite/src/utils.rs 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4651      +/-   ##
==========================================
+ Coverage   85.68%   85.69%   +0.01%     
==========================================
  Files         292      292              
  Lines       33570    33574       +4     
==========================================
+ Hits        28763    28770       +7     
+ Misses       4807     4804       -3     

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

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Thanks, makes sense

})
.await?;

conn.vacuum().await
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we can vacuum as part of the transaction, or if it would lead to more trouble? It's not clear from the sqlite doc…

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it's not possible it returns an error.

#[cfg(test)]
return Err(error.into());
}
conn.vacuum().await?;
Copy link
Member

Choose a reason for hiding this comment

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

Preexisting, but does it make sense to vacuum all the time? If only a single media has been removed, it's probably not worth it — especially as vacuuming requires doubling the size of the database on disk, since it creates a copy of the database while it does it. Unfortunately that means heuristics to decide when to trigger, then, and maybe over a certain number of files / total size on disk, that would be profitable and simple enough to trigger often?

Comment on lines 25 to 26
#[cfg(not(test))]
use tracing::warn;
Copy link
Member

Choose a reason for hiding this comment

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

I'd use tracing::warn! at the single place where it's used instead, to not avoid a conditional use statement (which I personally find ugly).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines 152 to 153
// We want to know if there is an error with this step during tests.
#[cfg(test)]
Copy link
Member

Choose a reason for hiding this comment

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

Can we enable it if we've compiled in debug mode too? (that is, with #[cfg(debug_assertions)] too)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file.

- Implement the new method of `EventCacheStoreMedia` for `SqliteEventCacheStore`.
([#4603](https://github.com/matrix-org/matrix-rust-sdk/pull/4603))
- Defragment the state store after removing a room.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Defragment the state store after removing a room.
- Defragment an sqlite state store after removing a room.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: Kévin Commaille <[email protected]>
Signed-off-by: Kévin Commaille <[email protected]>
@bnjbvr bnjbvr enabled auto-merge (squash) February 11, 2025 14:07
@bnjbvr bnjbvr merged commit 65ee18a into matrix-org:main Feb 11, 2025
40 checks passed
@zecakeh zecakeh deleted the vaccum-forget-room branch February 11, 2025 14:18
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