summaryrefslogtreecommitdiff
path: root/src/mongo/db/timeseries
diff options
context:
space:
mode:
authorDan Larkin-York <dan.larkin-york@mongodb.com>2021-04-06 14:12:33 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-06 14:47:13 +0000
commitef7d6ec2d7090f3a8b0eae9c1c6b91e0dfbd4ce9 (patch)
tree6be53e02083f8e3992f3742c5e5e91105f4e6fe6 /src/mongo/db/timeseries
parent6b9ca9f2f2886ee5f3479d7a3a7f189fa4dd1025 (diff)
downloadmongo-ef7d6ec2d7090f3a8b0eae9c1c6b91e0dfbd4ce9.tar.gz
SERVER-55785 Don't access bucket that no longer exists when aborting a write batch
Diffstat (limited to 'src/mongo/db/timeseries')
-rw-r--r--src/mongo/db/timeseries/bucket_catalog.cpp19
-rw-r--r--src/mongo/db/timeseries/bucket_catalog.h5
2 files changed, 15 insertions, 9 deletions
diff --git a/src/mongo/db/timeseries/bucket_catalog.cpp b/src/mongo/db/timeseries/bucket_catalog.cpp
index 7035cf36beb..727653de2c7 100644
--- a/src/mongo/db/timeseries/bucket_catalog.cpp
+++ b/src/mongo/db/timeseries/bucket_catalog.cpp
@@ -298,7 +298,7 @@ void BucketCatalog::abort(std::shared_ptr<WriteBatch> batch) {
auto lk = _lockExclusive();
if (!_allBuckets.contains(bucket)) {
// Special case, bucket has already been cleared, and we need only abort this batch.
- batch->_abort();
+ batch->_abort(false);
return;
}
@@ -437,13 +437,13 @@ void BucketCatalog::_abort(stdx::unique_lock<Mutex>& lk,
// otherwise try to claim the rights and abort it. If we don't get the rights, then wait
// for the other writer to resolve the batch.
for (const auto& [_, current] : bucket->_batches) {
- current->_abort();
+ current->_abort(true);
}
bucket->_batches.clear();
if (auto& prepared = bucket->_preparedBatch) {
if (prepared == batch) {
- prepared->_abort();
+ prepared->_abort(true);
}
prepared.reset();
}
@@ -1185,11 +1185,16 @@ void BucketCatalog::WriteBatch::_finish(const CommitInfo& info) {
_bucket = nullptr;
}
-void BucketCatalog::WriteBatch::_abort() {
+void BucketCatalog::WriteBatch::_abort(bool canAccessBucket) {
_active = false;
- _promise.setError({ErrorCodes::TimeseriesBucketCleared,
- str::stream() << "Time-series bucket " << _bucket->id() << " for "
- << _bucket->_ns << " was cleared"});
+ std::string bucketIdentification;
+ if (canAccessBucket) {
+ bucketIdentification.append(str::stream()
+ << _bucket->id() << " for " << _bucket->_ns << " ");
+ }
+ _promise.setError(
+ {ErrorCodes::TimeseriesBucketCleared,
+ str::stream() << "Time-series bucket " << bucketIdentification << "was cleared"});
_bucket = nullptr;
}
diff --git a/src/mongo/db/timeseries/bucket_catalog.h b/src/mongo/db/timeseries/bucket_catalog.h
index dd8e5a7efea..501814a64bd 100644
--- a/src/mongo/db/timeseries/bucket_catalog.h
+++ b/src/mongo/db/timeseries/bucket_catalog.h
@@ -136,9 +136,10 @@ public:
/**
* Abandon the write batch and notify any waiters that the bucket has been cleared. Must
- * have commit rights.
+ * have commit rights. Parameter controls whether the function is allowed to access the
+ * bucket.
*/
- void _abort();
+ void _abort(bool canAccessBucket);
Bucket* _bucket;