scenic
scenic copied to clipboard
Add side_by_side mode to update_materialized_view
This adds a side_by_side
kwarg to the update_materialized_view
method, which builds the new view alongside the old one and then atomically swaps them to reduce downtime at the cost of increasing disk usage. It is plumbed through to migrations as a hash value for the materialized
kwarg of update_view
.
Fixes scenic-views/scenic#386.
it's somewhat maddening that this repository doesn't have a working rubocop.yml
(what is in there is a many-years-old version of rubocop and seems to disagree with how hound is configured).
We also implemented something similar in a project using Scenic, but we had some issues with the indexes of the view you are replacing: you should drop them in the current view before adding the swap one, otherwise when you rename the view you'll have conflicts in the naming.
Ah, good point. I could probably modify this to rename all the indices, too…
Actually, this won't cause conflicts because the indexes on the new view get created after the swap, and the drop at the end of the swap removes the conflicting indexes.
That being said, building the indexes after the drop means that the indexes are built while holding the access exclusive lock, which probably is not a good idea.
@calebhearth @derekprior Gentle ping on this, do you need anything else for this PR to be merged?
This would really help some Mastodon materialized view changes :)
Any changes you'd like me to make to this?
Just adding another nudge here
Anything you'd like me to do to help move this forward?
Rebasing this after https://github.com/scenic-views/scenic/pull/397 will likely get rid of hound noise in this PR.