Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport concurrent migrations in MongoDB #283
Open
Conversation
… mess up the configuration collection.
return &database.Error{OrigErr: err, Err: "save version failed"} | ||
filt := bson.D{{"version", bson.D{{"$exists", true}}}} | ||
upd := bson.D{{"$set", bson.D{ | ||
{"version", int32(version)}, |
This comment has been minimized.
This comment has been minimized.
{"dirty", dirty}, | ||
}}} | ||
var tr = true | ||
if res := migrationsCollection.FindOneAndUpdate(context.TODO(), filt, upd, &options.FindOneAndUpdateOptions{Upsert: &tr}); res.Err() != nil { |
This comment has been minimized.
This comment has been minimized.
dhui
Sep 9, 2019
Member
You'll probably run into fewer races with FindOneAndUpdate()
+ Upsert: true
than Drop()
+ InsertOne()
, but this change won't actually make it safe to run migrations concurrently. e.g. it doesn't serialize/coordinate changes
To run safely concurrently, you'll need to use transactions. This isn't a blocker for merging this PR, but as is, the release notes would only state that a race condition is less likely to happen.
Also, tests (linter) are failing:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
mrqzzz commentedSep 5, 2019
SetVersion in mongodb.go is now atomical.
Concurrent migrations don't mess up the configuration collection.