-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Schema deltas are no longer transactional on sqlite #14909
Comments
It looks like this may have been introduced by #13873, which replaced the old handrolled code for parsing sql files with something more conventional. That was probably a good idea, but it does break the transactional semantics we were relying on for our migrations... Originally posted by @richvdh in #14401 (comment) |
Sorry, that's my mistake. FWIW the old parser still exists, see e.g. synapse/synapse/storage/prepare_database.py Line 609 in 0a38c7e
The only other option would be to inject an explicit (I recall that when I was making the full schema dumps that parser couldn't handle something postgres-specific. Trigger definitions maybe?) Originally posted by @DMRobertson in #14401 (comment) |
It's not, but I think it would have the right semantics, and would avoid us maintaining our own SQL parser, with all the pitfalls that brings. Originally posted by @richvdh in #14401 (comment) |
#13873 introduced a regression which causes sqlite database migrations to no longer run inside a transaction. Wrap them in a transaction again, to avoid database corruption when migrations are interrupted. Fixes #14909. Signed-off-by: Sean Quah <[email protected]>
#13873 introduced a regression which causes sqlite database migrations to no longer run inside a transaction. Wrap them in a transaction again, to avoid database corruption when migrations are interrupted. Fixes #14909. Signed-off-by: Sean Quah <[email protected]>
@DMRobertson points out here that there is a small window in between the schema delta being committed and Synapse updating its bookkeeping which is still non-transactional. We need to leave the transaction open in |
#14910 fixed the regression introduced by #13873 where sqlite database migrataions would no longer run inside a transaction. However, it committed the transaction before Synapse updated its bookkeeping of which migrations have been run, which means that migrations may be run again after they have completed successfully. Leave the transaction open at the end of `executescript`, to restore the old, correct behaviour. Fixes #14909. Signed-off-by: Sean Quah <[email protected]>
#14910 fixed the regression introduced by #13873 where sqlite database migrataions would no longer run inside a transaction. However, it committed the transaction before Synapse updated its bookkeeping of which migrations have been run, which means that migrations may be run again after they have completed successfully. Leave the transaction open at the end of `executescript`, to restore the old, correct behaviour. Fixes #14909. Signed-off-by: Sean Quah <[email protected]>
#14910 fixed the regression introduced by #13873 where sqlite database migrations would no longer run inside a transaction. However, it committed the transaction before Synapse updated its bookkeeping of which migrations have been run, which means that migrations may be run again after they have completed successfully. Leave the transaction open at the end of `executescript`, to restore the old, correct behaviour. Also make the PostgreSQL behaviour consistent with SQLite. Fixes #14909. Signed-off-by: Sean Quah <[email protected]>
#13873 may have introduced a regression where schema deltas are no longer executed inside a transaction on sqlite. This can lead to database inconsistencies and bootloops when Synapse is killed while running database migrations.
Examples:
sqlite3.OperationalError: table background_updates already exists
on startup #14460Previously: #6467.
Split out from #14401.
The text was updated successfully, but these errors were encountered: