summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2020-09-08 15:15:11 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-08 20:17:50 +0000
commitf2a4792e6bea5d403dcf3474698312c7178ece86 (patch)
treea331c214d7157948ac349839f025233aa0ea8c59 /src/mongo/db/storage
parentd9227bf6bbcc1918c954ef2485e12157e2349fbf (diff)
downloadmongo-f2a4792e6bea5d403dcf3474698312c7178ece86.tar.gz
SERVER-48067 Reduce memory consumption for unique index builds with large numbers of non-unique keys
(cherry picked from commit 3c2951938d65667d675c48511d9d1046655809a5)
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r--src/mongo/db/storage/key_string.cpp9
-rw-r--r--src/mongo/db/storage/key_string.h7
2 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/db/storage/key_string.cpp b/src/mongo/db/storage/key_string.cpp
index 627f804b2f4..b041cba850f 100644
--- a/src/mongo/db/storage/key_string.cpp
+++ b/src/mongo/db/storage/key_string.cpp
@@ -2564,6 +2564,15 @@ int compare(const char* leftBuf, const char* rightBuf, size_t leftSize, size_t r
return leftSize < rightSize ? -1 : 1;
}
+void Value::serializeWithoutRecordId(BufBuilder& buf) const {
+ dassert(decodeRecordIdAtEnd(_buffer.get(), _ksSize).isValid());
+
+ const int32_t sizeWithoutRecordId = sizeWithoutRecordIdAtEnd(_buffer.get(), _ksSize);
+ buf.appendNum(sizeWithoutRecordId); // Serialize size of KeyString
+ buf.appendBuf(_buffer.get(), sizeWithoutRecordId); // Serialize KeyString
+ buf.appendBuf(_buffer.get() + _ksSize, _bufSize - _ksSize); // Serialize TypeBits
+}
+
template class BuilderBase<BufBuilder>;
template class BuilderBase<StackBufBuilder>;
diff --git a/src/mongo/db/storage/key_string.h b/src/mongo/db/storage/key_string.h
index 33a57c2853a..b803c6ecf62 100644
--- a/src/mongo/db/storage/key_string.h
+++ b/src/mongo/db/storage/key_string.h
@@ -369,6 +369,13 @@ public:
buf.appendBuf(_buffer.get(), _bufSize); // Serialize Keystring + Typebits
}
+ /**
+ * Serializes this Value, excluing the RecordId, into a storable format with TypeBits
+ * information. The serialized format takes the following form:
+ * [keystring size][keystring encoding][typebits encoding]
+ */
+ void serializeWithoutRecordId(BufBuilder& buf) const;
+
// Deserialize the Value from a serialized format.
static Value deserialize(BufReader& buf, KeyString::Version version) {
const int32_t sizeOfKeystring = buf.read<LittleEndian<int32_t>>();