1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
#pragma once
#include <library/cpp/actors/core/actor_bootstrapped.h>
#include <library/cpp/actors/core/mon.h>
#include <ydb/core/base/tablet.h>
#include <ydb/core/base/tablet_pipe.h>
#include <ydb/core/protos/services.pb.h>
#include <ydb/core/tx/schemeshard/schemeshard.h>
#include <ydb/core/tx/tx_proxy/proxy.h>
#include <ydb/core/viewer/protos/viewer.pb.h>
#include <ydb/core/viewer/json/json.h>
#include "viewer.h"
#include "browse.h"
#include "wb_aggregate.h"
namespace NKikimr {
namespace NViewerDB {
using namespace NViewer;
using namespace NActors;
class TBrowseTable : public TBrowseTabletsCommon {
protected:
static const bool WithRetry = false;
using TThis = TBrowseTable;
using TBase = TBrowseTabletsCommon;
TActorId TxProxy = MakeTxProxyID();
public:
TBrowseTable(const TActorId& owner, const IViewer::TBrowseContext& browseContext)
: TBrowseTabletsCommon(owner, browseContext)
{}
void Handle(NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult::TPtr &ev, const TActorContext &ctx) {
DescribeResult.Reset(ev->Release());
++Responses;
ctx.Send(BrowseContext.Owner, new NViewerEvents::TEvBrowseRequestCompleted(TxProxy, TEvTxUserProxy::EvNavigate));
const auto& pbRecord(DescribeResult->GetRecord());
if (pbRecord.GetStatus() == NKikimrScheme::EStatus::StatusSuccess) {
if (pbRecord.HasPathDescription()) {
const auto& pbPathDescription(pbRecord.GetPathDescription());
TVector<ui64> tablets;
tablets.reserve(pbPathDescription.TablePartitionsSize());
for (const auto& partition : pbPathDescription.GetTablePartitions()) {
tablets.emplace_back(partition.GetDatashardId());
}
if (!tablets.empty()) {
Sort(tablets);
tablets.erase(std::unique(tablets.begin(), tablets.end()), tablets.end());
SendTabletRequests(tablets, ctx);
std::copy(tablets.begin(), tablets.end(), std::back_inserter(Tablets));
}
}
} else {
switch (DescribeResult->GetRecord().GetStatus()) {
case NKikimrScheme::EStatus::StatusPathDoesNotExist:
return HandleBadRequest(ctx, "The path is not found");
default:
return HandleBadRequest(ctx, "Error getting schema information");
}
}
if (Responses == Requests) {
ReplyAndDie(ctx);
}
}
void SendTabletRequests(const TVector<TTabletId>& tablets, const TActorContext& ctx) {
TDomainsInfo* domainsInfo = AppData(ctx)->DomainsInfo.Get();
for (auto tabletId : tablets) {
TActorId pipeClient = GetTabletPipe(tabletId, ctx);
NTabletPipe::SendData(ctx, pipeClient, new TEvTablet::TEvGetCounters(), tabletId);
++Requests;
ctx.Send(BrowseContext.Owner, new NViewerEvents::TEvBrowseRequestSent(TxProxy, tabletId, TEvTablet::EvGetCounters));
auto hiveUid = HiveUidFromTabletID(tabletId);
auto hiveTabletId = domainsInfo->GetHive(hiveUid);
pipeClient = GetTabletPipe(hiveTabletId, ctx);
NTabletPipe::SendData(ctx, pipeClient, new TEvHive::TEvLookupChannelInfo(tabletId), tabletId);
++Requests;
ctx.Send(BrowseContext.Owner, new NViewerEvents::TEvBrowseRequestSent(pipeClient, TEvHive::EvLookupChannelInfo));
}
}
STFUNC(StateWork) {
switch (ev->GetTypeRewrite()) {
HFunc(NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult, Handle);
HFunc(TEvTablet::TEvGetCountersResponse, TBase::Handle);
HFunc(TEvHive::TEvChannelInfo, TBase::Handle);
HFunc(TEvBlobStorage::TEvResponseControllerInfo, TBase::Handle);
CFunc(TEvents::TSystem::PoisonPill, HandlePoisonPill);
}
}
void Handle(TEvBlobStorage::TEvResponseControllerInfo::TPtr &ev, const TActorContext &ctx) {
THolder<TEvBlobStorage::TEvResponseControllerInfo> bsResult = ev->Release();
auto& bsGroupInfo = *bsResult->Record.MutableBSGroupInfo();
while (!bsGroupInfo.empty()) {
THolder<NKikimrBlobStorage::TEvResponseBSControllerInfo::TBSGroupInfo> groupInfo(bsGroupInfo.ReleaseLast());
ErasureSpecies.insert(groupInfo->GetErasureSpecies());
for (const auto& vDiskInfo : groupInfo->GetVDiskInfo()) {
VDiskCategories.insert(vDiskInfo.GetVDiskCategory());
PDiskCategories.insert(vDiskInfo.GetPDiskCategory());
Nodes.insert(vDiskInfo.GetNodeId());
PDisks.insert(vDiskInfo.GetPDiskId());
}
GroupInfo[groupInfo->GetGroupId()] = std::move(groupInfo);
}
ctx.Send(BrowseContext.Owner, new NViewerEvents::TEvBrowseRequestCompleted(ev->Sender, TEvBlobStorage::EvRequestControllerInfo));
if (++Responses == Requests) {
ReplyAndDie(ctx);
}
}
virtual void Bootstrap(const TActorContext& ctx) override {
THolder<TEvTxUserProxy::TEvNavigate> request(new TEvTxUserProxy::TEvNavigate());
if (!BrowseContext.UserToken.empty()) {
request->Record.SetUserToken(BrowseContext.UserToken);
}
NKikimrSchemeOp::TDescribePath* record = request->Record.MutableDescribePath();
record->SetPath(Path);
record->SetBackupInfo(true);
request->Record.SetUserToken(BrowseContext.UserToken);
ctx.Send(TxProxy, request.Release());
++Requests;
Become(&TThis::StateWork);
}
virtual void ReplyAndDie(const TActorContext &ctx) override {
NKikimrViewer::TBrowseInfo browseInfo;
NKikimrViewer::TMetaInfo metaInfo;
NKikimrViewer::TMetaCommonInfo& pbCommon = *metaInfo.MutableCommon();
FillCommonData(browseInfo, metaInfo);
if (DescribeResult != nullptr) {
const auto& pbRecord(DescribeResult->GetRecord());
if (pbRecord.HasPathDescription()) {
const auto& pbPathDescription(pbRecord.GetPathDescription());
if (pbPathDescription.HasSelf()) {
const auto& pbSelf(pbPathDescription.GetSelf());
pbCommon.SetOwner(pbSelf.GetOwner());
if (pbSelf.GetCreateStep() != 0) {
pbCommon.SetCreateTime(pbSelf.GetCreateStep());
}
}
if (pbPathDescription.HasTable()) {
const auto& pbTable(pbPathDescription.GetTable());
if (pbTable.HasUniformPartitionsCount()) {
pbCommon.SetPartitions(pbTable.GetUniformPartitionsCount());
}
if (pbTable.SplitBoundarySize() > 0) {
pbCommon.SetPartitions(pbTable.SplitBoundarySize() + 1);
}
if (pbTable.ColumnsSize() > 0) {
NKikimrViewer::TMetaTableInfo& pbMetaTable = *metaInfo.MutableTable();
for (const auto& column : pbTable.GetColumns()) {
auto& pbSchema = *pbMetaTable.AddSchema();
pbSchema.SetName(column.GetName());
pbSchema.SetType(column.GetType());
for (ui32 keyId : pbTable.GetKeyColumnIds()) {
if (keyId == column.GetId()) {
pbSchema.SetKey(true);
break;
}
}
}
}
}
if (pbPathDescription.HasTableStats()) {
const auto& pbTableStats(pbPathDescription.GetTableStats());
pbCommon.SetRowCount(pbTableStats.GetRowCount());
pbCommon.SetAccessTime(pbTableStats.GetLastAccessTime());
pbCommon.SetUpdateTime(pbTableStats.GetLastUpdateTime());
pbCommon.SetImmediateTxCompleted(pbTableStats.GetImmediateTxCompleted());
pbCommon.SetPlannedTxCompleted(pbTableStats.GetPlannedTxCompleted());
pbCommon.SetTxRejectedByOverload(pbTableStats.GetTxRejectedByOverload());
pbCommon.SetTxRejectedBySpace(pbTableStats.GetTxRejectedBySpace());
pbCommon.SetRowUpdates(pbTableStats.GetRowUpdates());
pbCommon.SetRowDeletes(pbTableStats.GetRowDeletes());
pbCommon.SetRowReads(pbTableStats.GetRowReads());
pbCommon.SetRangeReads(pbTableStats.GetRangeReads());
pbCommon.SetRangeReadRows(pbTableStats.GetRangeReadRows());
}
if (pbPathDescription.HasTabletMetrics()) {
const auto& pbTabletMetrics(pbPathDescription.GetTabletMetrics());
auto& pbResources(*pbCommon.MutableResources());
pbResources.SetCPU(pbTabletMetrics.GetCPU());
pbResources.SetMemory(pbTabletMetrics.GetMemory());
pbResources.SetNetwork(pbTabletMetrics.GetNetwork());
pbResources.SetStorage(pbTabletMetrics.GetStorage());
pbResources.SetReadThroughput(pbTabletMetrics.GetReadThroughput());
pbResources.SetWriteThroughput(pbTabletMetrics.GetWriteThroughput());
}
pbCommon.MutableBackup()->MutableLastResults()->CopyFrom(pbPathDescription.GetLastBackupResult());
pbCommon.MutableBackup()->MutableProgress()->CopyFrom(pbPathDescription.GetBackupProgress());
}
}
ctx.Send(Owner, new NViewerEvents::TEvBrowseResponse(std::move(browseInfo), std::move(metaInfo)));
Die(ctx);
}
};
}
}
|