Skip to content

Conversation

@FGasper
Copy link
Collaborator

@FGasper FGasper commented Nov 28, 2024

This entails a fair bit of moving & renaming code, but the actual logic added is fairly simple:

  • BuildInfo is now ClusterInfo, and it indicates the cluster topology.
  • The index-checker’s logic to ignore numeric type differences is refactored & reused.
  • The logic to fetch shard keys is separated from its existing use for synthesizing a document key.
  • Topology-fetching logic is moved from the integration suite to util.

Small fixes:

  • The progress report’s collection metadata table, which included an extra “type” header and thus always looked mismatched.
  • getIndexesMap() now correctly checks for error before checking for an index name.

@FGasper FGasper marked this pull request as draft November 28, 2024 17:31
@FGasper FGasper requested a review from tdq45gj December 3, 2024 16:00
@FGasper FGasper marked this pull request as ready for review December 3, 2024 16:00
Copy link
Collaborator

@tdq45gj tdq45gj left a 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,
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Database(configDBName).
Collection(collsCollName)

rawResult, err := configCollectionsColl.FindOne(ctx, bson.D{{"_id", namespace}}).Raw()
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Collaborator Author

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,
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Comment on lines +14 to +15
// ServerThinksTheseMatch runs an aggregation on the server that determines
// whether the server thinks a & b are equal. This allows you, e.g., to
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@FGasper FGasper requested a review from tdq45gj December 3, 2024 19:24
Copy link
Collaborator

@tdq45gj tdq45gj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@FGasper FGasper merged commit 8992698 into mongodb-labs:main Dec 3, 2024
49 checks passed
@FGasper FGasper deleted the REP-5328-shard-keys-metadata branch December 3, 2024 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants