diff options
author | George Wangensteen <george.wangensteen@mongodb.com> | 2021-10-13 19:38:12 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-13 20:19:56 +0000 |
commit | b429d5dda98bbe18ab0851ffd1729d3b57fc8a4e (patch) | |
tree | 9bfc2b28acfa5ae9e33863ccb2e1922f3faea038 /src/mongo/s/query/cluster_cursor_manager.cpp | |
parent | d302f66d4ccd9bf2478518cacce5863dcc2f0c12 (diff) | |
download | mongo-b429d5dda98bbe18ab0851ffd1729d3b57fc8a4e.tar.gz |
SERVER-58503 Kill open cursors for a connection when a load balanced connection on mongos is closed
Diffstat (limited to 'src/mongo/s/query/cluster_cursor_manager.cpp')
-rw-r--r-- | src/mongo/s/query/cluster_cursor_manager.cpp | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/src/mongo/s/query/cluster_cursor_manager.cpp b/src/mongo/s/query/cluster_cursor_manager.cpp index dd0a484c085..72422330bfe 100644 --- a/src/mongo/s/query/cluster_cursor_manager.cpp +++ b/src/mongo/s/query/cluster_cursor_manager.cpp @@ -235,6 +235,7 @@ StatusWith<CursorId> ClusterCursorManager::registerCursor( cursorLifetime, now, authenticatedUsers, + opCtx->getClient()->getUUID(), opCtx->getOperationKey())); invariant(emplaceResult.second); _log.push({LogEvent::Type::kRegisterComplete, cursorId, now, nss}); @@ -411,46 +412,36 @@ void ClusterCursorManager::detachAndKillCursor(stdx::unique_lock<Latch> lk, std::size_t ClusterCursorManager::killMortalCursorsInactiveSince(OperationContext* opCtx, Date_t cutoff) { - const auto now = _clockSource->now(); - stdx::unique_lock<Latch> lk(_mutex); - - auto pred = [cutoff](CursorId cursorId, const CursorEntry& entry) -> bool { - if (entry.getLifetimeType() == CursorLifetime::Immortal || - entry.getOperationUsingCursor() || - (entry.getLsid() && !enableTimeoutOfInactiveSessionCursors.load())) { - return false; - } - - bool res = entry.getLastActive() <= cutoff; + return killCursorsSatisfying( + opCtx, [cutoff](CursorId cursorId, const CursorEntry& entry) -> bool { + if (entry.getLifetimeType() == CursorLifetime::Immortal || + entry.getOperationUsingCursor() || + (entry.getLsid() && !enableTimeoutOfInactiveSessionCursors.load())) { + return false; + } - if (res) { - LOGV2(22837, - "Cursor timed out", - "cursorId"_attr = cursorId, - "idleSince"_attr = entry.getLastActive().toString()); - } + bool res = entry.getLastActive() <= cutoff; - return res; - }; + if (res) { + LOGV2(22837, + "Cursor timed out", + "cursorId"_attr = cursorId, + "idleSince"_attr = entry.getLastActive().toString()); + } - return killCursorsSatisfying(std::move(lk), opCtx, std::move(pred), now); + return res; + }); } void ClusterCursorManager::killAllCursors(OperationContext* opCtx) { - const auto now = _clockSource->now(); - stdx::unique_lock<Latch> lk(_mutex); - auto pred = [](CursorId, const CursorEntry&) -> bool { return true; }; - - killCursorsSatisfying(std::move(lk), opCtx, std::move(pred), now); + killCursorsSatisfying(opCtx, [](CursorId, const CursorEntry&) -> bool { return true; }); } std::size_t ClusterCursorManager::killCursorsSatisfying( - stdx::unique_lock<Latch> lk, - OperationContext* opCtx, - std::function<bool(CursorId, const CursorEntry&)> pred, - Date_t now) { + OperationContext* opCtx, const std::function<bool(CursorId, const CursorEntry&)>& pred) { invariant(opCtx); - invariant(lk.owns_lock()); + const auto now = _clockSource->now(); + stdx::unique_lock<Latch> lk(_mutex); std::size_t nKilled = 0; _log.push( |