Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement database locking for migrations #33731

Open
Tracked by #19587
AndriySvyryd opened this issue May 16, 2024 · 2 comments
Open
Tracked by #19587

Implement database locking for migrations #33731

AndriySvyryd opened this issue May 16, 2024 · 2 comments

Comments

@AndriySvyryd
Copy link
Member

AndriySvyryd commented May 16, 2024

Generally speaking, concurrent invocations of Migrate() will fail and possibly leave the database in a corrupted state. In order to mitigate this, we could create a temporary table using HistoryRepository that will serve as a lock while the migrations are applied by the process that acquired it. Providers will be able to override all related logic to instead leverage database-specific mechanisms to accomplish this.

@roji
Copy link
Member

roji commented May 16, 2024

That's a good idea - databases do frequently expose locking mechanisms that could work well, e.g. full-table exclusive lock on the HistoryRepository table for PG and SQL Server. Though I'm not sure what a default implementation would look like here - what do you have in mind with the temporary table?

@AndriySvyryd
Copy link
Member Author

what do you have in mind with the temporary table?

Before applying migrations create __EFLock table. If it was created successfully - the lock was acquired. If not, enter the normal retry loop.
After migrations and seeding (#17568) finished applying delete __EFLock table.

@AndriySvyryd AndriySvyryd added this to the Backlog milestone May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants