summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2021-03-03 13:31:10 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-04 01:06:56 +0000
commit68695f96302deff9157af0f822dfa0b48c0bcbc0 (patch)
tree1a4522ee1dcba26587a4f29ebd499b4dde283f4f
parent018b205b9180d05ad858f4976e6e2bc85a7d15e7 (diff)
downloadmongo-68695f96302deff9157af0f822dfa0b48c0bcbc0.tar.gz
SERVER-54921 Fix index out-of-bounds error for bulk ordered time-series inserts
-rw-r--r--src/mongo/db/commands/write_commands/write_commands.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp
index b130b982c86..ce017dc4b04 100644
--- a/src/mongo/db/commands/write_commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands.cpp
@@ -651,6 +651,7 @@ public:
void _commitTimeseriesBucket(OperationContext* opCtx,
const BucketCatalog::BucketId& bucketId,
+ size_t start,
size_t index,
std::vector<BSONObj>* errors,
boost::optional<repl::OpTime>* opTime,
@@ -673,7 +674,7 @@ public:
return;
}
- if (auto error = generateError(opCtx, result, index, errors->size())) {
+ if (auto error = generateError(opCtx, result, start + index, errors->size())) {
errors->push_back(*error);
}
@@ -694,10 +695,10 @@ public:
}
/**
- * Writes to the underlying system.buckets collection. Returns the indices of the batch
- * which were attempted in an update operation, but found no bucket to update. These indices
- * can be passed as the optional 'indices' parameter in a subsequent call to this function,
- * in order to to be retried as inserts.
+ * Writes to the underlying system.buckets collection. Returns the indices, relative to
+ * 'start', of the batch which were attempted in an update operation, but found no bucket to
+ * update. These indices can be passed as the optional 'indices' parameter in a subsequent
+ * call to this function, in order to to be retried as inserts.
*/
std::vector<size_t> _performUnorderedTimeseriesWrites(
OperationContext* opCtx,
@@ -712,6 +713,8 @@ public:
std::vector<std::pair<BucketCatalog::BucketId, size_t>> bucketsToCommit;
std::vector<std::pair<Future<BucketCatalog::CommitInfo>, size_t>> bucketsToWaitOn;
auto insert = [&](size_t index) {
+ invariant(start + index < request().getDocuments().size());
+
auto result =
bucketCatalog.insert(opCtx, ns(), request().getDocuments()[start + index]);
if (auto error = generateError(opCtx, result, index, errors->size())) {
@@ -741,7 +744,8 @@ public:
for (const auto& [bucketId, index] : bucketsToCommit) {
_commitTimeseriesBucket(opCtx,
bucketId,
- start + index,
+ start,
+ index,
errors,
opTime,
electionId,