Skip to content

Commit 514b2d6

Browse files
Merge f0995a9 into 78d1439
2 parents 78d1439 + f0995a9 commit 514b2d6

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

ydb/core/viewer/protos/viewer.proto

+2-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ message TTenant {
381381
uint64 StorageGroups = 40;
382382
uint64 StorageAllocatedLimit = 41;
383383
Ydb.Cms.DatabaseQuotas DatabaseQuotas = 42;
384-
repeated TStorageUsage StorageUsage = 43;
384+
repeated TStorageUsage TablesStorage = 44;
385+
repeated TStorageUsage DatabaseStorage = 45;
385386
}
386387

387388
message TTenants {

ydb/core/viewer/viewer_tenantinfo.h

+51-13
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ class TJsonTenantInfo : public TViewerPipeClient {
4646
THashMap<TString, std::vector<TNodeId>> TenantNodes;
4747
THashMap<TString, NKikimrViewer::TEvViewerResponse> OffloadMergedTabletStateResponse;
4848
THashMap<TString, NKikimrViewer::TEvViewerResponse> OffloadMergedSystemStateResponse;
49+
THashMap<TString, NKikimrViewer::TStorageUsage::EType> StoragePoolType;
4950
TTabletId RootHiveId = 0;
5051
TString RootId; // id of root domain (tenant)
5152
NKikimrViewer::TTenantInfo Result;
53+
std::optional<TRequestResponse<NSysView::TEvSysView::TEvGetStoragePoolsResponse>> GetStoragePoolsResponse;
5254

5355
struct TStorageQuota {
5456
uint64 SoftQuota = 0;
@@ -124,6 +126,7 @@ class TJsonTenantInfo : public TViewerPipeClient {
124126
if (Storage) {
125127
RequestHiveStorageStats(RootHiveId);
126128
}
129+
GetStoragePoolsResponse = RequestBSControllerPools();
127130

128131
if (Requests == 0) {
129132
ReplyAndPassAway();
@@ -154,9 +157,10 @@ class TJsonTenantInfo : public TViewerPipeClient {
154157
hFunc(TEvViewer::TEvViewerResponse, Handle);
155158
hFunc(TEvents::TEvUndelivered, Undelivered);
156159
hFunc(TEvInterconnect::TEvNodeDisconnected, Disconnected);
157-
hFunc(TEvTabletPipe::TEvClientConnected, TBase::Handle);
160+
hFunc(TEvTabletPipe::TEvClientConnected, Handle);
158161
hFunc(TEvStateStorage::TEvBoardInfo, Handle);
159162
hFunc(NHealthCheck::TEvSelfCheckResultProto, Handle);
163+
hFunc(NSysView::TEvSysView::TEvGetStoragePoolsResponse, Handle);
160164
cFunc(TEvents::TSystem::Wakeup, HandleTimeout);
161165
}
162166
}
@@ -534,6 +538,30 @@ class TJsonTenantInfo : public TViewerPipeClient {
534538
return type;
535539
}
536540

541+
void Handle(TEvTabletPipe::TEvClientConnected::TPtr& ev) {
542+
if (ev->Get()->Status != NKikimrProto::OK) {
543+
TString error = TStringBuilder() << "Failed to establish pipe: " << NKikimrProto::EReplyStatus_Name(ev->Get()->Status);
544+
if (ev->Get()->TabletId == GetBSControllerId()) {
545+
if (GetStoragePoolsResponse.has_value()) {
546+
GetStoragePoolsResponse->Error(error);
547+
}
548+
}
549+
}
550+
TBase::Handle(ev); // all RequestDone() are handled by base handler
551+
}
552+
553+
void Handle(NSysView::TEvSysView::TEvGetStoragePoolsResponse::TPtr& ev) {
554+
GetStoragePoolsResponse->Set(std::move(ev));
555+
556+
if (GetStoragePoolsResponse && GetStoragePoolsResponse->IsOk()) {
557+
for (const NKikimrSysView::TStoragePoolEntry& entry : GetStoragePoolsResponse->Get()->Record.GetEntries()) {
558+
StoragePoolType[entry.GetInfo().GetName()] = GetStorageType(entry.GetInfo().GetKind());
559+
}
560+
}
561+
562+
RequestDone();
563+
}
564+
537565
void ReplyAndPassAway() override {
538566
BLOG_TRACE("ReplyAndPassAway() started");
539567
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
@@ -666,6 +694,7 @@ class TJsonTenantInfo : public TViewerPipeClient {
666694
}
667695

668696
if (Storage) {
697+
THashMap<NKikimrViewer::TStorageUsage::EType, ui64> databaseStorageByType;
669698
auto itHiveStorageStats = HiveStorageStats.find(hiveId);
670699
if (itHiveStorageStats != HiveStorageStats.end()) {
671700
const NKikimrHive::TEvResponseHiveStorageStats& record = itHiveStorageStats->second.Get()->Record;
@@ -675,9 +704,12 @@ class TJsonTenantInfo : public TViewerPipeClient {
675704
uint64 storageGroups = 0;
676705
for (const NKikimrHive::THiveStoragePoolStats& poolStat : record.GetPools()) {
677706
if (poolStat.GetName().StartsWith(tenantBySubDomainKey.GetName())) {
707+
NKikimrViewer::TStorageUsage::EType storageType = StoragePoolType[poolStat.GetName()];
678708
for (const NKikimrHive::THiveStorageGroupStats& groupStat : poolStat.GetGroups()) {
679709
storageAllocatedSize += groupStat.GetAllocatedSize();
680710
storageAvailableSize += groupStat.GetAvailableSize();
711+
databaseStorageByType[storageType] += groupStat.GetAllocatedSize();
712+
databaseStorageByType[storageType] += groupStat.GetAvailableSize();
681713
storageMinAvailableSize = std::min(storageMinAvailableSize, groupStat.GetAvailableSize());
682714
++storageGroups;
683715
}
@@ -690,7 +722,7 @@ class TJsonTenantInfo : public TViewerPipeClient {
690722
tenant.SetStorageGroups(storageGroups);
691723
}
692724

693-
THashMap<NKikimrViewer::TStorageUsage::EType, ui64> storageUsageByType;
725+
THashMap<NKikimrViewer::TStorageUsage::EType, ui64> tablesStorageByType;
694726
THashMap<NKikimrViewer::TStorageUsage::EType, TStorageQuota> storageQuotasByType;
695727

696728
for (const auto& quota : tenant.GetDatabaseQuotas().storage_quotas()) {
@@ -703,11 +735,11 @@ class TJsonTenantInfo : public TViewerPipeClient {
703735
if (entry.DomainDescription) {
704736
for (const auto& poolUsage : entry.DomainDescription->Description.GetDiskSpaceUsage().GetStoragePoolsUsage()) {
705737
auto type = GetStorageType(poolUsage.GetPoolKind());
706-
storageUsageByType[type] += poolUsage.GetTotalSize();
738+
tablesStorageByType[type] += poolUsage.GetTotalSize();
707739
}
708740

709-
if (storageUsageByType.empty() && entry.DomainDescription->Description.HasDiskSpaceUsage()) {
710-
storageUsageByType[GuessStorageType(entry.DomainDescription->Description)] =
741+
if (tablesStorageByType.empty() && entry.DomainDescription->Description.HasDiskSpaceUsage()) {
742+
tablesStorageByType[GuessStorageType(entry.DomainDescription->Description)] =
711743
entry.DomainDescription->Description.GetDiskSpaceUsage().GetTables().GetTotalSize();
712744
}
713745

@@ -718,17 +750,23 @@ class TJsonTenantInfo : public TViewerPipeClient {
718750
}
719751
}
720752

721-
for (const auto& [type, size] : storageUsageByType) {
722-
auto& storageUsage = *tenant.AddStorageUsage();
723-
storageUsage.SetType(type);
724-
storageUsage.SetSize(size);
753+
for (const auto& [type, size] : tablesStorageByType) {
725754
auto it = storageQuotasByType.find(type);
726-
if (it != storageQuotasByType.end()) {
727-
storageUsage.SetLimit(it->second.HardQuota);
728-
storageUsage.SetSoftQuota(it->second.SoftQuota);
729-
storageUsage.SetHardQuota(it->second.HardQuota);
755+
if (it != storageQuotasByType.end() && it->second.SoftQuota) {
756+
auto& tablesStorage = *tenant.AddTablesStorage();
757+
tablesStorage.SetType(type);
758+
tablesStorage.SetSize(size);
759+
tablesStorage.SetLimit(it->second.SoftQuota);
760+
tablesStorage.SetSoftQuota(it->second.SoftQuota);
761+
tablesStorage.SetHardQuota(it->second.HardQuota);
730762
}
731763
}
764+
765+
for (const auto& [type, size] : databaseStorageByType) {
766+
auto& databaseStorage = *tenant.AddDatabaseStorage();
767+
databaseStorage.SetType(type);
768+
databaseStorage.SetSize(size);
769+
}
732770
}
733771

734772
THashSet<TNodeId> tenantNodes;

0 commit comments

Comments
 (0)