summaryrefslogtreecommitdiff
path: root/src/mongo/s/write_ops
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2013-12-13 08:44:24 -0500
committerScott Hernandez <scotthernandez@gmail.com>2013-12-13 15:51:49 -0500
commitfe185a30da0616ec9cff3f4fc6a90c025724b64b (patch)
tree2b2ad9a6f78af8576dcf9ebdfbe33a10b8ccf749 /src/mongo/s/write_ops
parent34738d8f39dae85b10687b207473e61b52b5b93c (diff)
downloadmongo-fe185a30da0616ec9cff3f4fc6a90c025724b64b.tar.gz
SERVER-3409: Expose number of docs modified (excl. no-ops)
Diffstat (limited to 'src/mongo/s/write_ops')
-rw-r--r--src/mongo/s/write_ops/batch_write_op.cpp1
-rw-r--r--src/mongo/s/write_ops/batch_write_op.h1
-rw-r--r--src/mongo/s/write_ops/batched_command_response.cpp46
-rw-r--r--src/mongo/s/write_ops/batched_command_response.h10
4 files changed, 58 insertions, 0 deletions
diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp
index 0a32dad9301..e5f43628405 100644
--- a/src/mongo/s/write_ops/batch_write_op.cpp
+++ b/src/mongo/s/write_ops/batch_write_op.cpp
@@ -340,6 +340,7 @@ namespace mongo {
numUpserted = 1;
}
stats->numUpdated += ( response.getN() - numUpserted );
+ stats->numModified += ( response.getNDocsModified() - numUpserted );
stats->numUpserted += numUpserted;
}
else {
diff --git a/src/mongo/s/write_ops/batch_write_op.h b/src/mongo/s/write_ops/batch_write_op.h
index ec248b88f37..92cac37bec1 100644
--- a/src/mongo/s/write_ops/batch_write_op.h
+++ b/src/mongo/s/write_ops/batch_write_op.h
@@ -171,6 +171,7 @@ namespace mongo {
int numInserted;
int numUpserted;
int numUpdated;
+ int numModified;
int numDeleted;
};
diff --git a/src/mongo/s/write_ops/batched_command_response.cpp b/src/mongo/s/write_ops/batched_command_response.cpp
index 1372ab718a1..e45bfa64494 100644
--- a/src/mongo/s/write_ops/batched_command_response.cpp
+++ b/src/mongo/s/write_ops/batched_command_response.cpp
@@ -40,6 +40,7 @@ namespace mongo {
const BSONField<BSONObj> BatchedCommandResponse::errInfo("errInfo");
const BSONField<string> BatchedCommandResponse::errMessage("errmsg");
const BSONField<long long> BatchedCommandResponse::n("n", 0);
+ const BSONField<long long> BatchedCommandResponse::nDocsModified("nDocsModified", 0);
const BSONField<BSONObj> BatchedCommandResponse::singleUpserted("upserted");
const BSONField<std::vector<BatchedUpsertDetail*> >
BatchedCommandResponse::upsertDetails("upserted");
@@ -87,6 +88,7 @@ namespace mongo {
if (_isErrMessageSet) builder.append(errMessage(), _errMessage);
+ if (_isNDocsModifiedSet) builder.appendNumber(nDocsModified(), _nDocsModified);
if (_isNSet) builder.appendNumber(n(), _n);
// We're using the BSONObj to store the _id value.
@@ -160,6 +162,22 @@ namespace mongo {
_n = tempN;
}
+ // 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("nDocumentsModified");
+ 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);
+ if (fieldState == FieldParser::FIELD_INVALID) return false;
+ _isNDocsModifiedSet = fieldState == FieldParser::FIELD_SET;
+ }
+ else if (fieldState == FieldParser::FIELD_SET) {
+ _isNDocsModifiedSet = true;
+ _nDocsModified = tempNUpdated;
+ }
+
// singleUpserted and upsertDetails have the same field name, but are distinguished
// by type. First try parsing singleUpserted, if that doesn't work, try upsertDetails
fieldState = FieldParser::extractID(source, singleUpserted, &_singleUpserted, errMsg);
@@ -198,6 +216,9 @@ namespace mongo {
_errMessage.clear();
_isErrMessageSet = false;
+ _nDocsModified = 0;
+ _isNDocsModifiedSet = false;
+
_n = 0;
_isNSet = false;
@@ -234,6 +255,9 @@ namespace mongo {
other->_errMessage = _errMessage;
other->_isErrMessageSet = _isErrMessageSet;
+ other->_nDocsModified = _nDocsModified;
+ other->_isNDocsModifiedSet = _isNDocsModifiedSet;
+
other->_n = _n;
other->_isNSet = _isNSet;
@@ -346,6 +370,28 @@ namespace mongo {
return _errMessage;
}
+ void BatchedCommandResponse::setNDocsModified(long long n) {
+ _nDocsModified = n;
+ _isNDocsModifiedSet = true;
+ }
+
+ void BatchedCommandResponse::unsetNDocsModified() {
+ _isNDocsModifiedSet = false;
+ }
+
+ bool BatchedCommandResponse::isNDocsModified() const {
+ return _isNDocsModifiedSet;
+ }
+
+ long long BatchedCommandResponse::getNDocsModified() const {
+ if ( _isNDocsModifiedSet ) {
+ return _nDocsModified;
+ }
+ else {
+ return nDocsModified.getDefault();
+ }
+ }
+
void BatchedCommandResponse::setN(long long n) {
_n = n;
_isNSet = true;
diff --git a/src/mongo/s/write_ops/batched_command_response.h b/src/mongo/s/write_ops/batched_command_response.h
index 5430309661d..46a882e322a 100644
--- a/src/mongo/s/write_ops/batched_command_response.h
+++ b/src/mongo/s/write_ops/batched_command_response.h
@@ -57,6 +57,7 @@ namespace mongo {
static const BSONField<BSONObj> errInfo;
static const BSONField<string> errMessage;
static const BSONField<long long> n;
+ static const BSONField<long long> nDocsModified;
static const BSONField<BSONObj> singleUpserted; // ID type
static const BSONField<std::vector<BatchedUpsertDetail*> > upsertDetails;
static const BSONField<Date_t> lastOp;
@@ -106,6 +107,11 @@ 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 setN(long long n);
void unsetN();
bool isNSet() const;
@@ -160,6 +166,10 @@ namespace mongo {
long long _n;
bool _isNSet;
+ // (O) number of documents updated
+ long long _nDocsModified;
+ bool _isNDocsModifiedSet;
+
// (O) "promoted" _upserted, if the corresponding request contained only one batch item
// Should only be present if _upserted is not.
BSONObj _singleUpserted;