diff options
author | Daniel Gottlieb <daniel.gottlieb@10gen.com> | 2017-06-01 11:19:08 -0400 |
---|---|---|
committer | Daniel Gottlieb <daniel.gottlieb@10gen.com> | 2017-06-01 11:19:08 -0400 |
commit | cd2e5f07df13612b68deea94b82b001fca119373 (patch) | |
tree | e1a8bfd7e413cff5bdaef931ce7f7428c79ce168 | |
parent | 85d4a3a085c67f2258b60b07259db73e2f29ea50 (diff) | |
download | mongo-cd2e5f07df13612b68deea94b82b001fca119373.tar.gz |
SERVER-29210: Manage WiredTiger checkpoints in MongoDB.
Prior to this change, WiredTiger would be started with a configuration that
instructs WiredTiger to start its own checkpoint thread. The parameters
would trigger a checkpoint every 60 seconds or 2GB of data written to the
journal. This patch disables WiredTiger's checkpoint thread and moves the
responsibility to MongoDB.
The checkpoint thread now only checkpoints every 60 seconds (still
configurable with `--syncdelay`). The trigger on the amount of data written
to the journal was removed as an unnecessary mechanism to maintain parity
with.
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 56 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h | 2 |
2 files changed, 56 insertions, 2 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index 91f7f23a407..de7ec75fd60 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -130,6 +130,53 @@ private: AtomicBool _shuttingDown{false}; }; +class WiredTigerKVEngine::WiredTigerCheckpointThread : public BackgroundJob { +public: + explicit WiredTigerCheckpointThread(WiredTigerSessionCache* sessionCache) + : BackgroundJob(false /* deleteSelf */), _sessionCache(sessionCache) {} + + virtual string name() const { + return "WTCheckpointThread"; + } + + virtual void run() { + Client::initThread(name().c_str()); + + LOG(1) << "starting " << name() << " thread"; + + while (!_shuttingDown.load()) { + { + stdx::unique_lock<stdx::mutex> lock(_mutex); + _condvar.wait_for(lock, + stdx::chrono::seconds(static_cast<std::int64_t>( + wiredTigerGlobalOptions.checkpointDelaySecs))); + } + + try { + const bool forceCheckpoint = true; + _sessionCache->waitUntilDurable(forceCheckpoint); + } catch (const UserException& exc) { + invariant(exc.getCode() == ErrorCodes::ShutdownInProgress); + } + } + LOG(1) << "stopping " << name() << " thread"; + } + + void shutdown() { + _shuttingDown.store(true); + _condvar.notify_one(); + wait(); + } + +private: + WiredTigerSessionCache* _sessionCache; + + // _mutex/_condvar used to notify when _shuttingDown is flipped. + stdx::mutex _mutex; + stdx::condition_variable _condvar; + AtomicBool _shuttingDown{false}; +}; + namespace { class TicketServerParameter : public ServerParameter { @@ -228,8 +275,6 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, ss << "log=(enabled=true,archive=true,path=journal,compressor="; ss << wiredTigerGlobalOptions.journalCompressor << "),"; ss << "file_manager=(close_idle_time=100000),"; //~28 hours, will put better fix in 3.1.x - ss << "checkpoint=(wait=" << wiredTigerGlobalOptions.checkpointDelaySecs; - ss << ",log_size=2GB),"; ss << "statistics_log=(wait=" << wiredTigerGlobalOptions.statisticsLogDelaySecs << "),"; ss << "verbose=(recovery_progress),"; } @@ -287,6 +332,11 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, _journalFlusher->go(); } + if (!_readOnly && !_ephemeral) { + _checkpointThread = stdx::make_unique<WiredTigerCheckpointThread>(_sessionCache.get()); + _checkpointThread->go(); + } + _sizeStorerUri = "table:sizeStorer"; WiredTigerSession session(_conn); if (!_readOnly && repair && _hasUri(session.getSession(), _sizeStorerUri)) { @@ -335,6 +385,8 @@ void WiredTigerKVEngine::cleanShutdown() { // these must be the last things we do before _conn->close(); if (_journalFlusher) _journalFlusher->shutdown(); + if (_checkpointThread) + _checkpointThread->shutdown(); _sizeStorer.reset(); _sessionCache->shuttingDown(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index 19663b2b8fa..805756596e9 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -192,6 +192,7 @@ public: private: class WiredTigerJournalFlusher; + class WiredTigerCheckpointThread; Status _salvageIfNeeded(const char* uri); void _checkIdentPath(StringData ident); @@ -215,6 +216,7 @@ private: bool _ephemeral; bool _readOnly; std::unique_ptr<WiredTigerJournalFlusher> _journalFlusher; // Depends on _sizeStorer + std::unique_ptr<WiredTigerCheckpointThread> _checkpointThread; std::string _rsOptions; std::string _indexOptions; |