summaryrefslogtreecommitdiff
path: root/src/mongo/s/write_ops/batch_write_op.cpp
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2019-05-30 11:28:49 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2019-05-31 10:08:25 -0400
commit182f15f37344118b33419c05820c2753d06191ed (patch)
tree7f44e53c1d4305f8a943845a4dd1e986d2e36a92 /src/mongo/s/write_ops/batch_write_op.cpp
parent7ffc3e775f941622e8b3f1e7eb768594d4687820 (diff)
downloadmongo-182f15f37344118b33419c05820c2753d06191ed.tar.gz
SERVER-41316 Account for constants in UpdateOpEntry size estimate
Diffstat (limited to 'src/mongo/s/write_ops/batch_write_op.cpp')
-rw-r--r--src/mongo/s/write_ops/batch_write_op.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp
index 74e75276f7c..7c877882186 100644
--- a/src/mongo/s/write_ops/batch_write_op.cpp
+++ b/src/mongo/s/write_ops/batch_write_op.cpp
@@ -188,10 +188,17 @@ int getWriteSizeBytes(const WriteOp& writeOp) {
estSize += UpdateOpEntry::kUpsertFieldName.size() + boolSize;
estSize += UpdateOpEntry::kMultiFieldName.size() + boolSize;
- // Add the sizes of the 'q' and 'u' fields, plus the constant updateOp overhead size.
+ // Add the sizes of the 'q' and 'u' fields.
estSize += (UpdateOpEntry::kQFieldName.size() + item.getUpdate().getQ().objsize() +
- UpdateOpEntry::kUFieldName.size() + item.getUpdate().getU().objsize() +
- kEstUpdateOverheadBytes);
+ UpdateOpEntry::kUFieldName.size() + item.getUpdate().getU().objsize());
+
+ // Add the size of the 'c' field if present.
+ if (auto constants = item.getUpdate().getC()) {
+ estSize += UpdateOpEntry::kCFieldName.size() + item.getUpdate().getC()->objsize();
+ }
+
+ // Finally, add the constant updateOp overhead size.
+ estSize += kEstUpdateOverheadBytes;
// When running a debug build, verify that estSize is at least the BSON serialization size.
dassert(estSize >= item.getUpdate().toBSON().objsize());