diff options
author | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2018-11-13 15:38:54 -0500 |
---|---|---|
committer | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2018-11-15 08:46:53 -0500 |
commit | 014ba2b0a86281a7bd52e4c99a25d10915e137c1 (patch) | |
tree | fa8c58d7b4d0d5d102b20bd48a73fb6b3d9e4a2f /src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp | |
parent | ffe84f86f30cbfc356365d6a6755fee74ad85b2b (diff) | |
download | mongo-014ba2b0a86281a7bd52e4c99a25d10915e137c1.tar.gz |
SERVER-37483: Ensure correct table logging configuration on startup.
Diffstat (limited to 'src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp')
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp index 6863dfeb71b..c302e6acfa2 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp @@ -553,6 +553,43 @@ bool WiredTigerUtil::useTableLogging(NamespaceString ns, bool replEnabled) { return true; } +Status WiredTigerUtil::setTableLogging(OperationContext* opCtx, const std::string& uri, bool on) { + // Try to close as much as possible to avoid EBUSY errors. + WiredTigerRecoveryUnit::get(opCtx)->getSession()->closeAllCursors(uri); + WiredTigerSessionCache* sessionCache = WiredTigerRecoveryUnit::get(opCtx)->getSessionCache(); + sessionCache->closeAllCursors(uri); + + // Use a dedicated session for alter operations to avoid transaction issues. + WiredTigerSession session(sessionCache->conn()); + return setTableLogging(session.getSession(), uri, on); +} + +Status WiredTigerUtil::setTableLogging(WT_SESSION* session, const std::string& uri, bool on) { + std::string setting; + if (on) { + setting = "log=(enabled=true)"; + } else { + setting = "log=(enabled=false)"; + } + + int ret = session->alter(session, uri.c_str(), setting.c_str()); + if (ret) { + // `setTableLogging` can be called even when the table is in the desired state. WT can + // return EBUSY if it cannot access the table to be altered before it knows whether + // there's anything to change. Assert that if alter call returned an error, the table is + // in the expected state. + std::string existingMetadata = getMetadataRaw(session, uri).getValue(); + if (existingMetadata.find(setting) == std::string::npos) { + severe() << "Failed to update log setting. Uri: " << uri << " Enable? " << on + << " Ret: " << ret << " MD: " << redact(existingMetadata) + << " Msg: " << session->strerror(session, ret); + fassertFailed(50756); + } + } + + return Status::OK(); +} + Status WiredTigerUtil::exportTableToBSON(WT_SESSION* session, const std::string& uri, const std::string& config, |