summaryrefslogtreecommitdiff
path: root/src/mongo/tools
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2016-06-06 14:08:29 -0400
committerMathias Stearn <mathias@10gen.com>2016-06-22 16:04:36 -0400
commite508ddcb51eec941ae50d9c2efb06b601811dc19 (patch)
treecab51e8665c29d8220b64e7f69a8bbc592ca5339 /src/mongo/tools
parent40f20eca105a5e06a72df583ac654f946e9b058e (diff)
downloadmongo-e508ddcb51eec941ae50d9c2efb06b601811dc19.tar.gz
SERVER-24418 Make Message and BufBuilder use SharedBuffer for memory management
This makes it possible to get owned BSONObj out of a Message without copying. Hooked up to the following places: - Anything using the Fetcher (including oplog fetching on secondaries) - Anything using DBClientInterface::findOne() - Anything using CursorResponse (including Sharded queries) As a simplification, Messages no longer support non-contiguous buffers, or non-owning buffers. The former wasn't used by anything, and the latter was only used by mongosniff only for messages that fit in a single packet.
Diffstat (limited to 'src/mongo/tools')
-rw-r--r--src/mongo/tools/sniffer.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/mongo/tools/sniffer.cpp b/src/mongo/tools/sniffer.cpp
index 255d41c1394..b5081a361ed 100644
--- a/src/mongo/tools/sniffer.cpp
+++ b/src/mongo/tools/sniffer.cpp
@@ -82,6 +82,7 @@ using mongo::BufBuilder;
using mongo::DBClientConnection;
using mongo::MemoryMappedFile;
using std::string;
+namespace MsgData = mongo::MsgData;
#define SNAP_LEN 65535
@@ -176,6 +177,13 @@ map<Connection, map<long long, long long>> mapCursor;
void processMessage(Connection& c, Message& d);
+Message copyToMessage(const char* source) {
+ auto msgLen = MsgData::ConstView(source).getLen();
+ auto msgData = mongo::SharedBuffer::allocate(msgLen);
+ memcpy(msgData.get(), source, msgLen);
+ return Message(std::move(msgData));
+}
+
void got_packet(u_char* args, const struct pcap_pkthdr* header, const u_char* packet) {
const struct sniff_ip* ip = (struct sniff_ip*)(packet + captureHeaderSize);
int size_ip = IP_HL(ip) * 4;
@@ -225,7 +233,7 @@ void got_packet(u_char* args, const struct pcap_pkthdr* header, const u_char* pa
Message m;
if (bytesRemainingInMessage[c] == 0) {
- m.setData(const_cast<char*>(reinterpret_cast<const char*>(payload)), false);
+ m = copyToMessage(reinterpret_cast<const char*>(payload));
if (!m.header().valid()) {
cerr << "Invalid message start, skipping packet." << endl;
return;
@@ -251,8 +259,7 @@ void got_packet(u_char* args, const struct pcap_pkthdr* header, const u_char* pa
}
if (bytesRemainingInMessage[c] > 0)
return;
- m.setData(messageBuilder[c]->buf(), true);
- messageBuilder[c]->decouple();
+ m.setData(messageBuilder[c]->release());
messageBuilder[c].reset();
}
@@ -454,7 +461,7 @@ void processDiagLog(const char* file) {
long read = 0;
while (read < length) {
- Message m(pos, false);
+ Message m = copyToMessage(pos);
int len = m.header().getLen();
DbMessage d(m);
cout << len << " " << d.getns() << endl;