SERVER-103807 Reset _storageExecutionTime when caching sessions (#40756) (#41373)

GitOrigin-RevId: 75c2e0fe928700fe4e52c146fb760388c1d58df5
This commit is contained in:
Gregory Wlodarek 2025-10-10 05:52:56 +11:00 committed by MongoDB Bot
parent c2c5491b61
commit 0048f016e8
3 changed files with 53 additions and 22 deletions

View File

@ -229,6 +229,7 @@ void WiredTigerConnection::_releaseSession(std::unique_ptr<WiredTigerSession> se
invariant(session->cursorsOut() == 0);
session->detachOperationContext();
session->_storageExecutionTime = Microseconds::zero();
{
// Release resources in the session we're about to cache.

View File

@ -307,7 +307,7 @@ private:
Date_t _idleExpireTime;
// Tracks the duration of the last WT_SESSION API call.
// Tracks the cumulative duration of WT_SESSION API calls.
Microseconds _storageExecutionTime;
// A set that contains the undo config strings for any reconfigurations we might have performed

View File

@ -36,14 +36,12 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_session.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
#include "mongo/logv2/log.h"
#include "mongo/unittest/log_test.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/tick_source_mock.h"
#include <cstdint>
#include <limits>
#include <memory>
#include <ostream>
#include <string>
@ -168,6 +166,24 @@ protected:
readAtKey(_readKey++);
}
int64_t getStorageExecutionTime(WiredTigerSession& session) {
// Querying stats also advances the tick source
tickSourceMock.setAdvanceOnRead(Microseconds{0});
WiredTigerStats stats{session};
BSONObj statsObj = stats.toBSON();
auto waitingObj = statsObj["timeWaitingMicros"];
if (waitingObj.eoo()) {
return 0LL;
}
auto storageExecutionTime = waitingObj["storageExecutionMicros"];
if (storageExecutionTime.eoo()) {
return 0LL;
}
return storageExecutionTime.Long();
}
unittest::TempDir _path{"wiredtiger_operation_stats_test"};
std::string _uri{"table:wiredtiger_operation_stats_test"};
ClockSourceMock _clockSource;
@ -314,25 +330,6 @@ TEST_F(WiredTigerStatsTest, Clone) {
}
TEST_F(WiredTigerStatsTest, StorageExecutionTime) {
auto getStorageExecutionTime = [&](WiredTigerSession& session) {
// querying stats also advances the tick source
tickSourceMock.setAdvanceOnRead(Microseconds{0});
WiredTigerStats stats{session};
BSONObj statsObj = stats.toBSON();
auto waitingObj = statsObj["timeWaitingMicros"];
if (waitingObj.eoo()) {
return 0LL;
}
auto storageExecutionTime = waitingObj["storageExecutionMicros"];
if (storageExecutionTime.eoo()) {
return 0LL;
}
return storageExecutionTime.Long();
};
ASSERT_EQ(getStorageExecutionTime(*_session), 0);
tickSourceMock.setAdvanceOnRead(Microseconds{200});
_session->checkpoint(nullptr);
@ -347,5 +344,38 @@ TEST_F(WiredTigerStatsTest, StorageExecutionTime) {
ASSERT_EQ(storageExecutionTime, 400);
}
TEST_F(WiredTigerStatsTest, StorageExecutionTimeReuseCachedSession) {
ASSERT_EQ(_conn->getIdleSessionsCount(), 0);
{
// Creates a session which will be cached.
auto session = _conn->getUninterruptibleSession();
session->setTickSource_forTest(&tickSourceMock);
ASSERT_EQ(getStorageExecutionTime(*session), 0);
tickSourceMock.setAdvanceOnRead(Microseconds{200});
session->checkpoint(nullptr);
auto storageExecutionTime = getStorageExecutionTime(*session);
ASSERT_EQ(storageExecutionTime, 200);
}
// Ensure the session is cached.
ASSERT_EQ(_conn->getIdleSessionsCount(), 1);
{
// Ensure we're reusing the cached session.
auto session = _conn->getUninterruptibleSession();
ASSERT_EQ(_conn->getIdleSessionsCount(), 0);
ASSERT_EQ(getStorageExecutionTime(*session), 0);
tickSourceMock.setAdvanceOnRead(Microseconds{200});
session->checkpoint(nullptr);
auto storageExecutionTime = getStorageExecutionTime(*session);
ASSERT_EQ(storageExecutionTime, 200);
}
}
} // namespace
} // namespace mongo