scenic icon indicating copy to clipboard operation
scenic copied to clipboard

Add side_by_side mode to update_materialized_view

Open Roguelazer opened this issue 1 year ago • 9 comments

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.

Roguelazer avatar Apr 04 '23 23:04 Roguelazer

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).

Roguelazer avatar Apr 04 '23 23:04 Roguelazer

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.

ferblape avatar Apr 05 '23 05:04 ferblape

Ah, good point. I could probably modify this to rename all the indices, too…

Roguelazer avatar Apr 05 '23 05:04 Roguelazer

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.

Roguelazer avatar Apr 05 '23 15:04 Roguelazer

@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 :)

renchap avatar Jun 09 '23 15:06 renchap

Any changes you'd like me to make to this?

Roguelazer avatar Aug 04 '23 23:08 Roguelazer

Just adding another nudge here

gsinkin avatar Aug 23 '23 21:08 gsinkin

Anything you'd like me to do to help move this forward?

Roguelazer avatar Oct 18 '23 18:10 Roguelazer

Rebasing this after https://github.com/scenic-views/scenic/pull/397 will likely get rid of hound noise in this PR.

mjankowski avatar May 29 '24 20:05 mjankowski