Plan icon indicating copy to clipboard operation
Plan copied to clipboard

Prevent multiple servers from patching database schema at the same time

Open AuroraLS3 opened this issue 3 years ago • 1 comments

Describe the issue

When networks update, a schema update patch may cause issues in the plugin startup as all servers attempt to do the patch at the same time.

It would be beneficial to check if any server is already patching the schema before doing patches.

AuroraLS3 avatar Feb 13 '22 07:02 AuroraLS3

It is complicated to do this in a way that prevents other servers from hanging while waiting for the patch checks to complete. The patch system should be modified to check if patching is necessary in the first place before attempting lock.

TODO

  • [ ] Modify patch system to first run a 'is patching necessary' step and then attempt patching if necessary.
  • [ ] Add a plan_patching_status table with two columns
    • One that has UNIQUE constraint. All servers should attempt to insert same value to the table.
    • One that has the timestamp patching started in case server crashes while patching
    • One that has the server id of the server that is patching, so that any server restarting knows to ignore the timestamp.
  • [ ] Add a 'Is database patching' check
  • [ ] Add logic to block all transactions until 'Is database patching' is false again
  • [ ] Add transaction that attempts to lock the schema, but if it fails due to the unique constraint moves back to previous step
  • [ ] Add transaction that unlocks the schema
  • [ ] Attempt to run the unlock transaction even if database fails to patch to prevent unnecessary schema locking.

AuroraLS3 avatar May 09 '22 16:05 AuroraLS3