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

Closed
Tracked by #19587
AndriySvyryd opened this issue May 16, 2024 · 3 comments · Fixed by #34115
Closed
Tracked by #19587

Implement database locking for migrations #33731

AndriySvyryd opened this issue May 16, 2024 · 3 comments · Fixed by #34115
Labels
area-aspire area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement

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
@AndriySvyryd AndriySvyryd modified the milestones: Backlog, 9.0.0 Jun 20, 2024
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 28, 2024
@AndriySvyryd AndriySvyryd removed their assignment Jun 28, 2024
AndriySvyryd added a commit that referenced this issue Jul 9, 2024
@roji
Copy link
Member

roji commented Jul 12, 2024

PG tracking issue: npgsql/efcore.pg#3223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-aspire area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants