summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/client/dbclient.cpp4
-rw-r--r--src/mongo/db/commands.h4
-rw-r--r--src/mongo/db/commands/find_cmd.cpp4
-rw-r--r--src/mongo/db/commands/getmore_cmd.cpp4
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp22
-rw-r--r--src/mongo/db/curop.cpp8
-rw-r--r--src/mongo/db/curop.h16
-rw-r--r--src/mongo/db/db_raii.cpp4
-rw-r--r--src/mongo/db/dbmessage.cpp2
-rw-r--r--src/mongo/db/instance.cpp16
-rw-r--r--src/mongo/db/introspect.cpp7
-rw-r--r--src/mongo/db/introspect.h3
-rw-r--r--src/mongo/db/stats/top.cpp39
-rw-r--r--src/mongo/db/stats/top.h5
-rw-r--r--src/mongo/executor/downconvert_find_and_getmore_commands.cpp4
-rw-r--r--src/mongo/executor/network_interface_asio_command.cpp4
-rw-r--r--src/mongo/rpc/legacy_reply.cpp2
-rw-r--r--src/mongo/s/server.cpp6
-rw-r--r--src/mongo/util/net/message.h83
19 files changed, 153 insertions, 84 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp
index 007f295d51d..e881e161c29 100644
--- a/src/mongo/client/dbclient.cpp
+++ b/src/mongo/client/dbclient.cpp
@@ -326,8 +326,8 @@ rpc::UniqueReply DBClientWithCommands::runCommandWithMetadata(StringData databas
uassert(ErrorCodes::RPCProtocolNegotiationFailed,
str::stream() << "Mismatched RPC protocols - request was '"
- << opToString(requestMsg.operation()) << "' '"
- << " but reply was '" << opToString(replyMsg.operation()) << "' ",
+ << networkOpToString(requestMsg.operation()) << "' '"
+ << " but reply was '" << networkOpToString(replyMsg.operation()) << "' ",
requestBuilder->getProtocol() == commandReply->getProtocol());
if (ErrorCodes::SendStaleConfig ==
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h
index e835b73c959..5897fb79321 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -245,8 +245,8 @@ public:
return false;
}
- virtual Operation getLogicalOp() const {
- return dbCommand;
+ virtual LogicalOp getLogicalOp() const {
+ return LogicalOp::opCommand;
}
/** @param webUI expose the command in the web ui as localhost:28017/<name>
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index 1176b291aeb..6651baef97d 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -101,8 +101,8 @@ public:
help << "query for documents";
}
- Operation getLogicalOp() const override {
- return dbQuery;
+ LogicalOp getLogicalOp() const override {
+ return LogicalOp::opQuery;
}
/**
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp
index baefe6dbec5..deebe481f1b 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -103,8 +103,8 @@ public:
help << "retrieve more results from an existing cursor";
}
- Operation getLogicalOp() const override {
- return dbGetMore;
+ LogicalOp getLogicalOp() const override {
+ return LogicalOp::opGetMore;
}
/**
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp
index 251b8af52fe..3eaa3964bd9 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -160,7 +160,7 @@ void noteInCriticalSection(WriteErrorDetail* staleError) {
* Translates write item type to wire protocol op code. Helper for
* WriteBatchExecutor::applyWriteItem().
*/
-Operation getOpCode(const BatchItemRef& currWrite) {
+NetworkOp getOpCode(const BatchItemRef& currWrite) {
switch (currWrite.getRequest()->getBatchType()) {
case BatchedCommandRequest::BatchType_Insert:
return dbInsert;
@@ -486,7 +486,7 @@ static void beginCurrentOp(OperationContext* txn, const BatchItemRef& currWrite)
stdx::lock_guard<Client> lk(*txn->getClient());
CurOp* const currentOp = CurOp::get(txn);
currentOp->setNetworkOp_inlock(getOpCode(currWrite));
- currentOp->setLogicalOp_inlock(getOpCode(currWrite));
+ currentOp->setLogicalOp_inlock(networkOpToLogicalOp(getOpCode(currWrite)));
currentOp->ensureStarted();
currentOp->setNS_inlock(currWrite.getRequest()->getNS().ns());
@@ -541,8 +541,8 @@ static void logCurOpError(CurOp* currentOp, WriteErrorDetail* opError) {
currentOp->debug().exceptionInfo =
ExceptionInfo(opError->getErrMessage(), opError->getErrCode());
- LOG(3) << " Caught Assertion in " << opToString(currentOp->getNetworkOp()) << ", continuing "
- << causedBy(opError->getErrMessage());
+ LOG(3) << " Caught Assertion in " << networkOpToString(currentOp->getNetworkOp())
+ << ", continuing " << causedBy(opError->getErrMessage());
}
static void finishCurrentOp(OperationContext* txn, WriteErrorDetail* opError) {
@@ -552,7 +552,7 @@ static void finishCurrentOp(OperationContext* txn, WriteErrorDetail* opError) {
recordCurOpMetrics(txn);
Top::get(txn->getClient()->getServiceContext())
.record(currentOp->getNS(),
- currentOp->getNetworkOp(),
+ currentOp->getLogicalOp(),
1, // "write locked"
currentOp->totalTimeMicros(),
currentOp->isCommand());
@@ -811,7 +811,7 @@ void WriteBatchExecutor::execInserts(const BatchedCommandRequest& request,
{
stdx::lock_guard<Client> lk(*_txn->getClient());
currentOp = CurOp::get(_txn);
- currentOp->setLogicalOp_inlock(dbInsert);
+ currentOp->setLogicalOp_inlock(LogicalOp::opInsert);
currentOp->ensureStarted();
currentOp->setNS_inlock(request.getNS().ns());
currentOp->debug().ninserted = 0;
@@ -852,6 +852,16 @@ void WriteBatchExecutor::execInserts(const BatchedCommandRequest& request,
break;
}
}
+
+ // TODO: Move Top and CurOp metrics management into an RAII object.
+ currentOp->done();
+ recordCurOpMetrics(_txn);
+ Top::get(_txn->getClient()->getServiceContext())
+ .record(currentOp->getNS(),
+ currentOp->getLogicalOp(),
+ 1, // "write locked"
+ currentOp->totalTimeMicros(),
+ currentOp->isCommand());
}
void WriteBatchExecutor::execUpdate(const BatchItemRef& updateItem,
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index 148f3896b6d..f8a1d52209b 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -293,7 +293,7 @@ void CurOp::reportState(BSONObjBuilder* builder) {
builder->append("microsecs_running", static_cast<long long int>(elapsedMicros()));
}
- builder->append("op", opToString(_logicalOp));
+ builder->append("op", logicalOpToString(_logicalOp));
builder->append("ns", _ns);
if (_networkOp == dbInsert) {
@@ -452,7 +452,7 @@ string OpDebug::report(const CurOp& curop, const SingleThreadedLockStats& lockSt
if (iscommand)
s << "command ";
else
- s << opToString(networkOp) << ' ';
+ s << networkOpToString(networkOp) << ' ';
s << curop.getNS();
@@ -578,7 +578,7 @@ void OpDebug::append(const CurOp& curop,
BSONObjBuilder& b) const {
const size_t maxElementSize = 50 * 1024;
- b.append("op", opToString(logicalOp));
+ b.append("op", logicalOpToString(logicalOp));
NamespaceString nss = NamespaceString(curop.getNS());
b.append("ns", nss.ns());
@@ -587,7 +587,7 @@ void OpDebug::append(const CurOp& curop,
appendAsObjOrString(
"query", upconvertQueryEntry(query, nss, ntoreturn, ntoskip), maxElementSize, &b);
} else if (!query.isEmpty()) {
- const char* fieldName = (logicalOp == dbCommand) ? "command" : "query";
+ const char* fieldName = (logicalOp == LogicalOp::opCommand) ? "command" : "query";
appendAsObjOrString(fieldName, query, maxElementSize, &b);
} else if (!iscommand && curop.haveQuery()) {
appendAsObjOrString("query", curop.query(), maxElementSize, &b);
diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h
index 55e48df56cf..423e1adc5fa 100644
--- a/src/mongo/db/curop.h
+++ b/src/mongo/db/curop.h
@@ -147,11 +147,11 @@ public:
// basic options
// _networkOp represents the network-level op code: OP_QUERY, OP_GET_MORE, OP_COMMAND, etc.
- Operation networkOp{opInvalid}; // only set this through setNetworkOp_inlock() to keep synced
+ NetworkOp networkOp{opInvalid}; // only set this through setNetworkOp_inlock() to keep synced
// _logicalOp is the logical operation type, ie 'dbQuery' regardless of whether this is an
// OP_QUERY find, a find command using OP_QUERY, or a find command using OP_COMMAND.
// Similarly, the return value will be dbGetMore for both OP_GET_MORE and getMore command.
- Operation logicalOp{opInvalid}; // only set this through setNetworkOp_inlock() to keep synced
+ LogicalOp logicalOp{LogicalOp::opInvalid}; // only set this through setNetworkOp_inlock()
bool iscommand{false};
BSONObj query{};
BSONObj updateobj{};
@@ -259,7 +259,7 @@ public:
/**
* Sets the type of the current network operation.
*/
- void setNetworkOp_inlock(Operation op) {
+ void setNetworkOp_inlock(NetworkOp op) {
_networkOp = op;
_debug.networkOp = op;
}
@@ -267,7 +267,7 @@ public:
/**
* Sets the type of the current logical operation.
*/
- void setLogicalOp_inlock(Operation op) {
+ void setLogicalOp_inlock(LogicalOp op) {
_logicalOp = op;
_debug.logicalOp = op;
}
@@ -317,7 +317,7 @@ public:
* Gets the network operation type. No lock is required if called by the thread executing
* the operation, but the lock must be held if called from another thread.
*/
- Operation getNetworkOp() const {
+ NetworkOp getNetworkOp() const {
return _networkOp;
}
@@ -325,7 +325,7 @@ public:
* Gets the logical operation type. No lock is required if called by the thread executing
* the operation, but the lock must be held if called from another thread.
*/
- Operation getLogicalOp() const {
+ LogicalOp getLogicalOp() const {
return _logicalOp;
}
@@ -499,11 +499,11 @@ private:
long long _end{0};
// _networkOp represents the network-level op code: OP_QUERY, OP_GET_MORE, OP_COMMAND, etc.
- Operation _networkOp{opInvalid}; // only set this through setNetworkOp_inlock() to keep synced
+ NetworkOp _networkOp{opInvalid}; // only set this through setNetworkOp_inlock() to keep synced
// _logicalOp is the logical operation type, ie 'dbQuery' regardless of whether this is an
// OP_QUERY find, a find command using OP_QUERY, or a find command using OP_COMMAND.
// Similarly, the return value will be dbGetMore for both OP_GET_MORE and getMore command.
- Operation _logicalOp{opInvalid}; // only set this through setNetworkOp_inlock() to keep synced
+ LogicalOp _logicalOp{LogicalOp::opInvalid}; // only set this through setNetworkOp_inlock()
bool _isCommand{false};
int _dbprofile{0}; // 0=off, 1=slow, 2=all
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp
index 8732fedefe0..b0da72c5bb8 100644
--- a/src/mongo/db/db_raii.cpp
+++ b/src/mongo/db/db_raii.cpp
@@ -103,7 +103,7 @@ AutoGetCollectionForRead::~AutoGetCollectionForRead() {
auto currentOp = CurOp::get(_txn);
Top::get(_txn->getClient()->getServiceContext())
.record(currentOp->getNS(),
- currentOp->getNetworkOp(),
+ currentOp->getLogicalOp(),
-1, // "read locked"
_timer.micros(),
currentOp->isCommand());
@@ -197,7 +197,7 @@ OldClientContext::~OldClientContext() {
auto currentOp = CurOp::get(_txn);
Top::get(_txn->getClient()->getServiceContext())
.record(currentOp->getNS(),
- currentOp->getNetworkOp(),
+ currentOp->getLogicalOp(),
_txn->lockState()->isWriteLocked() ? 1 : -1,
_timer.micros(),
currentOp->isCommand());
diff --git a/src/mongo/db/dbmessage.cpp b/src/mongo/db/dbmessage.cpp
index 5750542eb26..0be54d0f818 100644
--- a/src/mongo/db/dbmessage.cpp
+++ b/src/mongo/db/dbmessage.cpp
@@ -39,7 +39,7 @@ using std::stringstream;
string Message::toString() const {
stringstream ss;
- ss << "op: " << opToString(operation()) << " len: " << size();
+ ss << "op: " << networkOpToString(operation()) << " len: " << size();
if (operation() >= 2000 && operation() < 2100) {
DbMessage d(*this);
ss << " ns: " << d.getns();
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index bc6481410f1..4506a1f6a14 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -413,7 +413,7 @@ void assembleResponse(OperationContext* txn,
DbResponse& dbresponse,
const HostAndPort& remote) {
// before we lock...
- Operation op = m.operation();
+ NetworkOp op = m.operation();
bool isCommand = false;
DbMessage dbmsg(m);
@@ -496,7 +496,7 @@ void assembleResponse(OperationContext* txn,
// Commands handling code will reset this if the operation is a command
// which is logically a basic CRUD operation like query, insert, etc.
currentOp.setNetworkOp_inlock(op);
- currentOp.setLogicalOp_inlock(op);
+ currentOp.setLogicalOp_inlock(networkOpToLogicalOp(op));
}
OpDebug& debug = currentOp.debug();
@@ -558,7 +558,7 @@ void assembleResponse(OperationContext* txn,
uassert(18663,
str::stream() << "legacy writeOps not longer supported for "
<< "versioned connections, ns: " << nsString.ns()
- << ", op: " << opToString(op)
+ << ", op: " << networkOpToString(op)
<< ", remote: " << remote.toString(),
connInfo == NULL);
}
@@ -577,13 +577,15 @@ void assembleResponse(OperationContext* txn,
}
} catch (const UserException& ue) {
LastError::get(c).setLastError(ue.getCode(), ue.getInfo().msg);
- MONGO_LOG_COMPONENT(3, responseComponent) << " Caught Assertion in " << opToString(op)
- << ", continuing " << ue.toString() << endl;
+ MONGO_LOG_COMPONENT(3, responseComponent) << " Caught Assertion in "
+ << networkOpToString(op) << ", continuing "
+ << ue.toString() << endl;
debug.exceptionInfo = ue.getInfo();
} catch (const AssertionException& e) {
LastError::get(c).setLastError(e.getCode(), e.getInfo().msg);
- MONGO_LOG_COMPONENT(3, responseComponent) << " Caught Assertion in " << opToString(op)
- << ", continuing " << e.toString() << endl;
+ MONGO_LOG_COMPONENT(3, responseComponent) << " Caught Assertion in "
+ << networkOpToString(op) << ", continuing "
+ << e.toString() << endl;
debug.exceptionInfo = e.getInfo();
shouldLog = true;
}
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index 8a6cca1dabb..1893f38b87e 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -80,7 +80,7 @@ void _appendUserInfo(const CurOp& c, BSONObjBuilder& builder, AuthorizationSessi
} // namespace
-void profile(OperationContext* txn, int op) {
+void profile(OperationContext* txn, NetworkOp op) {
// Initialize with 1kb at start in order to avoid realloc later
BufBuilder profileBufBuilder(1024);
@@ -148,8 +148,9 @@ void profile(OperationContext* txn, int op) {
}
}
} catch (const AssertionException& assertionEx) {
- warning() << "Caught Assertion while trying to profile " << opToString(op) << " against "
- << CurOp::get(txn)->getNS() << ": " << assertionEx.toString() << endl;
+ warning() << "Caught Assertion while trying to profile " << networkOpToString(op)
+ << " against " << CurOp::get(txn)->getNS() << ": " << assertionEx.toString()
+ << endl;
}
}
diff --git a/src/mongo/db/introspect.h b/src/mongo/db/introspect.h
index 0bfc3863e42..4f44a1623a1 100644
--- a/src/mongo/db/introspect.h
+++ b/src/mongo/db/introspect.h
@@ -29,6 +29,7 @@
#pragma once
#include "mongo/base/status.h"
+#include "mongo/util/net/message.h"
namespace mongo {
@@ -38,7 +39,7 @@ class OperationContext;
/**
* Invoked when database profile is enabled.
*/
-void profile(OperationContext* txn, int op);
+void profile(OperationContext* txn, NetworkOp op);
/**
* Pre-creates the profile collection for the specified database.
diff --git a/src/mongo/db/stats/top.cpp b/src/mongo/db/stats/top.cpp
index 5b06b7b3c0d..be251870d94 100644
--- a/src/mongo/db/stats/top.cpp
+++ b/src/mongo/db/stats/top.cpp
@@ -36,7 +36,6 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/service_context.h"
#include "mongo/util/log.h"
-#include "mongo/util/net/message.h"
namespace mongo {
@@ -73,7 +72,7 @@ Top& Top::get(ServiceContext* service) {
return getTop(service);
}
-void Top::record(StringData ns, int op, int lockType, long long micros, bool command) {
+void Top::record(StringData ns, LogicalOp logicalOp, int lockType, long long micros, bool command) {
if (ns[0] == '?')
return;
@@ -82,16 +81,16 @@ void Top::record(StringData ns, int op, int lockType, long long micros, bool com
// cout << "record: " << ns << "\t" << op << "\t" << command << endl;
stdx::lock_guard<SimpleMutex> lk(_lock);
- if ((command || op == dbQuery) && ns == _lastDropped) {
+ if ((command || logicalOp == LogicalOp::opQuery) && ns == _lastDropped) {
_lastDropped = "";
return;
}
CollectionData& coll = _usage[hashedNs];
- _record(coll, op, lockType, micros, command);
+ _record(coll, logicalOp, lockType, micros);
}
-void Top::_record(CollectionData& c, int op, int lockType, long long micros, bool command) {
+void Top::_record(CollectionData& c, LogicalOp logicalOp, int lockType, long long micros) {
c.total.inc(micros);
if (lockType > 0)
@@ -99,40 +98,32 @@ void Top::_record(CollectionData& c, int op, int lockType, long long micros, boo
else if (lockType < 0)
c.readLock.inc(micros);
- switch (op) {
- case 0:
+ switch (logicalOp) {
+ case LogicalOp::opInvalid:
// use 0 for unknown, non-specific
break;
- case dbUpdate:
+ case LogicalOp::opUpdate:
c.update.inc(micros);
break;
- case dbInsert:
+ case LogicalOp::opInsert:
c.insert.inc(micros);
break;
- case dbQuery:
- if (command)
- c.commands.inc(micros);
- else
- c.queries.inc(micros);
+ case LogicalOp::opQuery:
+ c.queries.inc(micros);
break;
- case dbGetMore:
+ case LogicalOp::opGetMore:
c.getmore.inc(micros);
break;
- case dbDelete:
+ case LogicalOp::opDelete:
c.remove.inc(micros);
break;
- case dbKillCursors:
+ case LogicalOp::opKillCursors:
break;
- case opReply:
- case dbMsg:
- case dbCommandReply:
- log() << "unexpected op in Top::record: " << op << endl;
- break;
- case dbCommand:
+ case LogicalOp::opCommand:
c.commands.inc(micros);
break;
default:
- log() << "unknown op in Top::record: " << op << endl;
+ MONGO_UNREACHABLE;
}
}
diff --git a/src/mongo/db/stats/top.h b/src/mongo/db/stats/top.h
index 56090b5c408..eb7f6ab9872 100644
--- a/src/mongo/db/stats/top.h
+++ b/src/mongo/db/stats/top.h
@@ -32,6 +32,7 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include "mongo/util/concurrency/mutex.h"
+#include "mongo/util/net/message.h"
#include "mongo/util/string_map.h"
namespace mongo {
@@ -82,7 +83,7 @@ public:
typedef StringMap<CollectionData> UsageMap;
public:
- void record(StringData ns, int op, int lockType, long long micros, bool command);
+ void record(StringData ns, LogicalOp logicalOp, int lockType, long long micros, bool command);
void append(BSONObjBuilder& b);
void cloneMap(UsageMap& out) const;
void collectionDropped(StringData ns);
@@ -90,7 +91,7 @@ public:
private:
void _appendToUsageMap(BSONObjBuilder& b, const UsageMap& map) const;
void _appendStatsEntry(BSONObjBuilder& b, const char* statsName, const UsageData& map) const;
- void _record(CollectionData& c, int op, int lockType, long long micros, bool command);
+ void _record(CollectionData& c, LogicalOp logicalOp, int lockType, long long micros);
mutable SimpleMutex _lock;
UsageMap _usage;
diff --git a/src/mongo/executor/downconvert_find_and_getmore_commands.cpp b/src/mongo/executor/downconvert_find_and_getmore_commands.cpp
index 48204ca2cbb..034c1f133cc 100644
--- a/src/mongo/executor/downconvert_find_and_getmore_commands.cpp
+++ b/src/mongo/executor/downconvert_find_and_getmore_commands.cpp
@@ -59,10 +59,10 @@ namespace {
StatusWith<std::tuple<CursorId, BSONArray>> getBatchFromReply(std::uint32_t requestId,
const Message& response) {
auto header = response.header();
- if (header.getOperation() != mongo::opReply) {
+ if (header.getNetworkOp() != mongo::opReply) {
return {ErrorCodes::ProtocolError,
str::stream() << "Expected to be decoding an OP_REPLY but got "
- << mongo::opToString(header.getOperation())};
+ << mongo::networkOpToString(header.getNetworkOp())};
}
if (header.getResponseTo() != requestId) {
diff --git a/src/mongo/executor/network_interface_asio_command.cpp b/src/mongo/executor/network_interface_asio_command.cpp
index 80deb8cf0d9..0c355f2d4b7 100644
--- a/src/mongo/executor/network_interface_asio_command.cpp
+++ b/src/mongo/executor/network_interface_asio_command.cpp
@@ -145,8 +145,8 @@ ResponseStatus decodeRPC(Message* received,
return Status(ErrorCodes::RPCProtocolNegotiationFailed,
str::stream() << "Mismatched RPC protocols - request was '"
<< requestProtocol.getValue().toString() << "' '"
- << " but reply was '" << opToString(received->operation())
- << "'");
+ << " but reply was '"
+ << networkOpToString(received->operation()) << "'");
}
auto ownedCommandReply = reply->getCommandReply().getOwned();
auto ownedReplyMetadata = reply->getMetadata().getOwned();
diff --git a/src/mongo/rpc/legacy_reply.cpp b/src/mongo/rpc/legacy_reply.cpp
index b516b536503..60d68008558 100644
--- a/src/mongo/rpc/legacy_reply.cpp
+++ b/src/mongo/rpc/legacy_reply.cpp
@@ -47,7 +47,7 @@ LegacyReply::LegacyReply(const Message* message) : _message(std::move(message))
QueryResult::View qr = _message->singleData().view2ptr();
// should be checked by caller.
- invariant(qr.msgdata().getOperation() == opReply);
+ invariant(qr.msgdata().getNetworkOp() == opReply);
uassert(ErrorCodes::BadValue,
str::stream() << "Got legacy command reply with a bad cursorId field,"
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index a0e3b920dde..5043620883b 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -140,8 +140,8 @@ public:
r.process(txn.get());
} catch (const AssertionException& ex) {
LOG(ex.isUserAssertion() ? 1 : 0) << "Assertion failed"
- << " while processing " << opToString(m.operation())
- << " op"
+ << " while processing "
+ << networkOpToString(m.operation()) << " op"
<< " for " << r.getnsIfPresent() << causedBy(ex);
if (r.expectResponse()) {
@@ -153,7 +153,7 @@ public:
LastError::get(cc()).setLastError(ex.getCode(), ex.what());
} catch (const DBException& ex) {
log() << "Exception thrown"
- << " while processing " << opToString(m.operation()) << " op"
+ << " while processing " << networkOpToString(m.operation()) << " op"
<< " for " << r.getnsIfPresent() << causedBy(ex);
if (r.expectResponse()) {
diff --git a/src/mongo/util/net/message.h b/src/mongo/util/net/message.h
index da5433a7f20..eb1afc098aa 100644
--- a/src/mongo/util/net/message.h
+++ b/src/mongo/util/net/message.h
@@ -55,7 +55,7 @@ class MessagingPort;
typedef uint32_t MSGID;
-enum Operation {
+enum NetworkOp {
opInvalid = 0,
opReply = 1, /* reply. responseTo is set. */
dbMsg = 1000, /* generic msg command followed by a std::string */
@@ -70,11 +70,48 @@ enum Operation {
dbCommandReply = 2009,
};
+enum class LogicalOp {
+ opInvalid,
+ opMsg,
+ opUpdate,
+ opInsert,
+ opQuery,
+ opGetMore,
+ opDelete,
+ opKillCursors,
+ opCommand,
+};
+
+static inline LogicalOp networkOpToLogicalOp(NetworkOp networkOp) {
+ switch (networkOp) {
+ case dbMsg:
+ return LogicalOp::opMsg;
+ case dbUpdate:
+ return LogicalOp::opUpdate;
+ case dbInsert:
+ return LogicalOp::opInsert;
+ case dbQuery:
+ return LogicalOp::opQuery;
+ case dbGetMore:
+ return LogicalOp::opGetMore;
+ case dbDelete:
+ return LogicalOp::opDelete;
+ case dbKillCursors:
+ return LogicalOp::opKillCursors;
+ case dbCommand:
+ return LogicalOp::opCommand;
+ default:
+ int op = int(networkOp);
+ massert(34348, str::stream() << "cannot translate opcode " << op, !op);
+ return LogicalOp::opInvalid;
+ }
+}
+
bool doesOpGetAResponse(int op);
-inline const char* opToString(int op) {
- switch (op) {
- case 0:
+inline const char* networkOpToString(NetworkOp networkOp) {
+ switch (networkOp) {
+ case opInvalid:
return "none";
case opReply:
return "reply";
@@ -97,11 +134,37 @@ inline const char* opToString(int op) {
case dbCommandReply:
return "commandReply";
default:
+ int op = static_cast<int>(networkOp);
massert(16141, str::stream() << "cannot translate opcode " << op, !op);
return "";
}
}
+inline const char* logicalOpToString(LogicalOp logicalOp) {
+ switch (logicalOp) {
+ case LogicalOp::opInvalid:
+ return "none";
+ case LogicalOp::opMsg:
+ return "msg";
+ case LogicalOp::opUpdate:
+ return "update";
+ case LogicalOp::opInsert:
+ return "insert";
+ case LogicalOp::opQuery:
+ return "query";
+ case LogicalOp::opGetMore:
+ return "getmore";
+ case LogicalOp::opDelete:
+ return "remove";
+ case LogicalOp::opKillCursors:
+ return "killcursors";
+ case LogicalOp::opCommand:
+ return "command";
+ default:
+ MONGO_UNREACHABLE;
+ }
+}
+
inline bool opIsWrite(int op) {
switch (op) {
case 0:
@@ -244,8 +307,8 @@ public:
return header().getResponseTo();
}
- Operation getOperation() const {
- return Operation(header().getOpCode());
+ NetworkOp getNetworkOp() const {
+ return NetworkOp(header().getOpCode());
}
const char* data() const {
@@ -255,14 +318,14 @@ public:
bool valid() const {
if (getLen() <= 0 || getLen() > (4 * BSONObjMaxInternalSize))
return false;
- if (getOperation() < 0 || getOperation() > 30000)
+ if (getNetworkOp() < 0 || getNetworkOp() > 30000)
return false;
return true;
}
int64_t getCursor() const {
verify(getResponseTo() > 0);
- verify(getOperation() == opReply);
+ verify(getNetworkOp() == opReply);
return ConstDataView(data() + sizeof(int32_t)).read<LittleEndian<int64_t>>();
}
@@ -362,8 +425,8 @@ public:
return _buf ? _buf : _data[0].first;
}
- Operation operation() const {
- return header().getOperation();
+ NetworkOp operation() const {
+ return header().getNetworkOp();
}
MsgData::View singleData() const {