Fix attachment size calculation #5347
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, we included attachment sizes in the active size totals even if the attachments were deleted from the doc revision leafs.
The fix is, unsurprisingly, to do what the compactor does when it copies and updates sizes: only update sizes for leaf revision during the rev-tree traversal. We did this for doc bodies already in #4264, but forgot to consider attachments then.
In general we're aiming for the active size to approximate the size of the file after compaction. That is what drives smoosh (autocompaction) priority. If we don't remove non-leaf attachments from the calculation, the active/file ratio in smoosh may never trigger properly as ratio will stay low for shards with large attachments.
Until a release goes out with this fix, a workaround could be to compact shards with large attachments by hand, or use a lower threshold on
slack_dbschannel (and concurrency=1 to keep it in the background) to slowly cycle through all the shards and try to compact them.While the fix itself is small, to convince ourselves we did the right thing update the tests to check a few corner cases.
Interestingly enough we had a disabled Elixir compaction test which we disabled because it was "mysteriously" not reporting a lower "active" size after compacting. So re-enable it and also improve it a bit to have both a attachment that gets deleted and one that stays live.
Fix #5346