summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSuganthi Mani <suganthi.mani@mongodb.com>2018-12-06 17:55:25 -0500
committerSuganthi Mani <suganthi.mani@mongodb.com>2019-01-08 21:17:29 -0500
commit214bf238fedc4e147e6473f5fc64428987added6 (patch)
treec5828c2f30cc194ce851968623a73a31ee788763 /src
parentb349bfbecc47a27e40505b626bee5270de7060af (diff)
downloadmongo-214bf238fedc4e147e6473f5fc64428987added6.tar.gz
SERVER-37915 Updates serverStatus.opcountersRepl.command on secondaries.
And, atomic applyOps cmd increments serverStatus.opcounters<opType> for each individual operation on primary.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/repl/oplog.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 0e244b9a0d0..428bee03dfd 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -1085,7 +1085,13 @@ Status applyOperation_inlock(OperationContext* opCtx,
LOG(3) << "applying op: " << redact(op)
<< ", oplog application mode: " << OplogApplication::modeToString(mode);
- OpCounters* opCounters = opCtx->writesAreReplicated() ? &globalOpCounters : &replOpCounters;
+ // Choose opCounters based on running on standalone/primary or secondary by checking
+ // whether writes are replicated. Atomic applyOps command is an exception, which runs
+ // on primary/standalone but disables write replication.
+ OpCounters* opCounters =
+ (mode == repl::OplogApplication::Mode::kApplyOpsCmd || opCtx->writesAreReplicated())
+ ? &globalOpCounters
+ : &replOpCounters;
std::array<StringData, 8> names = {"ts", "t", "o", "ui", "ns", "op", "b", "o2"};
std::array<BSONElement, 8> fields;
@@ -1541,6 +1547,11 @@ Status applyCommand_inlock(OperationContext* opCtx,
const char* opType = fieldOp.valuestrsafe();
invariant(*opType == 'c'); // only commands are processed here
+ // Choose opCounters based on running on standalone/primary or secondary by checking
+ // whether writes are replicated.
+ OpCounters* opCounters = opCtx->writesAreReplicated() ? &globalOpCounters : &replOpCounters;
+ opCounters->gotCommand();
+
if (fieldO.eoo()) {
return Status(ErrorCodes::NoSuchKey, "Missing expected field 'o'");
}