Skip to content

Commit be39b5a

Browse files
authored
fixes applied to sessions sysview (#8661)
1 parent 5bea49a commit be39b5a

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

ydb/core/kqp/proxy_service/kqp_proxy_service.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,11 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> {
17321732
KQP_PROXY_LOG_D("incoming list sessions request " << ev->Get()->Record.ShortUtf8DebugString());
17331733

17341734
auto result = std::make_unique<TEvKqp::TEvListSessionsResponse>();
1735-
auto startIt = LocalSessions->GetOrderedLowerBound(ev->Get()->Record.GetSessionIdStart());
1735+
1736+
const auto& tenant = ev->Get()->Record.GetTenantName();
1737+
bool checkTenant = (AppData()->TenantName != tenant);
1738+
1739+
auto startIt = LocalSessions->GetOrderedLowerBound(tenant, ev->Get()->Record.GetSessionIdStart());
17361740
auto endIt = LocalSessions->GetOrderedEnd();
17371741
i32 freeSpace = ev->Get()->Record.GetFreeSpace();
17381742

@@ -1743,6 +1747,10 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> {
17431747

17441748
while(startIt != endIt && freeSpace > 0) {
17451749
auto* sessionInfo = startIt->second;
1750+
if (checkTenant && sessionInfo->Database != ev->Get()->Record.GetTenantName()) {
1751+
finished = true;
1752+
break;
1753+
}
17461754

17471755
if (!until.empty()) {
17481756
if (sessionInfo->SessionId > until) {
@@ -1770,7 +1778,8 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> {
17701778
if (finished) {
17711779
result->Record.SetFinished(true);
17721780
} else {
1773-
result->Record.SetContinuationToken(startIt->first);
1781+
Y_ABORT_UNLESS(startIt != endIt);
1782+
result->Record.SetContinuationToken(startIt->first.second);
17741783
result->Record.SetFinished(false);
17751784
}
17761785

ydb/core/kqp/proxy_service/kqp_proxy_service_impl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct TKqpSessionInfo {
150150

151151
class TLocalSessionsRegistry {
152152
THashMap<TString, TKqpSessionInfo> LocalSessions;
153-
std::map<TString, TKqpSessionInfo*> OrderedSessions;
153+
std::map<std::pair<TString, TString>, TKqpSessionInfo*> OrderedSessions;
154154
THashMap<TActorId, TString> TargetIdIndex;
155155
THashSet<TString> ShutdownInFlightSessions;
156156
THashMap<TString, ui32> SessionsCountPerDatabase;
@@ -208,7 +208,7 @@ class TLocalSessionsRegistry {
208208
auto result = LocalSessions.emplace(sessionId,
209209
TKqpSessionInfo(sessionId, workerId, database, dbCounters, std::move(pos),
210210
sessionStartedAt + idleDuration, IdleSessions.end(), pgWire, startedAt));
211-
OrderedSessions.emplace(sessionId, &result.first->second);
211+
OrderedSessions.emplace(std::make_pair(database, sessionId), &result.first->second);
212212
SessionsCountPerDatabase[database]++;
213213
Y_ABORT_UNLESS(result.second, "Duplicate session id!");
214214
TargetIdIndex.emplace(workerId, sessionId);
@@ -302,11 +302,11 @@ class TLocalSessionsRegistry {
302302
return ShutdownInFlightSessions.size();
303303
}
304304

305-
std::map<TString, TKqpSessionInfo*>::const_iterator GetOrderedLowerBound(const TString& continuation) const {
306-
return OrderedSessions.lower_bound(continuation);
305+
std::map<std::pair<TString, TString>, TKqpSessionInfo*>::const_iterator GetOrderedLowerBound(const TString& tenant, const TString& continuation) const {
306+
return OrderedSessions.lower_bound(std::make_pair(tenant, continuation));
307307
}
308308

309-
std::map<TString, TKqpSessionInfo*>::const_iterator GetOrderedEnd() const {
309+
std::map<std::pair<TString, TString>, TKqpSessionInfo*>::const_iterator GetOrderedEnd() const {
310310
return OrderedSessions.end();
311311
}
312312

@@ -339,7 +339,7 @@ class TLocalSessionsRegistry {
339339
}
340340
}
341341

342-
OrderedSessions.erase(sessionId);
342+
OrderedSessions.erase(std::make_pair(it->second.Database, sessionId));
343343
LocalSessions.erase(it);
344344
}
345345

@@ -452,7 +452,7 @@ class TResourcePoolsCache {
452452
return true;
453453
}
454454

455-
const auto databaseInfo = GetDatabaseInfo(database);
455+
const auto databaseInfo = GetDatabaseInfo(database);
456456
return !databaseInfo || !databaseInfo->Serverless;
457457
}
458458

ydb/core/kqp/proxy_service/kqp_session_info.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace NKikimr::NKqp {
66

77
using VSessions = NKikimr::NSysView::Schema::QuerySessions;
88

9+
constexpr size_t QUERY_TEXT_LIMIT = 10_KB;
10+
911
void TKqpSessionInfo::SerializeTo(::NKikimrKqp::TSessionInfo* proto, const TFieldsMap& fieldsMap) const {
1012
if (fieldsMap.NeedField(VSessions::SessionId::ColumnId)) { // 1
1113
proto->SetSessionId(SessionId);
@@ -26,7 +28,12 @@ void TKqpSessionInfo::SerializeTo(::NKikimrKqp::TSessionInfo* proto, const TFiel
2628

2729
// last executed query or currently running query.
2830
if (fieldsMap.NeedField(VSessions::Query::ColumnId)) { // 4
29-
proto->SetQuery(QueryText);
31+
if (QueryText.size() > QUERY_TEXT_LIMIT) {
32+
TString truncatedText = QueryText.substr(0, QUERY_TEXT_LIMIT);
33+
proto->SetQuery(QueryText);
34+
} else {
35+
proto->SetQuery(QueryText);
36+
}
3037
}
3138

3239
if (fieldsMap.NeedField(VSessions::QueryCount::ColumnId)) { // 5

ydb/core/protos/kqp.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ message TEvListSessionsRequest {
325325
repeated uint32 Columns = 5;
326326
optional int64 FreeSpace = 6;
327327
optional int64 Limit = 7;
328+
optional string TenantName = 8;
328329
}
329330

330331
message TEvListSessionsResponse {

ydb/core/sys_view/sessions/sessions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class TSessionsScan : public NKikimr::NSysView::TScanActorBase<TSessionsScan> {
178178
const auto& nodeId = PendingNodes.front();
179179
auto kqpProxyId = NKqp::MakeKqpProxyID(nodeId);
180180
auto req = std::make_unique<NKikimr::NKqp::TEvKqp::TEvListSessionsRequest>();
181+
req->Record.SetTenantName(TenantName);
181182
if (!ContinuationToken.empty()) {
182183
req->Record.SetSessionIdStart(ContinuationToken);
183184
req->Record.SetSessionIdStartInclusive(true);

0 commit comments

Comments
 (0)