diff options
author | Wisdom Omuya <deafgoat@gmail.com> | 2014-11-13 16:12:23 -0500 |
---|---|---|
committer | Wisdom Omuya <deafgoat@gmail.com> | 2014-11-14 16:01:47 -0500 |
commit | 25f2cee81e012e47c005befde15a29e3d2efcb66 (patch) | |
tree | 1294671fa91bbeb16885965e37c690ddcbd92f4b | |
parent | eb70dc3eb2c6683280cd0dc773c87229774cb6b7 (diff) | |
download | mongo-25f2cee81e012e47c005befde15a29e3d2efcb66.tar.gz |
TOOLS-327: replace --w with --writeConcern
Former-commit-id: 718c69adfae21aa80e7a340fc7864355a3f4e2e8
-rw-r--r-- | common/util/write_concern.go | 3 | ||||
-rw-r--r-- | common/util/write_concern_test.go | 7 | ||||
-rw-r--r-- | legacy/jstests/tool/dumprestore10.js | 2 | ||||
-rw-r--r-- | legacy/jstests/tool/dumprestore_auth.js | 8 | ||||
-rw-r--r-- | legacy/jstests/tool/dumprestore_auth2.js | 4 | ||||
-rw-r--r-- | legacy/jstests/tool/dumprestore_auth3.js | 12 | ||||
-rw-r--r-- | legacy26/jstests/tool/dumprestore10.js | 2 | ||||
-rw-r--r-- | legacy26/jstests/tool/dumprestore_auth.js | 4 | ||||
-rw-r--r-- | legacy26/jstests/tool/dumprestore_auth2.js | 4 | ||||
-rw-r--r-- | legacy26/jstests/tool/dumprestore_auth3.js | 12 | ||||
-rw-r--r-- | mongoimport/mongoimport.go | 4 | ||||
-rw-r--r-- | mongoimport/options/options.go | 2 | ||||
-rw-r--r-- | mongorestore/options/options.go | 2 |
13 files changed, 37 insertions, 29 deletions
diff --git a/common/util/write_concern.go b/common/util/write_concern.go index 375caeaa4d0..5c0163f6303 100644 --- a/common/util/write_concern.go +++ b/common/util/write_concern.go @@ -5,6 +5,7 @@ import ( "github.com/mongodb/mongo-tools/common/json" "github.com/mongodb/mongo-tools/common/log" "gopkg.in/mgo.v2" + "strconv" ) // write concern fields @@ -36,7 +37,7 @@ func constructWCObject(writeConcern string) (sessionSafety *mgo.Safe, err error) // allows a default to the old behavior wherein the entire argument // passed in is assigned to the 'w' field - thus allowing users pass // a write concern that looks like: "majority", 0, "4", etc. - wValue, err := ToInt(writeConcern) + wValue, err := strconv.Atoi(writeConcern) if err != nil { sessionSafety.WMode = writeConcern } else { diff --git a/common/util/write_concern_test.go b/common/util/write_concern_test.go index 5d1fe9411da..ec9a8e78612 100644 --- a/common/util/write_concern_test.go +++ b/common/util/write_concern_test.go @@ -15,6 +15,9 @@ func TestBuildWriteConcern(t *testing.T) { writeConcern, err = BuildWriteConcern(`{w:"majority"}`, true) So(err, ShouldBeNil) So(writeConcern.WMode, ShouldEqual, "majority") + writeConcern, err = BuildWriteConcern(`majority`, true) + So(err, ShouldBeNil) + So(writeConcern.WMode, ShouldEqual, "majority") writeConcern, err = BuildWriteConcern(`tagset`, true) So(err, ShouldBeNil) So(writeConcern.WMode, ShouldEqual, "tagset") @@ -148,6 +151,10 @@ func TestConstructWCObject(t *testing.T) { writeConcern, err = constructWCObject(writeConcernString) So(err, ShouldBeNil) So(writeConcern, ShouldBeNil) + writeConcernString = `0` + writeConcern, err = constructWCObject(writeConcernString) + So(err, ShouldBeNil) + So(writeConcern, ShouldBeNil) }) }) } diff --git a/legacy/jstests/tool/dumprestore10.js b/legacy/jstests/tool/dumprestore10.js index 4d18ee76f23..b4f029fdefa 100644 --- a/legacy/jstests/tool/dumprestore10.js +++ b/legacy/jstests/tool/dumprestore10.js @@ -49,7 +49,7 @@ runMongoProgram( "mongodump", "--host", "127.0.0.1:"+replTest.ports[0], "--out", step("try mongorestore with write concern"); -runMongoProgram( "mongorestore", "--w", "2", "--host", "127.0.0.1:"+replTest.ports[0], "--dir", data ); +runMongoProgram( "mongorestore", "--writeConcern", "2", "--host", "127.0.0.1:"+replTest.ports[0], "--dir", data ); var x = 0; diff --git a/legacy/jstests/tool/dumprestore_auth.js b/legacy/jstests/tool/dumprestore_auth.js index 2a3c8137ecd..a2de1f983f5 100644 --- a/legacy/jstests/tool/dumprestore_auth.js +++ b/legacy/jstests/tool/dumprestore_auth.js @@ -62,11 +62,11 @@ c.drop(); assert.eq(0 , c.count() , "after drop"); // Restore should fail without user & pass -t.runTool("restore" , "--dir" , t.ext, "--w" ,"0"); +t.runTool("restore" , "--dir" , t.ext, "--writeConcern" ,"0"); assert.eq(0 , c.count() , "after restore without auth"); // Restore should pass with authorized user -t.runTool("restore" , "--dir" , t.ext, "--username", "restore", "--password", "password", "--w", "0"); +t.runTool("restore" , "--dir" , t.ext, "--username", "restore", "--password", "password", "--writeConcern", "0"); assert.soon("c.findOne()" , "no data after sleep"); assert.eq(1 , c.count() , "after restore 2"); assert.eq(22 , c.findOne().a , "after restore 2"); @@ -83,12 +83,12 @@ assert.eq(0 , c.count() , "after drop"); // Restore with wrong user t.runTool("restore" , "--username", "restoreChester", "--password", "password", - "--db", dbName, "--collection", "foo", t.ext+dbName+"/foo.bson", "--w", "0"); + "--db", dbName, "--collection", "foo", t.ext+dbName+"/foo.bson", "--writeConcern", "0"); assert.eq(0 , c.count() , "after restore with wrong user"); // Restore with proper user t.runTool("restore" , "--username", "restoreFoo", "--password", "password", - "--db", dbName, "--collection", "foo", t.ext+dbName+"/foo.bson", "--w", "0"); + "--db", dbName, "--collection", "foo", t.ext+dbName+"/foo.bson", "--writeConcern", "0"); assert.soon("c.findOne()" , "no data after sleep"); assert.eq(1 , c.count() , "after restore 3"); assert.eq(22 , c.findOne().a , "after restore 3"); diff --git a/legacy/jstests/tool/dumprestore_auth2.js b/legacy/jstests/tool/dumprestore_auth2.js index 6fa6dfa402f..0392d1be3db 100644 --- a/legacy/jstests/tool/dumprestore_auth2.js +++ b/legacy/jstests/tool/dumprestore_auth2.js @@ -56,7 +56,7 @@ assert.eq(0, coll.count(), "didn't drop foo coll"); // This test depends on W=0 to mask unique index violations. // This should be fixed once we implement TOOLS-341 -t.runTool("restore", "--dir", t.ext, "--username", "restore", "--password", "pass", "--w", "0"); +t.runTool("restore", "--dir", t.ext, "--username", "restore", "--password", "pass", "--writeConcern", "0"); assert.soon("admindb.system.users.findOne()", "no data after restore"); assert.eq(4, admindb.system.users.count(), "didn't restore users"); @@ -80,7 +80,7 @@ admindb.createRole({role: "customRole2", roles: [], privileges:[]}); admindb.dropUser("root"); admindb.logout(); -t.runTool("restore", "--dir", t.ext, "--username", "restore", "--password", "pass", "--drop", "--w", "0"); +t.runTool("restore", "--dir", t.ext, "--username", "restore", "--password", "pass", "--drop", "--writeConcern", "0"); admindb.auth("root", "pass"); assert.soon("1 == admindb.system.users.find({user:'root'}).count()", "didn't restore users 2"); diff --git a/legacy/jstests/tool/dumprestore_auth3.js b/legacy/jstests/tool/dumprestore_auth3.js index 46b942b7045..f65bed7abff 100644 --- a/legacy/jstests/tool/dumprestore_auth3.js +++ b/legacy/jstests/tool/dumprestore_auth3.js @@ -58,7 +58,7 @@ db.dropAllRoles(); jsTestLog("Restore foo database from dump that doesn't contain user data "); // This test depends on W=0 to mask unique index violations. // This should be fixed once we implement TOOLS-341 -runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: "", w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: "", writeConcern: "0"}); db = mongod.getDB('foo'); @@ -90,7 +90,7 @@ assert.eq(0, db.getRoles().length, "didn't drop roles"); assert.eq(0, db.bar.count(), "didn't drop 'bar' collection"); jsTestLog("Restore foo database without restoring user data, even though it's in the dump"); -runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', writeConcern: "0"}); db = mongod.getDB('foo'); assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); @@ -99,7 +99,7 @@ assert.eq(0, db.getUsers().length, "Restored users even though it shouldn't have assert.eq(0, db.getRoles().length, "Restored roles even though it shouldn't have"); jsTestLog("Restore foo database *with* user data"); -runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: "", w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: "", writeConcern: "0"}); db = mongod.getDB('foo'); admindb = mongod.getDB('admin'); @@ -121,7 +121,7 @@ db.createRole({role: 'role2', roles: [], privileges:[]}); jsTestLog("Restore foo database (and user data) with --drop so it overrides the changes made"); // Restore with --drop to override the changes to user data runTool("mongorestore", mongod, - {dir: dumpDir + "foo/", db: 'foo', drop: "", restoreDbUsersAndRoles: "", w: "0"}); + {dir: dumpDir + "foo/", db: 'foo', drop: "", restoreDbUsersAndRoles: "", writeConcern: "0"}); db = mongod.getDB('foo'); admindb = mongod.getDB('admin'); @@ -152,7 +152,7 @@ db.getSiblingDB('bar').createUser({user: "user2", pwd: 'pwd', roles: []}); db.getSiblingDB('admin').dropAllUsers(); jsTestLog("Restore just the admin database. User data should be restored by default"); -runTool("mongorestore", mongod, {dir: dumpDir + "admin/", db: 'admin', drop: "", w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir + "admin/", db: 'admin', drop: "", writeConcern: "0"}); db = mongod.getDB('foo'); var otherdb = db.getSiblingDB('bar'); var admindb = db.getSiblingDB('admin'); @@ -186,7 +186,7 @@ assert.eq(0, db.getRoles().length, "didn't drop roles"); assert.eq(0, db.bar.count(), "didn't drop 'bar' collection"); jsTestLog("Restore all databases"); -runTool("mongorestore", mongod, {dir: dumpDir, w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir, writeConcern: "0"}); db = mongod.getDB('foo'); assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); diff --git a/legacy26/jstests/tool/dumprestore10.js b/legacy26/jstests/tool/dumprestore10.js index 72eff8ed154..f59b131bb05 100644 --- a/legacy26/jstests/tool/dumprestore10.js +++ b/legacy26/jstests/tool/dumprestore10.js @@ -48,7 +48,7 @@ runMongoProgram( "mongodump", "--host", "127.0.0.1:"+replTest.ports[0], "--out", step("try mongorestore with write concern"); -runMongoProgram( "mongorestore", "--w", "2", "--host", "127.0.0.1:"+replTest.ports[0], "--dir", data ); +runMongoProgram( "mongorestore", "--writeConcern", "2", "--host", "127.0.0.1:"+replTest.ports[0], "--dir", data ); var x = 0; diff --git a/legacy26/jstests/tool/dumprestore_auth.js b/legacy26/jstests/tool/dumprestore_auth.js index 96ce27c2707..f99b5d0405c 100644 --- a/legacy26/jstests/tool/dumprestore_auth.js +++ b/legacy26/jstests/tool/dumprestore_auth.js @@ -22,10 +22,10 @@ t.runTool("dump" , "--out" , t.ext, "--username", "backup", "--password", "passw c.drop(); assert.eq(0 , c.count() , "after drop"); -t.runTool("restore" , "--dir" , t.ext, "--w", "0"); // Should fail +t.runTool("restore" , "--dir" , t.ext, "--writeConcern", "0"); // Should fail assert.eq(0 , c.count() , "after restore without auth"); -t.runTool("restore" , "--dir" , t.ext, "--username", "restore", "--password", "password", "--w", "0"); +t.runTool("restore" , "--dir" , t.ext, "--username", "restore", "--password", "password", "--writeConcern", "0"); assert.soon("c.findOne()" , "no data after sleep"); assert.eq(1 , c.count() , "after restore 2"); assert.eq(22 , c.findOne().a , "after restore 2"); diff --git a/legacy26/jstests/tool/dumprestore_auth2.js b/legacy26/jstests/tool/dumprestore_auth2.js index 8e34c958ee3..fd7d9a034d3 100644 --- a/legacy26/jstests/tool/dumprestore_auth2.js +++ b/legacy26/jstests/tool/dumprestore_auth2.js @@ -54,7 +54,7 @@ assert.eq(2, admindb.system.users.count(), "didn't drop backup and test users"); assert.eq(0, admindb.system.roles.count(), "didn't drop roles"); assert.eq(0, coll.count(), "didn't drop foo coll"); -t.runTool("restore", "--dir", t.ext, "--username", "restore", "--password", "pass", "--w", "0"); +t.runTool("restore", "--dir", t.ext, "--username", "restore", "--password", "pass", "--writeConcern", "0"); assert.soon("admindb.system.users.findOne()", "no data after restore"); assert.eq(4, admindb.system.users.count(), "didn't restore users"); @@ -78,7 +78,7 @@ admindb.createRole({role: "customRole2", roles: [], privileges:[]}); admindb.dropUser("root"); admindb.logout(); -t.runTool("restore", "--dir", t.ext, "--username", "restore", "--password", "pass", "--drop", "--w", "0"); +t.runTool("restore", "--dir", t.ext, "--username", "restore", "--password", "pass", "--drop", "--writeConcern", "0"); admindb.auth("root", "pass"); assert.soon("1 == admindb.system.users.find({user:'root'}).count()", "didn't restore users 2"); diff --git a/legacy26/jstests/tool/dumprestore_auth3.js b/legacy26/jstests/tool/dumprestore_auth3.js index e21c4e08757..b87418ed176 100644 --- a/legacy26/jstests/tool/dumprestore_auth3.js +++ b/legacy26/jstests/tool/dumprestore_auth3.js @@ -57,7 +57,7 @@ db.dropAllUsers(); db.dropAllRoles(); jsTestLog("Restore foo database from dump that doesn't contain user data "); -runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: "", w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: "", writeConcern: "0"}); db = mongod.getDB('foo'); @@ -89,7 +89,7 @@ assert.eq(0, db.getRoles().length, "didn't drop roles"); assert.eq(0, db.bar.count(), "didn't drop 'bar' collection"); jsTestLog("Restore foo database without restoring user data, even though it's in the dump"); -runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', writeConcern: "0"}); db = mongod.getDB('foo'); assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); @@ -98,7 +98,7 @@ assert.eq(0, db.getUsers().length, "Restored users even though it shouldn't have assert.eq(0, db.getRoles().length, "Restored roles even though it shouldn't have"); jsTestLog("Restore foo database *with* user data"); -runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: "", w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: "", writeConcern: "0"}); db = mongod.getDB('foo'); admindb = mongod.getDB('admin'); @@ -120,7 +120,7 @@ db.createRole({role: 'role2', roles: [], privileges:[]}); jsTestLog("Restore foo database (and user data) with --drop so it overrides the changes made"); // Restore with --drop to override the changes to user data runTool("mongorestore", mongod, - {dir: dumpDir + "foo/", db: 'foo', drop: "", restoreDbUsersAndRoles: "", w: "0"}); + {dir: dumpDir + "foo/", db: 'foo', drop: "", restoreDbUsersAndRoles: "", writeConcern: "0"}); db = mongod.getDB('foo'); admindb = mongod.getDB('admin'); @@ -151,7 +151,7 @@ db.getSiblingDB('bar').createUser({user: "user2", pwd: 'pwd', roles: []}); db.getSiblingDB('admin').dropAllUsers(); jsTestLog("Restore just the admin database. User data should be restored by default"); -runTool("mongorestore", mongod, {dir: dumpDir + "admin/", db: 'admin', drop: "", w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir + "admin/", db: 'admin', drop: "", writeConcern: "0"}); db = mongod.getDB('foo'); var otherdb = db.getSiblingDB('bar'); var admindb = db.getSiblingDB('admin'); @@ -185,7 +185,7 @@ assert.eq(0, db.getRoles().length, "didn't drop roles"); assert.eq(0, db.bar.count(), "didn't drop 'bar' collection"); jsTestLog("Restore all databases"); -runTool("mongorestore", mongod, {dir: dumpDir, w: "0"}); +runTool("mongorestore", mongod, {dir: dumpDir, writeConcern: "0"}); db = mongod.getDB('foo'); assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); diff --git a/mongoimport/mongoimport.go b/mongoimport/mongoimport.go index 2fd81e53465..b3fd4b4ed66 100644 --- a/mongoimport/mongoimport.go +++ b/mongoimport/mongoimport.go @@ -544,8 +544,8 @@ func (mongoImport *MongoImport) ingester(documents []bson.Raw, collection *mgo.C // // Without write commands, we can't say for sure how many documents // were inserted when we use bulk inserts so we assume the entire batch - // succeeded - even if an error is returned. The result is that we may - // report that more documents - than were actually inserted - were + // insert failed if an error is returned. The result is that we may + // report that less documents - than were actually inserted - were // inserted into the database. This will change as soon as BulkResults // are supported by the driver if err == nil { diff --git a/mongoimport/options/options.go b/mongoimport/options/options.go index 4248accfb66..f8062c56937 100644 --- a/mongoimport/options/options.go +++ b/mongoimport/options/options.go @@ -71,7 +71,7 @@ type IngestOptions struct { // Specifies the write concern for each write operation that mongorestore writes to the target database. // By default, mongoimport waits for a majority of members from the replica set to respond before returning. - WriteConcern string `long:"w" default:"majority" description:"write concern options e.g. --w majority, --w '{w: 3, wtimeout: 500, fsync: true, j: true}'"` + WriteConcern string `long:"writeConcern" default:"majority" description:"write concern options e.g. --writeConcern majority, --writeConcern '{w: 3, wtimeout: 500, fsync: true, j: true}'"` } func (self *IngestOptions) Name() string { diff --git a/mongorestore/options/options.go b/mongorestore/options/options.go index 416f7f51d8b..5746727ab60 100644 --- a/mongorestore/options/options.go +++ b/mongorestore/options/options.go @@ -15,7 +15,7 @@ func (self *InputOptions) Name() string { type OutputOptions struct { Drop bool `long:"drop" description:"Drop each collection before import"` - WriteConcern string `long:"w" default:"majority" description:"Write concern options e.g. --w majority, --w '{w: 3, wtimeout: 500, fsync: true, j: true}'"` + WriteConcern string `long:"writeConcern" default:"majority" description:"Write concern options e.g. --writeConcern majority, --writeConcern '{w: 3, wtimeout: 500, fsync: true, j: true}'"` NoIndexRestore bool `long:"noIndexRestore" description:"Don't restore indexes"` NoOptionsRestore bool `long:"noOptionsRestore" description:"Don't restore options"` KeepIndexVersion bool `long:"keepIndexVersion" description:"Don't update index version"` |