Skip to content

Add new package with methods to save and load compressor state #63

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

Merged

Conversation

Azrenbeth
Copy link
Contributor

@Azrenbeth Azrenbeth commented Sep 14, 2021

Builds on #62

Azrenbeth added 5 commits September 14, 2021 10:17
This enables other packages to use the compressor without jemalloc
Also allow groups_to_compress to be used if min_state_group is None
(previously had to set it to something like -1 which was ugly)
let sql = r#"
SELECT level_num, max_size, current_length, current_head, last_compressed
FROM state_compressor_state as s
LEFT JOIN state_compressor_progress as p ON s.room_id = p.room_id
Copy link
Member

Choose a reason for hiding this comment

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

This LEFT JOIN means that we don't necessarily have an entry in state_compressor_progress, and so last_compressed could be null, which I don't think we're expecting?

Copy link
Contributor Author

@Azrenbeth Azrenbeth Sep 15, 2021

Choose a reason for hiding this comment

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

Well you don't want to be able to restart the compressor if progress is NULL and level state is non-empty, but neither do you want to start the compressor from scratch (which would happen if we put a JOIN here)

Consider the following scenario:
1: compressor is run on a room with default level sizes of 100,50,25
2: that room's entry in state_compressor_progress is deleted by accident
3: compressor is run on that same room with default level sizes of 100,50 (i.e. just two levels)

When we save the compressor state, we don't overwrite the contents of the level 3 (the one with max size 25) so when the compressor loads state from the database on the next run it will load that third level with corrupted data in.

I've now added a bail! so it spots this!

Azrenbeth added 2 commits September 15, 2021 11:56
- Use PRIMARY KEY rather than UNIQUE()
- Use USING for join rather than AS xyz ON
- Remove unneccessary ::< on get()
- Use column names rather than indices on get()
- Add comments about usize <-> i32 conversion
- Use INSERT ON ... CONFLICT ... DO UPDATE SET
  rather than DELETE ... INSERT
- Use TRUNCATE rather than DELETE FROM to clear tables
@Azrenbeth Azrenbeth merged commit a9bc800 into matrix-org:main Sep 16, 2021
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