electric icon indicating copy to clipboard operation
electric copied to clipboard

Sync publication state to active shapes on load

Open magnetised opened this issue 9 months ago • 0 comments

Fixes #1719 - I think.

Don't know if we've made other changes to the replication system since after 1719 but things seem robust against a storage reset.

This pr does fix the synchronization of the publication state to the active shape state, so if electric loses its persistent storage between restarts it will reset the publication state (tables plus filter clauses). Previously the shapes that were active are not restored on restart the outdated publication state would persist. To do this I've made the initial sync call to the publication manager synchronous

  1. start electric
  2. create shape
  3. stop electric
  4. write data to shape
  5. delete the persistent state
  6. start electric

on restart:

  1. replication client receives pending transactions from old shape table but discards them because there are no active consumers
  2. old shape table is removed from the publication
  3. replication proceeds as for a new/blank electric

1 and 2 could happen in any order but the end result is the same. Nothing builds up in the replication slot as the replication client is active all the time.

I'm not doing any special checks for ownership because we're not doing anything that electric wouldn't normally do to the publication that it assumes it owns according to it's configuration.

magnetised avatar Apr 15 '25 16:04 magnetised