diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2021-11-16 14:45:23 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-19 17:40:46 +0000 |
commit | 88ea6629a5980694ff4f4e83781fb4ae310671c1 (patch) | |
tree | 0771a86ccc9f314e619f068960b9022538a14ca4 | |
parent | 686303404d6faa0dde943deea549005baf46efb4 (diff) | |
download | mongo-88ea6629a5980694ff4f4e83781fb4ae310671c1.tar.gz |
SERVER-61097 SizeStorer flush uses 'operation_timeout_ms' to avoid deadlocks with cache eviction
(cherry picked from commit 57e351357ea73450df84b905674b127508aeb064)
(cherry picked from commit 7c65da785398047cb6569170bc614c99abf4ca07)
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp index e0847eb0444..be5dfca336e 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp @@ -143,8 +143,15 @@ void WiredTigerSizeStorer::flush(bool syncToDisk) { } }); + // To avoid deadlocks with cache eviction, allow the transaction to time itself out. Once + // the time limit has been exceeded on an operation in this transaction, WiredTiger returns + // WT_ROLLBACK for that operation. + std::string txnConfig = "operation_timeout_ms=10"; + if (syncToDisk) { + txnConfig += ",sync=true"; + } WT_SESSION* session = _session.getSession(); - WiredTigerBeginTxnBlock txnOpen(session, syncToDisk ? "sync=true" : nullptr); + WiredTigerBeginTxnBlock txnOpen(session, txnConfig.c_str()); for (auto it = buffer.begin(); it != buffer.end(); ++it) { @@ -162,7 +169,15 @@ void WiredTigerSizeStorer::flush(bool syncToDisk) { WiredTigerItem value(data.objdata(), data.objsize()); _cursor->set_key(_cursor, key.Get()); _cursor->set_value(_cursor, value.Get()); - invariantWTOK(_cursor->insert(_cursor)); + int ret = _cursor->insert(_cursor); + if (ret == WT_ROLLBACK) { + // One of the code paths calling this function is when a session is checked back + // into the session cache. This could involve read-only operations which don't + // except write conflicts. If WiredTiger returns WT_ROLLBACK during the flush, we + // skip flushing. + return; + } + invariantWTOK(ret); } txnOpen.done(); invariantWTOK(session->commit_transaction(session, nullptr)); |