diff options
author | Dan Larkin-York <dan.larkin-york@mongodb.com> | 2022-01-22 04:29:11 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-22 04:58:56 +0000 |
commit | 565edb2589ec3a1f59a0808618a45a0384ffc9c8 (patch) | |
tree | e602548b6ccdd4b7bc416d2336324487e6c464a3 | |
parent | 5aa944a184afa23481a5db2c53f9de8e7d9ce326 (diff) | |
download | mongo-565edb2589ec3a1f59a0808618a45a0384ffc9c8.tar.gz |
SERVER-62794 Fix BucketCatalog memory threshold initialization
-rw-r--r-- | src/mongo/db/timeseries/bucket_catalog.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/timeseries/timeseries.idl | 5 | ||||
-rw-r--r-- | src/mongo/db/timeseries/timeseries_global_options.cpp | 21 | ||||
-rw-r--r-- | src/mongo/db/timeseries/timeseries_global_options.h | 1 |
4 files changed, 24 insertions, 6 deletions
diff --git a/src/mongo/db/timeseries/bucket_catalog.cpp b/src/mongo/db/timeseries/bucket_catalog.cpp index 0b7feabab1c..77e3e7f3490 100644 --- a/src/mongo/db/timeseries/bucket_catalog.cpp +++ b/src/mongo/db/timeseries/bucket_catalog.cpp @@ -644,8 +644,7 @@ void BucketCatalog::_expireIdleBuckets(ExecutionStats* stats, // As long as we still need space and have entries and remaining attempts, close idle buckets. int32_t numClosed = 0; while (!_idleBuckets.empty() && - _memoryUsage.load() > static_cast<std::uint64_t>( - gTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes.load()) && + _memoryUsage.load() > getTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes() && numClosed <= gTimeseriesIdleBucketExpiryMaxCountPerAttempt) { Bucket* bucket = _idleBuckets.back(); diff --git a/src/mongo/db/timeseries/timeseries.idl b/src/mongo/db/timeseries/timeseries.idl index 6d1888a6f38..d3ede8fd3c3 100644 --- a/src/mongo/db/timeseries/timeseries.idl +++ b/src/mongo/db/timeseries/timeseries.idl @@ -50,10 +50,11 @@ server_parameters: validator: { gte: 1 } "timeseriesIdleBucketExpiryMemoryUsageThreshold": description: "The threshold in bytes for bucket catalog memory usage above which idle - buckets will be expired" + buckets will be expired. If set to a non-positive number, the threshold will + be automatically over-written to be 2.5% of system memory." set_at: [ startup, runtime ] cpp_varname: "gTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes" - validator: { gte: 1 } + default: 0 "timeseriesIdleBucketExpiryMaxCountPerAttempt": description: "The maximum number of buckets that may be closed due to expiry at each attempt" set_at: [ startup ] diff --git a/src/mongo/db/timeseries/timeseries_global_options.cpp b/src/mongo/db/timeseries/timeseries_global_options.cpp index 9d3adcb541d..5f4e3193c77 100644 --- a/src/mongo/db/timeseries/timeseries_global_options.cpp +++ b/src/mongo/db/timeseries/timeseries_global_options.cpp @@ -31,7 +31,24 @@ namespace mongo { -AtomicWord<long long> gTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes{static_cast<long long>( - ProcessInfo::getSystemMemSizeMB() * 25 * 1024)}; // ~2.5% of system memory +AtomicWord<long long> gTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes{-1}; + +uint64_t getTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes() { + long long userValue = gTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes.load(); + if (userValue > 0) { + return static_cast<uint64_t>(userValue); + } + + const uint64_t systemBasedValue{ProcessInfo::getSystemMemSizeMB() * 25 * + 1024}; // ~2.5% of system memory + while (!gTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes.compareAndSwap(&userValue, + systemBasedValue)) { + if (userValue > 0) { + return static_cast<uint64_t>(userValue); + } + } + + return systemBasedValue; +} } // namespace mongo diff --git a/src/mongo/db/timeseries/timeseries_global_options.h b/src/mongo/db/timeseries/timeseries_global_options.h index 540d4ebc83b..2e13432e8e9 100644 --- a/src/mongo/db/timeseries/timeseries_global_options.h +++ b/src/mongo/db/timeseries/timeseries_global_options.h @@ -34,5 +34,6 @@ namespace mongo { extern AtomicWord<long long> gTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes; +uint64_t getTimeseriesIdleBucketExpiryMemoryUsageThresholdBytes(); } // namespace mongo |