summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Gorman <bernard.gorman@gmail.com>2020-10-27 20:01:45 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-10-29 21:38:41 +0000
commit022d093fdba4f4b617c80048971ba6b3a6ad386a (patch)
tree85ff5d345cf6b881626a260928da66b63b087d57
parent3a55bbd37a050841bc2791b13489dd66c9bc7c67 (diff)
downloadmongo-022d093fdba4f4b617c80048971ba6b3a6ad386a.tar.gz
SERVER-51853 Always initialize the numInserted out-parameter in AbstractIndexAccessMethod::insertKeys
(cherry picked from commit 8177334703d89a19f38246c5ca95cbf3e5470d91)
-rw-r--r--src/mongo/db/index/index_access_method.cpp7
-rw-r--r--src/mongo/db/index/index_access_method.h8
2 files changed, 13 insertions, 2 deletions
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp
index cc050e63dd8..706218c164d 100644
--- a/src/mongo/db/index/index_access_method.cpp
+++ b/src/mongo/db/index/index_access_method.cpp
@@ -218,11 +218,14 @@ Status AbstractIndexAccessMethod::insertKeys(OperationContext* opCtx,
const InsertDeleteOptions& options,
KeyHandlerFn&& onDuplicateKey,
int64_t* numInserted) {
- bool checkIndexKeySize = shouldCheckIndexKeySize(opCtx);
-
+ // Initialize the 'numInserted' out-parameter to zero in case the caller did not already do so.
+ if (numInserted) {
+ *numInserted = 0;
+ }
// Add all new data keys, and all new multikey metadata keys, into the index. When iterating
// over the data keys, each of them should point to the doc's RecordId. When iterating over
// the multikey metadata keys, they should point to the reserved 'kMultikeyMetadataKeyId'.
+ bool checkIndexKeySize = shouldCheckIndexKeySize(opCtx);
for (const auto keyVec : {&keys, &multikeyMetadataKeys}) {
const auto& recordId = (keyVec == &keys ? loc : kMultikeyMetadataKeyId);
for (const auto& key : *keyVec) {
diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h
index 5fe38414125..5171c7ffef4 100644
--- a/src/mongo/db/index/index_access_method.h
+++ b/src/mongo/db/index/index_access_method.h
@@ -94,6 +94,14 @@ public:
KeyHandlerFn&& onDuplicateKey,
int64_t* numInserted) = 0;
+ /**
+ * Inserts the specified keys into the index, and determines whether these keys should cause the
+ * index to become multikey. If so, this method also handles the task of marking the index as
+ * multikey in the catalog, and sets the path-level multikey information if applicable. The
+ * 'numInserted' output parameter, if non-nullptr, will be reset to the number of keys inserted
+ * by this function call, or to zero in the case of either a non-OK return Status or an empty
+ * 'keys' argument.
+ */
virtual Status insertKeys(OperationContext* opCtx,
const std::vector<BSONObj>& keys,
const std::vector<BSONObj>& multikeyMetadataKeys,