diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2015-12-16 17:04:37 -0500 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2015-12-16 17:04:37 -0500 |
commit | 27692afcd08165ca8087bff7dd3fae754acfcb84 (patch) | |
tree | ff671b7ff220ab7edfb838468d012afe22861012 | |
parent | 33831818603c3c00dee06dd8bfa2bc9bea06a8af (diff) | |
download | mongo-27692afcd08165ca8087bff7dd3fae754acfcb84.tar.gz |
SERVER-21920 Use next_random_sample_size when sampling the oplog.
This allows the random cursor to account for skew in the WiredTiger
B-tree when taking samples for oplog stones.
(cherry picked from commit 4463e0366bac5874e4c527b88f25045d544850a5)
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp | 23 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h | 3 |
2 files changed, 20 insertions, 6 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp index dde48ec8f77..030b2dd7647 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp @@ -383,11 +383,15 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon << " approximately " << estRecordsPerStone << " records totaling to " << estBytesPerStone << " bytes"; + // Inform the random cursor of the number of samples we intend to take. This allows it to + // account for skew in the tree shape. + const std::string extraConfig = str::stream() << "next_random_sample_size=" << numSamples; + // Divide the oplog into 'wholeStones' logical sections, with each section containing // approximately 'estRecordsPerStone'. Do so by oversampling the oplog, sorting the samples in // order of their RecordId, and then choosing the samples expected to be near the right edge of // each logical section. - auto cursor = _rs->getRandomCursor(txn); + auto cursor = _rs->getRandomCursorWithOptions(txn, extraConfig); std::vector<RecordId> oplogEstimates; for (int i = 0; i < numSamples; ++i) { auto record = cursor->next(); @@ -636,8 +640,8 @@ StatusWith<std::string> WiredTigerRecordStore::parseOptionsField(const BSONObj o class WiredTigerRecordStore::RandomCursor final : public RecordCursor { public: - RandomCursor(OperationContext* txn, const WiredTigerRecordStore& rs) - : _cursor(nullptr), _rs(&rs), _txn(txn) { + RandomCursor(OperationContext* txn, const WiredTigerRecordStore& rs, StringData config) + : _cursor(nullptr), _rs(&rs), _txn(txn), _config(config.toString() + ",next_random") { restore(); } @@ -678,8 +682,8 @@ public: WT_SESSION* session = WiredTigerRecoveryUnit::get(_txn)->getSession(_txn)->getSession(); if (!_cursor) { - invariantWTOK( - session->open_cursor(session, _rs->_uri.c_str(), NULL, "next_random", &_cursor)); + invariantWTOK(session->open_cursor( + session, _rs->_uri.c_str(), nullptr, _config.c_str(), &_cursor)); invariant(_cursor); } return true; @@ -699,6 +703,7 @@ private: WT_CURSOR* _cursor; const WiredTigerRecordStore* _rs; OperationContext* _txn; + const std::string _config; }; @@ -1415,7 +1420,13 @@ std::unique_ptr<SeekableRecordCursor> WiredTigerRecordStore::getCursor(Operation } std::unique_ptr<RecordCursor> WiredTigerRecordStore::getRandomCursor(OperationContext* txn) const { - return stdx::make_unique<RandomCursor>(txn, *this); + const char* extraConfig = ""; + return getRandomCursorWithOptions(txn, extraConfig); +} + +std::unique_ptr<RecordCursor> WiredTigerRecordStore::getRandomCursorWithOptions( + OperationContext* txn, StringData extraConfig) const { + return stdx::make_unique<RandomCursor>(txn, *this, extraConfig); } std::vector<std::unique_ptr<RecordCursor>> WiredTigerRecordStore::getManyCursors( diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h index dcd30cf77be..3335e774c4c 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h @@ -150,6 +150,9 @@ public: bool forward) const final; std::unique_ptr<RecordCursor> getRandomCursor(OperationContext* txn) const final; + std::unique_ptr<RecordCursor> getRandomCursorWithOptions(OperationContext* txn, + StringData extraConfig) const; + std::vector<std::unique_ptr<RecordCursor>> getManyCursors(OperationContext* txn) const final; virtual Status truncate(OperationContext* txn); |