Permalink
Browse files

SERVER-12786: add shell writeMode option

  • Loading branch information...
scotthernandez committed Feb 26, 2014
1 parent f4c7d40 commit a56653e1df978f68b887788b39d053e3f88bb0ea
@@ -5,6 +5,8 @@
var coll = db.getCollection( "batch_write_delete" );
coll.drop();
+assert(coll.getDB().getMongo().useWriteCommands(), "test is not running with write commands")
+
jsTest.log("Starting delete tests...");
var request;
@@ -5,6 +5,8 @@
var coll = db.getCollection( "batch_write_insert" );
coll.drop();
+assert(coll.getDB().getMongo().useWriteCommands(), "test is not running with write commands")
+
jsTest.log("Starting insert tests...");
var request;
@@ -5,6 +5,8 @@
var coll = db.getCollection( "batch_write_update" );
coll.drop();
+assert(coll.getDB().getMongo().useWriteCommands(), "test is not running with write commands")
+
jsTest.log("Starting update tests...");
var request;
@@ -2,11 +2,11 @@
// Ensures that the server respects the batch write command WriteConcern, and behaves correctly
//
-
-
var coll = db.getCollection( "batch_write_wc" );
coll.drop();
+assert(coll.getDB().getMongo().useWriteCommands(), "test is not running with write commands")
+
jsTest.log("Starting Tests");
// Basic validation of WriteConcern
@@ -36,13 +36,6 @@ var executeTests = function() {
assert.eq(2, result.nInserted);
assert.eq(1, result.nUpserted);
assert.eq(2, result.nMatched);
- if (coll.getMongo().useWriteCommands()) {
- assert.eq(1, result.nModified);
- }
- else {
- // Legacy updates does not support nModified.
- assert.eq(0, result.nModified);
- }
assert.eq(1, result.nRemoved);
var upserts = result.getUpsertedIds();
assert.eq(1, upserts.length);
@@ -38,13 +38,6 @@ var executeTests = function() {
assert.eq(2, result.nInserted);
assert.eq(1, result.nUpserted);
assert.eq(2, result.nMatched);
- if (coll.getMongo().useWriteCommands()) {
- assert.eq(1, result.nModified);
- }
- else {
- // Legacy updates does not support nModified.
- assert.eq(0, result.nModified);
- }
assert.eq(1, result.nRemoved);
assert(1, result.getWriteErrorCount());
var upserts = result.getUpsertedIds();
View
@@ -1,10 +1,11 @@
// Test that opcounters get incremented properly.
-
var t = db.opcounters;
var isMongos = ("isdbgrid" == db.runCommand("ismaster").msg);
var opCounters;
var res;
+assert(t.getDB().getMongo().useWriteCommands(), "test is not running with write commands")
+
//
// Count ops attempted in write commands in mongod and mongos
//
@@ -24,33 +25,32 @@ t.drop();
// Single insert, no error.
opCounters = db.serverStatus().opcounters;
res = t.insert({_id:0});
-assert(!res.hasWriteErrors());
+assert.writeOK(res);
assert.eq(opCounters.insert + 1, db.serverStatus().opcounters.insert);
// Bulk insert, no error.
opCounters = db.serverStatus().opcounters;
res = t.insert([{_id:1},{_id:2}])
-assert(!res.hasWriteErrors());
+assert.writeOK(res);
assert.eq(opCounters.insert + 2, db.serverStatus().opcounters.insert);
// Single insert, with error.
opCounters = db.serverStatus().opcounters;
res = t.insert({_id:0})
-print(res.getWriteError())
-assert(res.hasWriteErrors());
+assert.writeError(res);
assert.eq(opCounters.insert + 1, db.serverStatus().opcounters.insert);
// Bulk insert, with error, ordered.
opCounters = db.serverStatus().opcounters;
res = t.insert([{_id:3},{_id:3},{_id:4}])
-assert(res.hasWriteErrors());
+assert.writeError(res);
assert.eq(opCounters.insert + 2, db.serverStatus().opcounters.insert);
// Bulk insert, with error, unordered.
var continueOnErrorFlag = 1;
opCounters = db.serverStatus().opcounters;
res = t.insert([{_id:5},{_id:5},{_id:6}], continueOnErrorFlag)
-assert(res.hasWriteErrors());
+assert.writeError(res);
assert.eq(opCounters.insert + 3, db.serverStatus().opcounters.insert);
//
@@ -63,13 +63,13 @@ t.insert({_id:0});
// Update, no error.
opCounters = db.serverStatus().opcounters;
res = t.update({_id:0}, {$set:{a:1}});
-assert(!res.hasWriteErrors());
+assert.writeOK(res);
assert.eq(opCounters.update + 1, db.serverStatus().opcounters.update);
// Update, with error.
opCounters = db.serverStatus().opcounters;
res = t.update({_id:0}, {$set:{_id:1}});
-assert(res.hasWriteErrors());
+assert.writeError(res);
assert.eq(opCounters.update + 1, db.serverStatus().opcounters.update);
//
@@ -82,13 +82,13 @@ t.insert([{_id:0},{_id:1}]);
// Delete, no error.
opCounters = db.serverStatus().opcounters;
res = t.remove({_id:0});
-assert(!res.hasWriteErrors());
+assert.writeOK(res);
assert.eq(opCounters.delete + 1, db.serverStatus().opcounters.delete);
// Delete, with error.
opCounters = db.serverStatus().opcounters;
res = t.remove({_id:{$invalidOp:1}});
-assert(res.hasWriteErrors());
+assert.writeError(res);
assert.eq(opCounters.delete + 1, db.serverStatus().opcounters.delete);
//
@@ -5,7 +5,7 @@
var coll = db.write_result;
coll.drop();
-assert(coll.getMongo().useWriteCommands());
+assert(coll.getDB().getMongo().useWriteCommands(), "test is not running with write commands")
var result = null;
@@ -8,7 +8,7 @@
conn = startMongodEmpty("--port", 30200, "--dbpath", MongoRunner.dataDir + "/dur_passthrough", "--dur", "--nopreallocj", "--smallfiles",
"--durOptions", "8");
db = conn.getDB("test");
-conn._useWriteCommands = true;
+conn.forceWriteMode("commands");
function doTest() {
var files = listFiles("jstests/core");
@@ -1,7 +1,7 @@
var myShardingTest = new ShardingTest("sharding_passthrough", 2, 0, 1);
myShardingTest.adminCommand({ enablesharding : "test" });
var db = myShardingTest.getDB("test");
-db.getMongo()._useWriteCommands = true;
+db.getMongo().forceWriteMode("commands");
var res = db.adminCommand({ setParameter: 1, useClusterWriteCommands: true });
var files = listFiles("jstests/core");
View
@@ -347,7 +347,7 @@ assert.writeOK = function(res, msg) {
if (!res)
errMsg = "missing first argument, no response to check"
- if (!res.getWriteError)
+ else if (!res.getWriteError)
assert.gleOK(res, msg)
else {
if (res.getWriteError()) {
@@ -371,8 +371,7 @@ assert.gleOK = function(res, msg) {
if (!res)
errMsg = "missing first argument, no response to check"
-
- if (!res.ok)
+ else if (!res.ok)
errMsg = "command failed: " + tojson(res);
if ('code' in res || 'errMsg' in res || 'errInfo' in res || 'writeErrors' in res)
@@ -387,11 +386,12 @@ assert.gleOK = function(res, msg) {
return res;
}
-
assert.writeError = function(res, msg) {
var errMsg = "";
- if (!res.getWriteConcernError) {
+ if (!res)
+ errMsg = "The response arg was missing or undefined! -- " + res
+ else if (!res.getWriteConcernError) {
if (!res.err)
errMsg = "no error" + tojson(res);
} else {
@@ -913,7 +913,8 @@ var _bulk_api_module = (function() {
for(var i = 0; i < batches.length; i++) {
// Execute the batch
- if(useWriteCommands) {
+ if(collection.getMongo().hasWriteCommands() &&
+ collection.getMongo().writeMode() == "commands") {
executeBatch(batches[i]);
} else {
executeBatchWithLegacyOps(batches[i]);
@@ -21,6 +21,7 @@ DBCollection.prototype.verify = function(){
assert.eq( this._fullName , this._db._name + "." + this._shortName , "name mismatch" );
assert( this._mongo , "no mongo in DBCollection" );
+ assert( this.getMongo() , "no mongo from getMongo()" );
}
DBCollection.prototype.getName = function(){
@@ -132,7 +133,7 @@ DBCollection.prototype._massageObject = function( q ){
DBCollection.prototype._validateObject = function( o ){
// Hidden property for testing purposes.
- if (this._mongo._skipValidation) return;
+ if (this.getMongo()._skipValidation) return;
if (typeof(o) != "object")
throw "attempted to save a " + typeof(o) + " value. document expected.";
@@ -145,7 +146,7 @@ DBCollection._allowedFields = { $id : 1 , $ref : 1 , $db : 1 };
DBCollection.prototype._validateForStorage = function( o ){
// Hidden property for testing purposes.
- if (this._mongo._skipValidation) return;
+ if (this.getMongo()._skipValidation) return;
this._validateObject( o );
for ( var k in o ){
@@ -225,7 +226,7 @@ DBCollection.prototype.insert = function( obj , options, _allow_dot ){
var startTime = (typeof(_verboseShell) === 'undefined' ||
!_verboseShell) ? 0 : new Date().getTime();
- if ( this._mongo.useWriteCommands() ) {
+ if ( this.getMongo().writeMode() != "legacy" ) {
// Bit 1 of option flag is continueOnError. Bit 0 (stop on error) is the default.
var batch = ordered ? this.initializeOrderedBulkOp() : this.initializeUnorderedBulkOp();
@@ -253,7 +254,7 @@ DBCollection.prototype.insert = function( obj , options, _allow_dot ){
}
}
- this._mongo.insert( this._fullName , obj, flags );
+ this.getMongo().insert( this._fullName , obj, flags );
// enforce write concern, if required
if (wc)
@@ -267,7 +268,7 @@ DBCollection.prototype.insert = function( obj , options, _allow_dot ){
DBCollection.prototype._validateRemoveDoc = function(doc) {
// Hidden property for testing purposes.
- if (this._mongo._skipValidation) return;
+ if (this.getMongo()._skipValidation) return;
for (var k in doc) {
if (k == "_id" && typeof( doc[k] ) == "undefined") {
@@ -292,7 +293,7 @@ DBCollection.prototype.remove = function( t , justOne ){
if (!wc)
wc = this.getWriteConcern();
- if ( this._mongo.useWriteCommands() ) {
+ if ( this.getMongo().writeMode() != "legacy" ) {
var query = (typeof(t) == 'undefined')? {} : this._massageObject(t);
var batch = this.initializeOrderedBulkOp();
var removeOp = batch.find(query);
@@ -308,7 +309,7 @@ DBCollection.prototype.remove = function( t , justOne ){
}
else {
this._validateRemoveDoc(t);
- this._mongo.remove(this._fullName, this._massageObject(t), justOne ? true : false );
+ this.getMongo().remove(this._fullName, this._massageObject(t), justOne ? true : false );
// enforce write concern, if required
if (wc)
@@ -322,7 +323,7 @@ DBCollection.prototype.remove = function( t , justOne ){
DBCollection.prototype._validateUpdateDoc = function(doc) {
// Hidden property for testing purposes.
- if (this._mongo._skipValidation) return;
+ if (this.getMongo()._skipValidation) return;
var firstKey = null;
for (var key in doc) { firstKey = key; break; }
@@ -359,7 +360,7 @@ DBCollection.prototype.update = function( query , obj , upsert , multi ){
if (!wc)
wc = this.getWriteConcern();
- if ( this._mongo.useWriteCommands() ) {
+ if ( this.getMongo().writeMode() != "legacy" ) {
var batch = this.initializeOrderedBulkOp();
var updateOp = batch.find(query);
@@ -378,7 +379,7 @@ DBCollection.prototype.update = function( query , obj , upsert , multi ){
}
else {
this._validateUpdateDoc(obj);
- this._mongo.update(this._fullName, query, obj,
+ this.getMongo().update(this._fullName, query, obj,
upsert ? true : false, multi ? true : false );
// enforce write concern, if required
@@ -490,8 +491,7 @@ DBCollection.prototype._indexSpec = function( keys, options ) {
DBCollection.prototype.createIndex = function( keys , options ){
var o = this._indexSpec( keys, options );
- if ( this._mongo.useWriteCommands() ) {
-
+ if ( this.getMongo().writeMode() != "legacy" ) {
// TODO: Use createIndexes command once fully supported by upgrade process
var bulk = this.getDB().system.indexes.initializeOrderedBulkOp();
bulk.insert(o);
Oops, something went wrong.

0 comments on commit a56653e

Please sign in to comment.