diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2019-05-08 10:49:53 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2019-05-10 09:22:45 -0400 |
commit | fb8394050fc5a8f0fb548f01dcfd606dcf6fda61 (patch) | |
tree | 14b7a5208727039aeac4e3f65224ddc1bf8fb25c | |
parent | 8845fb09ae597dc3eb4cdf85a2c22a9ad31f11f2 (diff) | |
download | mongo-fb8394050fc5a8f0fb548f01dcfd606dcf6fda61.tar.gz |
SERVER-41006 Make replBatchLimitBytes configurable
(cherry picked from commit 887e13622f1e3ffecefbed4f42bae62666680ee4)
-rw-r--r-- | src/mongo/db/repl/data_replicator_external_state_impl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_tail.cpp | 28 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_tail.h | 2 |
3 files changed, 26 insertions, 6 deletions
diff --git a/src/mongo/db/repl/data_replicator_external_state_impl.cpp b/src/mongo/db/repl/data_replicator_external_state_impl.cpp index bd32ead02a5..599e635a4d6 100644 --- a/src/mongo/db/repl/data_replicator_external_state_impl.cpp +++ b/src/mongo/db/repl/data_replicator_external_state_impl.cpp @@ -154,7 +154,7 @@ StatusWith<OplogApplier::Operations> DataReplicatorExternalStateImpl::getNextApp OplogApplier oplogApplier( nullptr, oplogBuffer, nullptr, nullptr, nullptr, nullptr, {}, nullptr); OplogApplier::BatchLimits batchLimits; - batchLimits.bytes = SyncTail::replBatchLimitBytes; + batchLimits.bytes = std::size_t(SyncTail::replBatchLimitBytes.load()); batchLimits.ops = std::size_t(SyncTail::replBatchLimitOperations.load()); return oplogApplier.getNextApplierBatch(opCtx, batchLimits); } diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index e507a9338ab..90e7b7d23ce 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -91,6 +91,7 @@ using std::endl; namespace repl { AtomicInt32 SyncTail::replBatchLimitOperations{5 * 1000}; +AtomicInt32 SyncTail::replBatchLimitBytes{100 * 1024 * 1024}; namespace { @@ -139,6 +140,25 @@ public: } } exportedBatchLimitOperationsParam; +class ExportedBatchLimitBytesParameter + : public ExportedServerParameter<int, ServerParameterType::kStartupAndRuntime> { +public: + ExportedBatchLimitBytesParameter() + : ExportedServerParameter<int, ServerParameterType::kStartupAndRuntime>( + ServerParameterSet::getGlobal(), + "replBatchLimitBytes", + &SyncTail::replBatchLimitBytes) {} + + virtual Status validate(const int& potentialNewValue) { + if (potentialNewValue < (16 * 1024 * 1024) || potentialNewValue > (100 * 1024 * 1024)) { + return Status(ErrorCodes::BadValue, + "replBatchLimitBytes must be between 16MB and 100MB, inclusive"); + } + + return Status::OK(); + } +} exportedBatchLimitBytesParam; + // The oplog entries applied Counter64 opsAppliedStats; ServerStatusMetricField<Counter64> displayOpsApplied("repl.apply.ops", &opsAppliedStats); @@ -324,7 +344,7 @@ std::size_t SyncTail::calculateBatchLimitBytes(OperationContext* opCtx, auto oplogMaxSizeResult = storageInterface->getOplogMaxSize(opCtx, NamespaceString::kRsOplogNamespace); auto oplogMaxSize = fassert(40301, oplogMaxSizeResult); - return std::min(oplogMaxSize / 10, std::size_t(replBatchLimitBytes)); + return std::min(oplogMaxSize / 10, std::size_t(replBatchLimitBytes.load())); } std::unique_ptr<ThreadPool> SyncTail::makeWriterPool() { @@ -840,14 +860,14 @@ private: Client::initThread("ReplBatcher"); BatchLimits batchLimits; - batchLimits.bytes = - calculateBatchLimitBytes(cc().makeOperationContext().get(), _storageInterface); while (true) { batchLimits.slaveDelayLatestTimestamp = _calculateSlaveDelayLatestTimestamp(); - // Check this once per batch since users can change it at runtime. + // Check the limits once per batch since users can change them at runtime. batchLimits.ops = replBatchLimitOperations.load(); + batchLimits.bytes = + calculateBatchLimitBytes(cc().makeOperationContext().get(), _storageInterface); OpQueue ops(batchLimits.ops); // tryPopAndWaitForMore adds to ops and returns true when we need to end a batch early. diff --git a/src/mongo/db/repl/sync_tail.h b/src/mongo/db/repl/sync_tail.h index af12ea68ef3..914252690df 100644 --- a/src/mongo/db/repl/sync_tail.h +++ b/src/mongo/db/repl/sync_tail.h @@ -80,7 +80,7 @@ public: /** * Lower bound of batch limit size (in bytes) returned by calculateBatchLimitBytes(). */ - static const unsigned int replBatchLimitBytes = 100 * 1024 * 1024; + static AtomicInt32 replBatchLimitBytes; /** * Calculates batch limit size (in bytes) using the maximum capped collection size of the oplog |