summaryrefslogtreecommitdiff
path: root/src/mongo/s/write_ops
diff options
context:
space:
mode:
authorJanna Golden <janna.golden@mongodb.com>2019-12-17 16:41:48 +0000
committerevergreen <evergreen@mongodb.com>2019-12-17 16:41:48 +0000
commit1fe9dfb1ade548488831bf29cdcc57636e5e3b8a (patch)
tree0e005b396049b1c246b73cde868dba1dac9582cc /src/mongo/s/write_ops
parent726a916f2e0072169878dd36efd0cd5d6964e12e (diff)
downloadmongo-1fe9dfb1ade548488831bf29cdcc57636e5e3b8a.tar.gz
SERVER-43617 Add metrics on the mongos to indicate the number of shards targeted for CRUD and agg commands
Diffstat (limited to 'src/mongo/s/write_ops')
-rw-r--r--src/mongo/s/write_ops/batch_write_exec.cpp12
-rw-r--r--src/mongo/s/write_ops/batch_write_exec.h3
-rw-r--r--src/mongo/s/write_ops/batch_write_op.cpp7
-rw-r--r--src/mongo/s/write_ops/batch_write_op.h4
-rw-r--r--src/mongo/s/write_ops/chunk_manager_targeter.cpp8
-rw-r--r--src/mongo/s/write_ops/chunk_manager_targeter.h2
-rw-r--r--src/mongo/s/write_ops/mock_ns_targeter.h5
7 files changed, 41 insertions, 0 deletions
diff --git a/src/mongo/s/write_ops/batch_write_exec.cpp b/src/mongo/s/write_ops/batch_write_exec.cpp
index 0fd8842ce92..0020eb137f8 100644
--- a/src/mongo/s/write_ops/batch_write_exec.cpp
+++ b/src/mongo/s/write_ops/batch_write_exec.cpp
@@ -455,6 +455,10 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
}
}
+ auto nShardsOwningChunks = batchOp.getNShardsOwningChunks();
+ if (nShardsOwningChunks.is_initialized())
+ stats->noteNumShardsOwningChunks(nShardsOwningChunks.get());
+
batchOp.buildClientResponse(clientResponse);
LOG(4) << "Finished execution of write batch"
@@ -476,6 +480,10 @@ void BatchWriteExecStats::noteWriteAt(const HostAndPort& host,
_writeOpTimes[ConnectionString(host)] = HostOpTime(opTime, electionId);
}
+void BatchWriteExecStats::noteNumShardsOwningChunks(const int nShardsOwningChunks) {
+ _numShardsOwningChunks.emplace(nShardsOwningChunks);
+}
+
const std::set<ShardId>& BatchWriteExecStats::getTargetedShards() const {
return _targetedShards;
}
@@ -484,4 +492,8 @@ const HostOpTimeMap& BatchWriteExecStats::getWriteOpTimes() const {
return _writeOpTimes;
}
+const boost::optional<int> BatchWriteExecStats::getNumShardsOwningChunks() const {
+ return _numShardsOwningChunks;
+}
+
} // namespace mongo
diff --git a/src/mongo/s/write_ops/batch_write_exec.h b/src/mongo/s/write_ops/batch_write_exec.h
index c729561630a..9b6773ecb47 100644
--- a/src/mongo/s/write_ops/batch_write_exec.h
+++ b/src/mongo/s/write_ops/batch_write_exec.h
@@ -94,9 +94,11 @@ public:
void noteWriteAt(const HostAndPort& host, repl::OpTime opTime, const OID& electionId);
void noteTargetedShard(const ShardId& shardId);
+ void noteNumShardsOwningChunks(const int nShardsOwningChunks);
const std::set<ShardId>& getTargetedShards() const;
const HostOpTimeMap& getWriteOpTimes() const;
+ const boost::optional<int> getNumShardsOwningChunks() const;
// Expose via helpers if this gets more complex
@@ -114,6 +116,7 @@ public:
private:
std::set<ShardId> _targetedShards;
HostOpTimeMap _writeOpTimes;
+ boost::optional<int> _numShardsOwningChunks;
};
} // namespace mongo
diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp
index 309d3f4f83e..47ece031758 100644
--- a/src/mongo/s/write_ops/batch_write_op.cpp
+++ b/src/mongo/s/write_ops/batch_write_op.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/ops/write_ops_parsers.h"
#include "mongo/db/s/database_sharding_state.h"
+#include "mongo/s/client/num_hosts_targeted_metrics.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/grid.h"
#include "mongo/s/transaction_router.h"
@@ -435,6 +436,8 @@ Status BatchWriteOp::targetBatch(const NSTargeter& targeter,
targetedBatches->emplace(batch->getEndpoint().shardName, batch);
}
+ _nShardsOwningChunks = targeter.getNShardsOwningChunks();
+
return Status::OK();
}
@@ -827,6 +830,10 @@ int BatchWriteOp::numWriteOpsIn(WriteOpState opState) const {
});
}
+boost::optional<int> BatchWriteOp::getNShardsOwningChunks() {
+ return _nShardsOwningChunks;
+}
+
void BatchWriteOp::_incBatchStats(const BatchedCommandResponse& response) {
const auto batchType = _clientRequest.getBatchType();
diff --git a/src/mongo/s/write_ops/batch_write_op.h b/src/mongo/s/write_ops/batch_write_op.h
index f4ef76bb2c8..eeccb02d2a0 100644
--- a/src/mongo/s/write_ops/batch_write_op.h
+++ b/src/mongo/s/write_ops/batch_write_op.h
@@ -201,6 +201,8 @@ public:
*/
int numWriteOpsIn(WriteOpState state) const;
+ boost::optional<int> getNShardsOwningChunks();
+
private:
/**
* Maintains the batch execution statistics when a response is received.
@@ -242,6 +244,8 @@ private:
// Set to true if this write is part of a transaction.
const bool _inTransaction{false};
+
+ boost::optional<int> _nShardsOwningChunks;
};
/**
diff --git a/src/mongo/s/write_ops/chunk_manager_targeter.cpp b/src/mongo/s/write_ops/chunk_manager_targeter.cpp
index 0d8cce10233..a36fb2b4feb 100644
--- a/src/mongo/s/write_ops/chunk_manager_targeter.cpp
+++ b/src/mongo/s/write_ops/chunk_manager_targeter.cpp
@@ -846,6 +846,14 @@ Status ChunkManagerTargeter::refreshIfNeeded(OperationContext* opCtx, bool* wasC
MONGO_UNREACHABLE;
}
+int ChunkManagerTargeter::getNShardsOwningChunks() const {
+ if (_routingInfo->cm()) {
+ return _routingInfo->cm()->getNShardsOwningChunks();
+ }
+
+ return 0;
+}
+
Status ChunkManagerTargeter::_refreshShardVersionNow(OperationContext* opCtx) {
Grid::get(opCtx)->catalogCache()->onStaleShardVersion(std::move(*_routingInfo));
diff --git a/src/mongo/s/write_ops/chunk_manager_targeter.h b/src/mongo/s/write_ops/chunk_manager_targeter.h
index e50bd2b1c24..ef8e2c6f8d2 100644
--- a/src/mongo/s/write_ops/chunk_manager_targeter.h
+++ b/src/mongo/s/write_ops/chunk_manager_targeter.h
@@ -111,6 +111,8 @@ public:
*/
Status refreshIfNeeded(OperationContext* opCtx, bool* wasChanged) override;
+ int getNShardsOwningChunks() const override;
+
private:
using ShardVersionMap = std::map<ShardId, ChunkVersion>;
diff --git a/src/mongo/s/write_ops/mock_ns_targeter.h b/src/mongo/s/write_ops/mock_ns_targeter.h
index 210406d327d..959ac03086e 100644
--- a/src/mongo/s/write_ops/mock_ns_targeter.h
+++ b/src/mongo/s/write_ops/mock_ns_targeter.h
@@ -137,6 +137,11 @@ public:
return Status::OK();
}
+ int getNShardsOwningChunks() const override {
+ // No-op
+ return 0;
+ }
+
private:
static ChunkRange _parseRange(const BSONObj& query) {
const StringData fieldName(query.firstElement().fieldName());