Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tendisplus/commands/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ Expected<std::string> Command::runSessionCmd(Session* sess) {
sess->getCtx()->setArgsBrief(sess->getArgs());
it->second->incrCallTimes();
auto now = nsSinceEpoch();
sess->resetLockWaitTime();
auto guard = MakeGuard([it, now, sess, commandName] {
sess->getCtx()->clearRequestCtx();
auto end = nsSinceEpoch();
Expand Down
3 changes: 3 additions & 0 deletions src/tendisplus/server/segment_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ Expected<DbWithLock> SegmentMgrFnvHash64::getDbWithKeyLock(
}

if (mode != mgl::LockMode::LOCK_NONE) {
auto start = nsSinceEpoch();
auto elk = KeyLock::AquireKeyLock(segId,
chunkId,
key,
mode,
sess,
sess->getServerEntry()->getMGLockMgr(),
lockTimeoutMs);
auto duration = nsSinceEpoch() - start;
sess->addLockWaitTime(duration);
if (!elk.ok()) {
return elk.status();
}
Expand Down
1 change: 1 addition & 0 deletions src/tendisplus/server/server_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ void SlowlogStat::slowlogDataPushEntryIfNeeded(
slowLog << "# Db: " << sess->getCtx()->getDbId() << "\n";
slowLog << "# Query_time: " << duration << "\n";
slowLog << "# Execute_time: " << execTime << "\n";
slowLog << "# LockWait_time: " << sess->getLockWaitTime() << "\n";
slowLog << "# Thread_id: " << getCurThreadId() << "\n";
slowLog << "# Session_id: " << sess->id() << "\n";
slowLog << "# Read_Pack_ts: " << sess->getCtx()->getReadPacketTs() << "\n";
Expand Down
1 change: 1 addition & 0 deletions src/tendisplus/server/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Session::Session(ServerEntry* svr, Type type)
_ctx(std::make_unique<SessionCtx>(this)),
_type(type),
_timestamp(msSinceEpoch()),
_lockWaitTime(0),
_sessId(_idGen.fetch_add(1, std::memory_order_relaxed)),
_inLua(false) {
_aliveCnt.fetch_add(1, std::memory_order_relaxed);
Expand Down
17 changes: 17 additions & 0 deletions src/tendisplus/server/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,29 @@ class Session : public std::enable_shared_from_this<Session> {
return {};
}

uint64_t getLockWaitTime() const {
return _lockWaitTime;
}

void setLockWaitTime(uint64_t time) {
_lockWaitTime = time;
}

void addLockWaitTime(uint64_t time) {
_lockWaitTime += time;
}

void resetLockWaitTime() {
_lockWaitTime = 0;
}

protected:
std::vector<std::string> _args;
ServerEntry* _server;
std::unique_ptr<SessionCtx> _ctx;
Type _type;
uint64_t _timestamp;
uint64_t _lockWaitTime;

private:
mutable std::mutex _baseMutex;
Expand Down