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

Support concurrent migrations in MongoDB #283

Open
wants to merge 1 commit into
base: master
from

Conversation

@mrqzzz
Copy link

mrqzzz commented Sep 5, 2019

SetVersion in mongodb.go is now atomical.
Concurrent migrations don't mess up the configuration collection.

… 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.

@dhui

dhui Sep 9, 2019

Member

Why cast to an int32?

{"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.

@dhui

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.

Copy link
Member

dhui left a comment

Also, tests (linter) are failing:

database/mongodb/mongodb.go:101:17: composites: `go.mongodb.org/mongo-driver/bson/primitive.E` composite literal uses unkeyed fields (govet)

	filt := bson.D{{"version", bson.D{{"$exists", true}}}}
	               ^

database/mongodb/mongodb.go:102:16: composites: `go.mongodb.org/mongo-driver/bson/primitive.E` composite literal uses unkeyed fields (govet)

	upd := bson.D{{"$set", bson.D{
	              ^

database/mongodb/mongodb.go:103:3: composites: `go.mongodb.org/mongo-driver/bson/primitive.E` composite literal uses unkeyed fields (govet)

		{"version", int32(version)},
		^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.