summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorAdam Midvidy <amidvidy@gmail.com>2015-10-22 10:34:51 -0400
committerAdam Midvidy <amidvidy@gmail.com>2015-10-30 15:47:26 -0400
commit791c412874ce87d9cc1eac75edce8116a9d40640 (patch)
treecdaaeaefd1d093d88ff9a5332a68a8e440b124fa /src/mongo/db
parente62e2e71eff397caf22a0da13ac4669a8546b298 (diff)
downloadmongo-791c412874ce87d9cc1eac75edce8116a9d40640.tar.gz
SERVER-20609 do not heap allocate Message
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/db.cpp6
-rw-r--r--src/mongo/db/dbdirectclient.cpp6
-rw-r--r--src/mongo/db/dbmessage.cpp6
-rw-r--r--src/mongo/db/dbmessage.h11
-rw-r--r--src/mongo/db/dbwebserver.cpp4
-rw-r--r--src/mongo/db/ftdc/SConscript1
-rw-r--r--src/mongo/db/instance.cpp38
7 files changed, 29 insertions, 43 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index 4f2d3676f19..ce1a9bfc4a3 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -173,10 +173,10 @@ public:
// results after the response reaches the client
}
- if (dbresponse.response) {
- port->reply(m, *dbresponse.response, dbresponse.responseTo);
+ if (!dbresponse.response.empty()) {
+ port->reply(m, dbresponse.response, dbresponse.responseTo);
if (dbresponse.exhaustNS.size() > 0) {
- MsgData::View header = dbresponse.response->header();
+ MsgData::View header = dbresponse.response.header();
QueryResult::View qr = header.view2ptr();
long long cursorid = qr.getCursorId();
if (cursorid) {
diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp
index 244669481c5..519cade63ad 100644
--- a/src/mongo/db/dbdirectclient.cpp
+++ b/src/mongo/db/dbdirectclient.cpp
@@ -121,11 +121,11 @@ bool DBDirectClient::call(Message& toSend, Message& response, bool assertOk, str
DbResponse dbResponse;
CurOp curOp(_txn);
assembleResponse(_txn, toSend, dbResponse, dummyHost);
- verify(dbResponse.response);
+ verify(!dbResponse.response.empty());
// can get rid of this if we make response handling smarter
- dbResponse.response->concat();
- response = std::move(*dbResponse.response);
+ dbResponse.response.concat();
+ response = std::move(dbResponse.response);
return true;
}
diff --git a/src/mongo/db/dbmessage.cpp b/src/mongo/db/dbmessage.cpp
index eb50ecb063a..5750542eb26 100644
--- a/src/mongo/db/dbmessage.cpp
+++ b/src/mongo/db/dbmessage.cpp
@@ -201,9 +201,9 @@ void replyToQuery(int queryResultFlags,
}
void replyToQuery(int queryResultFlags, Message& m, DbResponse& dbresponse, BSONObj obj) {
- Message* resp = new Message();
- replyToQuery(queryResultFlags, *resp, obj);
- dbresponse.response = resp;
+ Message resp;
+ replyToQuery(queryResultFlags, resp, obj);
+ dbresponse.response = std::move(resp);
dbresponse.responseTo = m.header().getId();
}
diff --git a/src/mongo/db/dbmessage.h b/src/mongo/db/dbmessage.h
index aa74fd59ffb..2f0c6b6645b 100644
--- a/src/mongo/db/dbmessage.h
+++ b/src/mongo/db/dbmessage.h
@@ -312,16 +312,11 @@ public:
* A response to a DbMessage.
*/
struct DbResponse {
- Message* response;
+ Message response;
MSGID responseTo;
std::string exhaustNS; /* points to ns if exhaust mode. 0=normal mode*/
- DbResponse(Message* r, MSGID rt) : response(r), responseTo(rt) {}
- DbResponse() {
- response = 0;
- }
- ~DbResponse() {
- delete response;
- }
+ DbResponse(Message r, MSGID rt) : response(std::move(r)), responseTo(rt) {}
+ DbResponse() = default;
};
void replyToQuery(int queryResultFlags,
diff --git a/src/mongo/db/dbwebserver.cpp b/src/mongo/db/dbwebserver.cpp
index 1ad6e54a236..b60e1dd77c3 100644
--- a/src/mongo/db/dbwebserver.cpp
+++ b/src/mongo/db/dbwebserver.cpp
@@ -280,13 +280,13 @@ public:
.setCommandArgs(cmdObj);
auto cmdRequestMsg = requestBuilder.done();
- rpc::CommandRequest cmdRequest{cmdRequestMsg.get()};
+ rpc::CommandRequest cmdRequest{&cmdRequestMsg};
rpc::CommandReplyBuilder cmdReplyBuilder{};
Command::execCommand(txn, c, cmdRequest, &cmdReplyBuilder);
auto cmdReplyMsg = cmdReplyBuilder.done();
- rpc::CommandReply cmdReply{cmdReplyMsg.get()};
+ rpc::CommandReply cmdReply{&cmdReplyMsg};
responseCode = 200;
diff --git a/src/mongo/db/ftdc/SConscript b/src/mongo/db/ftdc/SConscript
index 1527dbdd5f9..b2ff0255bfb 100644
--- a/src/mongo/db/ftdc/SConscript
+++ b/src/mongo/db/ftdc/SConscript
@@ -63,4 +63,3 @@ env.CppUnitTest(
'ftdc',
],
)
-
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index 59e3bebb214..e752ae92fa6 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -260,9 +260,9 @@ static void receivedCommand(OperationContext* txn,
auto response = builder.done();
- op->debug().responseLength = response->header().dataLen();
+ op->debug().responseLength = response.header().dataLen();
- dbResponse.response = response.release();
+ dbResponse.response = std::move(response);
dbResponse.responseTo = responseTo;
}
@@ -301,9 +301,9 @@ void receivedRpc(OperationContext* txn, Client& client, DbResponse& dbResponse,
auto response = replyBuilder.done();
- curOp->debug().responseLength = response->header().dataLen();
+ curOp->debug().responseLength = response.header().dataLen();
- dbResponse.response = response.release();
+ dbResponse.response = std::move(response);
dbResponse.responseTo = responseTo;
}
@@ -378,7 +378,6 @@ static void receivedQuery(OperationContext* txn,
DbMessage d(m);
QueryMessage q(d);
- unique_ptr<Message> resp(new Message());
CurOp& op = *CurOp::get(txn);
@@ -388,16 +387,13 @@ static void receivedQuery(OperationContext* txn,
audit::logQueryAuthzCheck(client, nss, q.query, status.code());
uassertStatusOK(status);
- dbResponse.exhaustNS = runQuery(txn, q, nss, *resp);
- verify(!resp->empty());
+ dbResponse.exhaustNS = runQuery(txn, q, nss, dbResponse.response);
} catch (const AssertionException& exception) {
- resp.reset(new Message());
- generateLegacyQueryErrorResponse(&exception, q, &op, resp.get());
+ dbResponse.response.reset();
+ generateLegacyQueryErrorResponse(&exception, q, &op, &dbResponse.response);
}
- op.debug().responseLength = resp->header().dataLen();
-
- dbResponse.response = resp.release();
+ op.debug().responseLength = dbResponse.response.header().dataLen();
dbResponse.responseTo = responseTo;
}
@@ -536,13 +532,11 @@ void assembleResponse(OperationContext* txn,
log(LogComponent::kQuery) << curTimeMillis64() % 10000
<< " long msg received, len:" << len << endl;
- Message* resp = new Message();
if (strcmp("end", p) == 0)
- resp->setData(opReply, "dbMsg end no longer supported");
+ dbresponse.response.setData(opReply, "dbMsg end no longer supported");
else
- resp->setData(opReply, "i am fine - dbMsg deprecated");
+ dbresponse.response.setData(opReply, "i am fine - dbMsg deprecated");
- dbresponse.response = resp;
dbresponse.responseTo = m.header().getId();
} else {
try {
@@ -923,17 +917,15 @@ bool receivedGetMore(OperationContext* txn, DbResponse& dbresponse, Message& m,
curop.debug().exceptionInfo = e.getInfo();
replyToQuery(ResultFlag_ErrSet, m, dbresponse, errObj);
- curop.debug().responseLength = dbresponse.response->header().dataLen();
+ curop.debug().responseLength = dbresponse.response.header().dataLen();
curop.debug().nreturned = 1;
return false;
}
- Message* resp = new Message();
- resp->setData(msgdata.view2ptr(), true);
- curop.debug().responseLength = resp->header().dataLen();
+ dbresponse.response.setData(msgdata.view2ptr(), true);
+ curop.debug().responseLength = dbresponse.response.header().dataLen();
curop.debug().nreturned = msgdata.getNReturned();
- dbresponse.response = resp;
dbresponse.responseTo = m.header().getId();
if (exhaust) {
@@ -1106,11 +1098,11 @@ static void insertSystemIndexes(OperationContext* txn, DbMessage& d, CurOp& curO
.setMetadata(rpc::makeEmptyMetadata())
.setCommandArgs(cmdObj)
.done();
- rpc::LegacyRequest cmdRequest{cmdRequestMsg.get()};
+ rpc::LegacyRequest cmdRequest{&cmdRequestMsg};
rpc::LegacyReplyBuilder cmdReplyBuilder{};
Command::execCommand(txn, createIndexesCmd, cmdRequest, &cmdReplyBuilder);
auto cmdReplyMsg = cmdReplyBuilder.done();
- rpc::LegacyReply cmdReply{cmdReplyMsg.get()};
+ rpc::LegacyReply cmdReply{&cmdReplyMsg};
uassertStatusOK(Command::getStatusFromCommandResult(cmdReply.getCommandReply()));
} catch (const DBException& ex) {
LastError::get(txn->getClient()).setLastError(ex.getCode(), ex.getInfo().msg);