From 41954217c7c132bb7ad49dff49bdba20681ab36a Mon Sep 17 00:00:00 2001 From: Daniel Gottlieb Date: Thu, 14 Jun 2018 15:05:46 -0400 Subject: SERVER-35271: Suppress WT compatibility error messages on startup. (cherry picked from commit ef999ac2018d29fd7425ea32df03eaab37d4709b) --- .../db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 14 ++++---- .../db/storage/wiredtiger/wiredtiger_kv_engine.h | 3 +- .../db/storage/wiredtiger/wiredtiger_util.cpp | 41 ++++++++++++++++++++-- src/mongo/db/storage/wiredtiger/wiredtiger_util.h | 39 ++++++++++++++------ 4 files changed, 78 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 9c148434c76..493befbfddb 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()), _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; { @@ -668,7 +669,8 @@ void WiredTigerKVEngine::cleanShutdown() { WT_CONNECTION* conn; std::stringstream openConfig; openConfig << _wtOpenConfig << ",log=(archive=false)"; - invariantWTOK(wiredtiger_open(_path.c_str(), &_eventHandler, openConfig.str().c_str(), &conn)); + invariantWTOK(wiredtiger_open( + _path.c_str(), _eventHandler.getWtEventHandler(), openConfig.str().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 _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..d6dda1ba857 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(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,26 @@ 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; } +} + +WT_EVENT_HANDLER* WiredTigerEventHandler::getWtEventHandler() { + WT_EVENT_HANDLER* ret = static_cast(this); + invariant((void*)this == (void*)ret); + + ret->handle_error = mdb_handle_error_with_startup_suppression; + ret->handle_message = mdb_handle_message; + ret->handle_progress = mdb_handle_progress; + + return ret; +} WiredTigerUtil::ErrorAccumulator::ErrorAccumulator(std::vector* 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..a3c1b9deae0 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h @@ -90,6 +90,35 @@ 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: + 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 +212,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* errors); -- cgit v1.2.1