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

TOOLS-2645: Check for duplicate index keys after converting legacy in… #282

Merged
merged 10 commits into from
Jul 28, 2020

Conversation

huan-Mongo
Copy link
Contributor

@huan-Mongo huan-Mongo commented Jul 22, 2020

…dex definitions
This PR depends on https://github.com/mongodb/mongo-tools-common/pull/45/files . I will revendor after the MTC PR gets merged.
Here I introduced flag fixDuplicatedLegacyIndexes. When enabled, after legacy indexes get converted, the indexes with duplicated index key will be skipped.

TempRolesCollOption = "--tempRolesColl"
BulkBufferSizeOption = "--batchSize"
FixDottedHashedIndexesOption = "--fixDottedHashIndex"
FixDuplicatedLegacyIndexesOption = "--fixDuplicatedLegacyIndexes"
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be recalling an outdated discussion, but I thought when we last discussed we were not going to add a new flag and instead make it part of the default --convertLegacyIndexes behavior

Copy link
Contributor Author

@huan-Mongo huan-Mongo Jul 23, 2020

Choose a reason for hiding this comment

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

I may remember incorrectly, @tfogo Do you remember if we would need a flag or not?

Copy link
Member

Choose a reason for hiding this comment

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

I think we agreed on not having a flag but adding a note to the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, cool. I will remove the flag then. Thanks!

@@ -306,17 +306,27 @@ func (restore *MongoRestore) RestoreIntent(intent *intents.Intent) Result {
return result
}

func (restore *MongoRestore) convertLegacyIndexes(indexes []IndexDocument, ns string) {
func (restore *MongoRestore) convertLegacyIndexes(indexes []IndexDocument, ns string) []IndexDocument {
indexKeys := make(map[string]bool) // A set contains all the unique index's json strings
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit, but the go idiom is to use map[string]struct{} for sets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

Copy link
Contributor

@rychipman rychipman left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@tfogo tfogo left a comment

Choose a reason for hiding this comment

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

Looking good, just a couple of small suggestions. LGTM once those are done.

indexString := bsonutil.CreateExtJSONString(index.Key)
if _, ok := indexKeys[indexString]; ok {
// skip duplicated indexes
continue
Copy link
Member

Choose a reason for hiding this comment

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

I think we want to log whenever we skip because we should notify the user that there won't be an index with that particular name in the destination. Might be important if the user is using the name as an index hint. We should also tell them what the name of the index that does exist is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense, added the log

restore, err := getRestoreWithArgs(args...)
So(err, ShouldBeNil)

Convey("Creating index with invalid option and --convertLegacyIndexes should succeed", func() {
Copy link
Member

Choose a reason for hiding this comment

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

This description should be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. fixed!

@huan-Mongo huan-Mongo requested a review from tfogo July 28, 2020 15:13
Copy link
Member

@tfogo tfogo left a comment

Choose a reason for hiding this comment

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

lgtm!

@huan-Mongo huan-Mongo merged commit 8ecb04b into mongodb:master Jul 28, 2020
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.

3 participants