Repository navigation
refactor(database): share Schema.Create mutex across callers - #1195
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
654fe0b to
6ebe384
Compare
adeb330 to
c45bf81
Compare
6ebe384 to
d51f567
Compare
c45bf81 to
2192f36
Compare
e2c4993 to
f92d4a6
Compare
Ent's migrate.Tables is a package-level slice that Atlas's setupTables mutates during Schema.Create. Anyone in the process calling Schema.Create concurrently with a different mutex would race on that slice, and the race detector would catch it the moment a second caller is added. Until now there was a single caller (pkg/database/migrate's fresh-install path) plus an unrelated test helper in pkg/database that used its own private sync.Mutex. They didn't contend because the second never ran in the same test binary as the first. The upcoming testhelper.CreateMigrateDatabase rewrite (next commit) will add a third caller, at which point the two mutexes would no longer be enough. This commit consolidates them by lifting the mutex into pkg/database as the exported `SchemaCreateMu`. Every code path that calls Schema.Create acquires it. The lifted mutex lives next to `Client` because both relate to Ent client lifecycle and pkg/database is the natural home; pkg/database/migrate already imports pkg/database so the dependency direction stays clean. No behaviour change beyond the test-time race elimination.
2192f36 to
6e3a419
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR consolidates Ent schema creation concurrency control by introducing an exported process-wide ChangesEnt schema creation concurrency consolidation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1195 +/- ##
=====================================
Coverage 4.94% 4.94%
=====================================
Files 6 6
Lines 445 445
=====================================
Hits 22 22
Misses 419 419
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Ent's migrate.Tables is a package-level slice that Atlas's
setupTables mutates during Schema.Create. Anyone in the process
calling Schema.Create concurrently with a different mutex would
race on that slice, and the race detector would catch it the
moment a second caller is added.
Until now there was a single caller (pkg/database/migrate's
fresh-install path) plus an unrelated test helper in
pkg/database that used its own private sync.Mutex. They didn't
contend because the second never ran in the same test binary
as the first. The upcoming testhelper.CreateMigrateDatabase
rewrite (next commit) will add a third caller, at which point
the two mutexes would no longer be enough.
This commit consolidates them by lifting the mutex into
pkg/database as the exported
SchemaCreateMu. Every code paththat calls Schema.Create acquires it. The lifted mutex lives
next to
Clientbecause both relate to Ent client lifecycleand pkg/database is the natural home; pkg/database/migrate
already imports pkg/database so the dependency direction stays
clean.
No behaviour change beyond the test-time race elimination.