-
Notifications
You must be signed in to change notification settings - Fork 354
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
Conversation
mongorestore/options.go
Outdated
TempRolesCollOption = "--tempRolesColl" | ||
BulkBufferSizeOption = "--batchSize" | ||
FixDottedHashedIndexesOption = "--fixDottedHashIndex" | ||
FixDuplicatedLegacyIndexesOption = "--fixDuplicatedLegacyIndexes" |
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 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
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 may remember incorrectly, @tfogo Do you remember if we would need a flag or not?
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 think we agreed on not having a flag but adding a note to the documentation.
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.
ah, cool. I will remove the flag then. Thanks!
mongorestore/restore.go
Outdated
@@ -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 |
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.
small nit, but the go idiom is to use map[string]struct{}
for sets
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.
Good idea!
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
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.
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 |
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 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.
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.
Make sense, added the log
mongorestore/mongorestore_test.go
Outdated
restore, err := getRestoreWithArgs(args...) | ||
So(err, ShouldBeNil) | ||
|
||
Convey("Creating index with invalid option and --convertLegacyIndexes should succeed", func() { |
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 description should be updated.
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.
Good catch. fixed!
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!
…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.