-
Notifications
You must be signed in to change notification settings - Fork 16
REP-5328 Compare shard keys as part of metadata verification. #63
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
REP-5328 Compare shard keys as part of metadata verification. #63
Conversation
tdq45gj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good in general. I wonder if ServerThinksTheseMatch should be a method on verifier and always use the meta client.
| // pipeline (`a` and `b`, respectively) before they're compared. | ||
| func ServerThinksTheseMatch( | ||
| ctx context.Context, | ||
| client *mongo.Client, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we want to restrict this function to only run on the meta cluster. Can we make it a method of the verifier and make sure that the query only runs on the meta cluster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think it’s better as a static function so that there’s better separation of concerns. The more things we “hang” on Verifier, the less modular it all is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment that to the function that explains it expects the client to only be the meta client for most of the cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
internal/util/sharding.go
Outdated
| Database(configDBName). | ||
| Collection(collsCollName) | ||
|
|
||
| rawResult, err := configCollectionsColl.FindOne(ctx, bson.D{{"_id", namespace}}).Raw() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we define a struct to consume the sharding config doc? I think it will make the code more straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| cursor, err := configCollectionsColl.Find(ctx, bson.D{{"uuid", uuid}}) | ||
| func (verifier *Verifier) getShardKeyFields( | ||
| ctx context.Context, | ||
| namespaceAndUUID *uuidutil.NamespaceAndUUID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this parameter ever be nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely not, but this is just reformatted code.
| // ServerThinksTheseMatch runs an aggregation on the server that determines | ||
| // whether the server thinks a & b are equal. This allows you, e.g., to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is not very accurate. It has a shortcut that compares the values in memory first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s an implementation, though. It seems trivially true that two binary-equivalent BSON values are ones that the server would also consider equivalent.
tdq45gj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
This entails a fair bit of moving & renaming code, but the actual logic added is fairly simple:
util.Small fixes:
getIndexesMap()now correctly checks for error before checking for an index name.