diff options
author | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2018-06-14 16:43:16 -0400 |
---|---|---|
committer | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2018-06-14 20:05:36 -0400 |
commit | 1115621110be9bd82079f425f766e2350ed5208d (patch) | |
tree | 8389cb2d063a75fc2fc974c239e025b73728b16e | |
parent | 5b8d340cf0877f3e5cdba76e350cdf5fb428e6de (diff) | |
download | mongo-1115621110be9bd82079f425f766e2350ed5208d.tar.gz |
SERVER-35271: Suppress WT compatibility error messages on startup.
(cherry picked from commit 34b3da52dc10216453eed6dd0939f7cb4acc546a)
4 files changed, 86 insertions, 19 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index a2673747fed..39f1ad272e4 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -75,7 +75,6 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" #include "mongo/db/storage/wiredtiger/wiredtiger_size_storer.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_util.h" #include "mongo/platform/atomic_word.h" #include "mongo/stdx/memory.h" #include "mongo/util/background.h" @@ -186,6 +185,7 @@ void openWiredTiger(const std::string& path, return; } + severe() << "Failed to start up WiredTiger under any compatibility version."; if (ret == EINVAL) { fassertFailedNoTrace(28561); } @@ -448,8 +448,7 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, bool ephemeral, bool repair, bool readOnly) - : _eventHandler(WiredTigerUtil::defaultEventHandlers()), - _clockSource(cs), + : _clockSource(cs), _oplogManager(stdx::make_unique<WiredTigerOplogManager>()), _canonicalName(canonicalName), _path(path), @@ -517,7 +516,8 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, string config = ss.str(); log() << "Detected WT journal files. Running recovery from last checkpoint."; log() << "journal to nojournal transition config: " << config; - int ret = wiredtiger_open(path.c_str(), &_eventHandler, config.c_str(), &_conn); + int ret = wiredtiger_open( + path.c_str(), _eventHandler.getWtEventHandler(), config.c_str(), &_conn); if (ret == EINVAL) { fassertFailedNoTrace(28717); } else if (ret != 0) { @@ -539,7 +539,8 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, string config = ss.str(); log() << "wiredtiger_open config: " << config; - openWiredTiger(path, &_eventHandler, config, &_conn, &_fileVersion); + openWiredTiger(path, _eventHandler.getWtEventHandler(), config, &_conn, &_fileVersion); + _eventHandler.setStartupSuccessful(); _wtOpenConfig = config; { @@ -666,7 +667,8 @@ void WiredTigerKVEngine::cleanShutdown() { _conn = nullptr; WT_CONNECTION* conn; - invariantWTOK(wiredtiger_open(_path.c_str(), &_eventHandler, _wtOpenConfig.c_str(), &conn)); + invariantWTOK(wiredtiger_open( + _path.c_str(), _eventHandler.getWtEventHandler(), _wtOpenConfig.c_str(), &conn)); WT_SESSION* session; conn->open_session(conn, nullptr, "", &session); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index 98806dd4222..e0f9e46e59a 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -42,6 +42,7 @@ #include "mongo/db/storage/kv/kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" +#include "mongo/db/storage/wiredtiger/wiredtiger_util.h" #include "mongo/stdx/functional.h" #include "mongo/stdx/mutex.h" #include "mongo/util/elapsed_tracker.h" @@ -283,7 +284,7 @@ private: void _setOldestTimestamp(Timestamp oldestTimestamp, bool force = false); WT_CONNECTION* _conn; - WT_EVENT_HANDLER _eventHandler; + WiredTigerEventHandler _eventHandler; std::unique_ptr<WiredTigerSessionCache> _sessionCache; ClockSource* const _clockSource; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp index bfa26ed8772..0805dcb3b12 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp @@ -381,6 +381,32 @@ size_t WiredTigerUtil::getCacheSizeMB(double requestedCacheSizeGB) { } namespace { +int mdb_handle_error_with_startup_suppression(WT_EVENT_HANDLER* handler, + WT_SESSION* session, + int errorCode, + const char* message) { + WiredTigerEventHandler* wtHandler = reinterpret_cast<WiredTigerEventHandler*>(handler); + + try { + StringData sd(message); + if (!wtHandler->wasStartupSuccessful()) { + // During startup, storage tries different WiredTiger compatibility modes to determine + // the state of the data files before FCV can be read. Suppress the error messages + // regarding expected version compatibility requirements. + if (sd.find("Version incompatibility detected:") != std::string::npos) { + return 0; + } + } + + error() << "WiredTiger error (" << errorCode << ") " << redact(message) + << " Raw: " << message; + fassert(50853, errorCode != WT_PANIC); + } catch (...) { + std::terminate(); + } + return 0; +} + int mdb_handle_error(WT_EVENT_HANDLER* handler, WT_SESSION* session, int errorCode, @@ -415,15 +441,32 @@ int mdb_handle_progress(WT_EVENT_HANDLER* handler, return 0; } -} -WT_EVENT_HANDLER WiredTigerUtil::defaultEventHandlers() { +WT_EVENT_HANDLER defaultEventHandlers() { WT_EVENT_HANDLER handlers = {}; handlers.handle_error = mdb_handle_error; handlers.handle_message = mdb_handle_message; handlers.handle_progress = mdb_handle_progress; return handlers; } +} + +WiredTigerEventHandler::WiredTigerEventHandler() { + WT_EVENT_HANDLER* handler = static_cast<WT_EVENT_HANDLER*>(this); + invariant((void*)this == (void*)handler); + + handler->handle_error = mdb_handle_error_with_startup_suppression; + handler->handle_message = mdb_handle_message; + handler->handle_progress = mdb_handle_progress; + handler->handle_close = nullptr; +} + +WT_EVENT_HANDLER* WiredTigerEventHandler::getWtEventHandler() { + WT_EVENT_HANDLER* ret = static_cast<WT_EVENT_HANDLER*>(this); + invariant((void*)this == (void*)ret); + + return ret; +} WiredTigerUtil::ErrorAccumulator::ErrorAccumulator(std::vector<std::string>* errors) : WT_EVENT_HANDLER(defaultEventHandlers()), diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h index 5817a5855f6..f5a7b4e9ee3 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h @@ -90,6 +90,37 @@ struct WiredTigerItem : public WT_ITEM { } }; +/** + * Returns a WT_EVENT_HANDLER with MongoDB's default handlers. + * The default handlers just log so it is recommended that you consider calling them even if + * you are capturing the output. + * + * There is no default "close" handler. You only need to provide one if you need to call a + * destructor. + */ +class WiredTigerEventHandler : private WT_EVENT_HANDLER { +public: + WiredTigerEventHandler(); + + WT_EVENT_HANDLER* getWtEventHandler(); + + bool wasStartupSuccessful() { + return _startupSuccessful; + } + + void setStartupSuccessful() { + _startupSuccessful = true; + } + +private: + int suppressibleStartupErrorLog(WT_EVENT_HANDLER* handler, + WT_SESSION* sesion, + int errorCode, + const char* message); + + bool _startupSuccessful = false; +}; + class WiredTigerUtil { MONGO_DISALLOW_COPYING(WiredTigerUtil); @@ -183,16 +214,6 @@ public: */ static size_t getCacheSizeMB(double requestedCacheSizeGB); - /** - * Returns a WT_EVENT_HANDER with MongoDB's default handlers. - * The default handlers just log so it is recommended that you consider calling them even if - * you are capturing the output. - * - * There is no default "close" handler. You only need to provide one if you need to call a - * destructor. - */ - static WT_EVENT_HANDLER defaultEventHandlers(); - class ErrorAccumulator : public WT_EVENT_HANDLER { public: ErrorAccumulator(std::vector<std::string>* errors); |