diff options
author | Randolph Tan <randolph@10gen.com> | 2014-01-10 13:07:04 -0500 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2014-01-13 11:41:31 -0500 |
commit | 77148d5a6c3e775c8e5e2944fac9695833f11b52 (patch) | |
tree | 58f222cf63bfd1ff5eaf2d040720fbe2cdc4c59a /src | |
parent | fef75c6b2d337151b37e3e77c54df72a9327b54e (diff) | |
download | mongo-77148d5a6c3e775c8e5e2944fac9695833f11b52.tar.gz |
SERVER-12319 nDocsModified in write commands to nModified
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/client.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/batch_executor.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/curop.h | 2 | ||||
-rw-r--r-- | src/mongo/db/ops/update.cpp | 8 | ||||
-rw-r--r-- | src/mongo/s/write_ops/batch_write_op.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/write_ops/batched_command_response.cpp | 44 | ||||
-rw-r--r-- | src/mongo/s/write_ops/batched_command_response.h | 14 | ||||
-rw-r--r-- | src/mongo/shell/batch_api.js | 13 |
8 files changed, 48 insertions, 45 deletions
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index d94f6102600..1e5e8b43367 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -567,7 +567,7 @@ namespace mongo { idhack = false; scanAndOrder = false; nupdated = -1; - nDocsModified = -1; + nModified = -1; ninserted = -1; ndeleted = -1; nmoved = -1; @@ -617,7 +617,7 @@ namespace mongo { OPDEBUG_TOSTRING_HELP_BOOL( scanAndOrder ); OPDEBUG_TOSTRING_HELP( nmoved ); OPDEBUG_TOSTRING_HELP( nupdated ); - OPDEBUG_TOSTRING_HELP( nDocsModified ); + OPDEBUG_TOSTRING_HELP( nModified ); OPDEBUG_TOSTRING_HELP( ninserted ); OPDEBUG_TOSTRING_HELP( ndeleted ); OPDEBUG_TOSTRING_HELP_BOOL( fastmod ); @@ -711,7 +711,7 @@ namespace mongo { OPDEBUG_APPEND_BOOL( moved ); OPDEBUG_APPEND_NUMBER( nmoved ); OPDEBUG_APPEND_NUMBER( nupdated ); - OPDEBUG_APPEND_NUMBER( nDocsModified ); + OPDEBUG_APPEND_NUMBER( nModified ); OPDEBUG_APPEND_NUMBER( ninserted ); OPDEBUG_APPEND_NUMBER( ndeleted ); OPDEBUG_APPEND_BOOL( fastmod ); diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index a2d7ffbc124..5c7305e5a82 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -178,7 +178,7 @@ namespace mongo { response->setN( _stats->numInserted + _stats->numUpserted + _stats->numUpdated + _stats->numDeleted ); if ( request.getBatchType() == BatchedCommandRequest::BatchType_Update ) - response->setNDocsModified( _stats->numModified ); + response->setNModified( _stats->numModified ); // TODO: Audit where we want to queue here - the shardingState calls may block for remote // data diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h index 4042e0bfd5a..eed53648a81 100644 --- a/src/mongo/db/curop.h +++ b/src/mongo/db/curop.h @@ -93,7 +93,7 @@ namespace mongo { bool idhack; // indicates short circuited code path on an update to make the update faster bool scanAndOrder; // scanandorder query plan aspect was used long long nupdated; // number of records updated (including no-ops) - long long nDocsModified; // number of records written (no no-ops) + long long nModified; // number of records written (no no-ops) long long nmoved; // updates resulted in a move (moves are expensive) long long ninserted; long long ndeleted; diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp index 49f0205705e..7345388089b 100644 --- a/src/mongo/db/ops/update.cpp +++ b/src/mongo/db/ops/update.cpp @@ -508,7 +508,7 @@ namespace mongo { // reflecting only the actions taken locally. In particlar, we must have the no-op // counter reset so that we can meaningfully comapre it with numMatched above. opDebug->nscanned = 0; - opDebug->nDocsModified = 0; + opDebug->nModified = 0; // Get the cached document from the update driver. mutablebson::Document& doc = driver->getDocument(); @@ -528,7 +528,7 @@ namespace mongo { while (true) { // See if we have a write in isolation mode - isolationModeWriteOccured = isolated && (opDebug->nDocsModified > 0); + isolationModeWriteOccured = isolated && (opDebug->nModified > 0); // Change to manual yielding (no yielding) if we have written in isolation mode if (isolationModeWriteOccured) { @@ -723,7 +723,7 @@ namespace mongo { // Only record doc modifications if they wrote (exclude no-ops) if (docWasModified) - opDebug->nDocsModified++; + opDebug->nModified++; if (!request.isMulti()) { break; @@ -738,7 +738,7 @@ namespace mongo { opDebug->nupdated = numMatched; return UpdateResult(numMatched > 0 /* updated existing object(s) */, !driver->isDocReplacement() /* $mod or obj replacement */, - opDebug->nDocsModified /* number of modified docs, no no-ops */, + opDebug->nModified /* number of modified docs, no no-ops */, numMatched /* # of docs matched/updated, even no-ops */, BSONObj()); } diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp index b1b10f13c2b..a2f28d16db9 100644 --- a/src/mongo/s/write_ops/batch_write_op.cpp +++ b/src/mongo/s/write_ops/batch_write_op.cpp @@ -369,7 +369,7 @@ namespace mongo { numUpserted = response.sizeUpsertDetails(); } stats->numUpdated += ( response.getN() - numUpserted ); - stats->numModified += response.getNDocsModified(); + stats->numModified += response.getNModified(); stats->numUpserted += numUpserted; } else { @@ -597,7 +597,7 @@ namespace mongo { + _stats->numDeleted; batchResp->setN( nValue ); if ( _clientRequest->getBatchType() == BatchedCommandRequest::BatchType_Update ) - batchResp->setNDocsModified( _stats->numModified ); + batchResp->setNModified( _stats->numModified ); dassert( batchResp->isValid( NULL ) ); } diff --git a/src/mongo/s/write_ops/batched_command_response.cpp b/src/mongo/s/write_ops/batched_command_response.cpp index 4512c2a1eeb..3fb0fc805f3 100644 --- a/src/mongo/s/write_ops/batched_command_response.cpp +++ b/src/mongo/s/write_ops/batched_command_response.cpp @@ -39,7 +39,7 @@ namespace mongo { const BSONField<int> BatchedCommandResponse::errCode("code", ErrorCodes::UnknownError); const BSONField<string> BatchedCommandResponse::errMessage("errmsg"); const BSONField<long long> BatchedCommandResponse::n("n", 0); - const BSONField<long long> BatchedCommandResponse::nDocsModified("nDocsModified", 0); + const BSONField<long long> BatchedCommandResponse::nModified("nModified", 0); const BSONField<std::vector<BatchedUpsertDetail*> > BatchedCommandResponse::upsertDetails("upserted"); const BSONField<OpTime> BatchedCommandResponse::lastOp("lastOp"); @@ -79,7 +79,7 @@ namespace mongo { if (_isErrMessageSet) builder.append(errMessage(), _errMessage); - if (_isNDocsModifiedSet) builder.appendNumber(nDocsModified(), _nDocsModified); + if (_isNModifiedSet) builder.appendNumber(nModified(), _nModified); if (_isNSet) builder.appendNumber(n(), _n); if (_upsertDetails.get()) { @@ -150,18 +150,18 @@ namespace mongo { // We're using appendNumber on generation so we'll try a smaller type // (int) first and then fall back to the original type (long long). - BSONField<int> fieldNUpdated(nDocsModified()); + BSONField<int> fieldNUpdated(nModified()); int tempNUpdated; fieldState = FieldParser::extract(source, fieldNUpdated, &tempNUpdated, errMsg); if (fieldState == FieldParser::FIELD_INVALID) { // try falling back to a larger type - fieldState = FieldParser::extract(source, nDocsModified, &_nDocsModified, errMsg); + fieldState = FieldParser::extract(source, nModified, &_nModified, errMsg); if (fieldState == FieldParser::FIELD_INVALID) return false; - _isNDocsModifiedSet = fieldState == FieldParser::FIELD_SET; + _isNModifiedSet = fieldState == FieldParser::FIELD_SET; } else if (fieldState == FieldParser::FIELD_SET) { - _isNDocsModifiedSet = true; - _nDocsModified = tempNUpdated; + _isNModifiedSet = true; + _nModified = tempNUpdated; } std::vector<BatchedUpsertDetail*>* tempUpsertDetails = NULL; @@ -205,8 +205,8 @@ namespace mongo { _errMessage.clear(); _isErrMessageSet = false; - _nDocsModified = 0; - _isNDocsModifiedSet = false; + _nModified = 0; + _isNModifiedSet = false; _n = 0; _isNSet = false; @@ -249,8 +249,8 @@ namespace mongo { other->_errMessage = _errMessage; other->_isErrMessageSet = _isErrMessageSet; - other->_nDocsModified = _nDocsModified; - other->_isNDocsModifiedSet = _isNDocsModifiedSet; + other->_nModified = _nModified; + other->_isNModifiedSet = _isNModifiedSet; other->_n = _n; other->_isNSet = _isNSet; @@ -351,25 +351,25 @@ namespace mongo { return _errMessage; } - void BatchedCommandResponse::setNDocsModified(long long n) { - _nDocsModified = n; - _isNDocsModifiedSet = true; + void BatchedCommandResponse::setNModified(long long n) { + _nModified = n; + _isNModifiedSet = true; } - void BatchedCommandResponse::unsetNDocsModified() { - _isNDocsModifiedSet = false; + void BatchedCommandResponse::unsetNModified() { + _isNModifiedSet = false; } - bool BatchedCommandResponse::isNDocsModified() const { - return _isNDocsModifiedSet; + bool BatchedCommandResponse::isNModified() const { + return _isNModifiedSet; } - long long BatchedCommandResponse::getNDocsModified() const { - if ( _isNDocsModifiedSet ) { - return _nDocsModified; + long long BatchedCommandResponse::getNModified() const { + if ( _isNModifiedSet ) { + return _nModified; } else { - return nDocsModified.getDefault(); + return nModified.getDefault(); } } diff --git a/src/mongo/s/write_ops/batched_command_response.h b/src/mongo/s/write_ops/batched_command_response.h index 8a06b76b192..92df56a3198 100644 --- a/src/mongo/s/write_ops/batched_command_response.h +++ b/src/mongo/s/write_ops/batched_command_response.h @@ -57,7 +57,7 @@ namespace mongo { static const BSONField<int> errCode; static const BSONField<string> errMessage; static const BSONField<long long> n; - static const BSONField<long long> nDocsModified; + static const BSONField<long long> nModified; static const BSONField<std::vector<BatchedUpsertDetail*> > upsertDetails; static const BSONField<OpTime> lastOp; static const BSONField<std::vector<WriteErrorDetail*> > writeErrors; @@ -102,10 +102,10 @@ namespace mongo { bool isErrMessageSet() const; const std::string& getErrMessage() const; - void setNDocsModified(long long n); - void unsetNDocsModified(); - bool isNDocsModified() const; - long long getNDocsModified() const; + void setNModified(long long n); + void unsetNModified(); + bool isNModified() const; + long long getNModified() const; void setN(long long n); void unsetN(); @@ -159,8 +159,8 @@ namespace mongo { bool _isNSet; // (O) number of documents updated - long long _nDocsModified; - bool _isNDocsModifiedSet; + long long _nModified; + bool _isNModifiedSet; // (O) "promoted" _upserted, if the corresponding request contained only one batch item // Should only be present if _upserted is not. diff --git a/src/mongo/shell/batch_api.js b/src/mongo/shell/batch_api.js index eb3462cb237..1d0a8e8f6c4 100644 --- a/src/mongo/shell/batch_api.js +++ b/src/mongo/shell/batch_api.js @@ -58,12 +58,16 @@ var _batch_api_module = (function() { defineReadOnlyProperty(this, "nInserted", bulkResult.nInserted); defineReadOnlyProperty(this, "nUpserted", bulkResult.nUpserted); defineReadOnlyProperty(this, "nUpdated", bulkResult.nUpdated); - defineReadOnlyProperty(this, "nModified", bulkResult.nUpserted); + defineReadOnlyProperty(this, "nModified", bulkResult.nModified); defineReadOnlyProperty(this, "nRemoved", bulkResult.nRemoved); // // Define access methods this.getUpsertedId = function() { + if (bulkResult.upserted.length == 0) { + return null; + } + return bulkResult.upserted[bulkResult.upserted.length - 1]; }; @@ -113,7 +117,7 @@ var _batch_api_module = (function() { defineReadOnlyProperty(this, "nInserted", bulkResult.nInserted); defineReadOnlyProperty(this, "nUpserted", bulkResult.nUpserted); defineReadOnlyProperty(this, "nUpdated", bulkResult.nUpdated); - defineReadOnlyProperty(this, "nModified", bulkResult.nUpserted); + defineReadOnlyProperty(this, "nModified", bulkResult.nModified); defineReadOnlyProperty(this, "nRemoved", bulkResult.nRemoved); // @@ -536,7 +540,7 @@ var _batch_api_module = (function() { // If we have an update Batch type if(batch.batchType == UPDATE) { - var nModified = result.nDocsModified ? result.nDocsModified : 0; + var nModified = ('nModified' in result)? result.nModified: 0; bulkResult.nUpserted = bulkResult.nUpserted + nUpserted; bulkResult.nUpdated = bulkResult.nUpdated + (result.n - nUpserted); bulkResult.nModified = bulkResult.nModified + nModified; @@ -649,7 +653,7 @@ var _batch_api_module = (function() { var batchResult = { n: 0 - , nDocsModified: 0 + , nModified: 0 , writeErrors: [] , upserted: [] }; @@ -715,7 +719,6 @@ var _batch_api_module = (function() { }); } else if(result.n) { batchResult.n = batchResult.n + result.n; - batchResult.nDocsModified = batchResult.nDocsModified + result.n; } } |