diff options
author | Tim Fogarty <tim.fogarty@mongodb.com> | 2020-01-09 12:33:19 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-01-09 12:33:19 +0000 |
commit | 3bf7c49d0450c012e8de4a321d7934a57692dd17 (patch) | |
tree | 79ff065767243e87b79ee28559bec3049dd95b76 | |
parent | 0b795201752949b87c380eaffc86fc4006e2adf1 (diff) | |
download | mongo-3bf7c49d0450c012e8de4a321d7934a57692dd17.tar.gz |
Import tools: a7ddcd8fc366b071f3fa359d277677812cc5c2ce from branch v3.6
ref: 6e50072775..a7ddcd8fc3
for: 3.6.17
TOOLS-2332 oplog_replay_local_rs.js fails on server latest
TOOLS-2422 admin.tempusers is not dropped by mongorestore
TOOLS-2423 mongorestore does not drop admin.tempusers if it exists in the dump
4 files changed, 111 insertions, 7 deletions
diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/import.data b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/import.data index 83481d6ad28..b1d2933e3e1 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/import.data +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/import.data @@ -1,5 +1,5 @@ { - "commit": "6e5007277595f7b79ff08944d22dd1ec12320cb4", + "commit": "a7ddcd8fc366b071f3fa359d277677812cc5c2ce", "github": "mongodb/mongo-tools.git", "vendor": "tools", "branch": "v3.6" diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/metadata.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/metadata.go index 12d99d858c0..c9f970e2da6 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/metadata.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/metadata.go @@ -179,6 +179,15 @@ func (restore *MongoRestore) CollectionExists(intent *intents.Intent) (bool, err return exists, nil } +// addToKnownCollections will add a collection to the restore.knownCollections cache. +// This is used to update the cache after a collection has been created during a restore. +func (restore *MongoRestore) addToKnownCollections(intent *intents.Intent) { + restore.knownCollectionsMutex.Lock() + defer restore.knownCollectionsMutex.Unlock() + + restore.knownCollections[intent.DB] = append(restore.knownCollections[intent.DB], intent.C) +} + // CreateIndexes takes in an intent and an array of index documents and // attempts to create them using the createIndexes command. If that command // fails, we fall back to individual index creation. @@ -357,20 +366,20 @@ func (restore *MongoRestore) RestoreUsersOrRoles(users, roles *intents.Intent) e } // make sure we always drop the temporary collection - defer func() { + defer func(cleanupArg loopArg) { session, e := restore.SessionProvider.GetSession() if e != nil { // logging errors here because this has no way of returning that doesn't mask other errors - log.Logvf(log.Info, "error establishing connection to drop temporary collection admin.%v: %v", arg.tempCollectionName, e) + log.Logvf(log.Info, "error establishing connection to drop temporary collection admin.%v: %v", cleanupArg.tempCollectionName, e) return } defer session.Close() - log.Logvf(log.DebugHigh, "dropping temporary collection admin.%v", arg.tempCollectionName) - e = session.DB("admin").C(arg.tempCollectionName).DropCollection() + log.Logvf(log.DebugHigh, "dropping temporary collection admin.%v", cleanupArg.tempCollectionName) + e = session.DB("admin").C(cleanupArg.tempCollectionName).DropCollection() if e != nil { - log.Logvf(log.Info, "error dropping temporary collection admin.%v: %v", arg.tempCollectionName, e) + log.Logvf(log.Info, "error dropping temporary collection admin.%v: %v", cleanupArg.tempCollectionName, e) } - }() + }(arg) userTargetDB = arg.intent.DB } diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/mongorestore_test.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/mongorestore_test.go index 37a6cd1e8d7..f6b71999c30 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/mongorestore_test.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/mongorestore_test.go @@ -87,3 +87,97 @@ func TestMongorestore(t *testing.T) { }) } + +func TestRestoreUsersOrRoles(t *testing.T) { + testtype.VerifyTestType(t, testtype.IntegrationTestType) + + nsOptions := &NSOptions{} + provider, toolOpts, err := testutil.GetBareSessionProvider() + if err != nil { + log.Logvf(log.Always, "error connecting to host: %v", err) + os.Exit(util.ExitError) + } + + Convey("With a test MongoRestore", t, func() { + inputOptions := &InputOptions{} + outputOptions := &OutputOptions{ + NumParallelCollections: 1, + NumInsertionWorkers: 1, + TempUsersColl: "tempusers", + TempRolesColl: "temproles", + } + restore := MongoRestore{ + ToolOptions: toolOpts, + OutputOptions: outputOptions, + InputOptions: inputOptions, + NSOptions: nsOptions, + SessionProvider: provider, + } + session, _ := provider.GetSession() + defer session.Close() + + db := session.DB("admin") + + Convey("Restoring users and roles should drop tempusers and temproles", func() { + restore.TargetDirectory = "testdata/usersdump" + err := restore.Restore() + So(err, ShouldBeNil) + + adminCollections, err := db.CollectionNames() + So(err, ShouldBeNil) + + for _, collName := range adminCollections { + So(collName, ShouldNotEqual, "tempusers") + So(collName, ShouldNotEqual, "temproles") + } + }) + }) +} + +func TestKnownCollections(t *testing.T) { + testtype.VerifyTestType(t, testtype.IntegrationTestType) + + Convey("With a test MongoRestore", t, func() { + inputOptions := &InputOptions{} + outputOptions := &OutputOptions{ + NumParallelCollections: 1, + NumInsertionWorkers: 1, + } + nsOptions := &NSOptions{} + provider, toolOpts, err := testutil.GetBareSessionProvider() + if err != nil { + log.Logvf(log.Always, "error connecting to host: %v", err) + os.Exit(util.ExitError) + } + restore := MongoRestore{ + ToolOptions: toolOpts, + OutputOptions: outputOptions, + InputOptions: inputOptions, + NSOptions: nsOptions, + SessionProvider: provider, + } + session, _ := provider.GetSession() + defer session.Close() + + db := session.DB("test") + defer func() { + db.C("foo").DropCollection() + }() + + Convey("Once collection foo has been restored, it should exist in restore.knownCollections", func() { + restore.TargetDirectory = "testdata/foodump" + err := restore.Restore() + So(err, ShouldBeNil) + + var namespaceExistsInCache bool + if cols, ok := restore.knownCollections["test"]; ok { + for _, collName := range cols { + if collName == "foo" { + namespaceExistsInCache = true + } + } + } + So(namespaceExistsInCache, ShouldBeTrue) + }) + }) +} diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/restore.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/restore.go index fda9c16f9a0..e9b1ee1e405 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/restore.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/mongorestore/restore.go @@ -184,6 +184,7 @@ func (restore *MongoRestore) RestoreIntent(intent *intents.Intent) error { if err != nil { return fmt.Errorf("error creating collection %v: %v", intent.Namespace(), err) } + restore.addToKnownCollections(intent) } else { log.Logvf(log.Info, "collection %v already exists - skipping collection create", intent.Namespace()) } |