Skip to content

Commit b4d20ec

Browse files
authored
Simplify build stats by removing obtain-release resources on each pause (#26264)
1 parent dc0256d commit b4d20ec

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

ydb/core/tx/datashard/datashard__stats.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,16 @@ class TTableStatsCoroBuilder : public TActorCoroImpl, private IPages, TTableStat
9999
PagesSize += info->GetPageSize(pageId);
100100
Send(MakeSharedPageCacheId(), new NSharedCache::TEvRequest(NSharedCache::EPriority::Bkgr, info->PageCollection, { pageId }));
101101

102-
Spent->Alter(false); // pause measurement
103-
ReleaseResources();
104-
102+
Interrupt();
105103
auto ev = WaitForSpecificEvent<NSharedCache::TEvResult>(&TTableStatsCoroBuilder::ProcessUnexpectedEvent);
106-
auto msg = ev->Get();
107-
108-
if (msg->Status != NKikimrProto::OK) {
104+
if (auto status = ev->Get()->Status; status != NKikimrProto::OK) {
109105
LOG_ERROR_S(GetActorContext(), NKikimrServices::TABLET_STATS_BUILDER, "Failed to build at datashard "
110-
<< TabletId << ", for tableId " << TableId << " requested pages but got " << msg->Status);
111-
throw TExTableStatsError(ECode::FETCH_PAGE_FAILED, NKikimrProto::EReplyStatus_Name(msg->Status));
106+
<< TabletId << ", for tableId " << TableId << " requested pages but got " << status);
107+
throw TExTableStatsError(ECode::FETCH_PAGE_FAILED, NKikimrProto::EReplyStatus_Name(status));
112108
}
109+
Resume();
113110

114-
ObtainResources();
115-
Spent->Alter(true); // resume measurement
116-
117-
for (auto& loaded : msg->Pages) {
111+
for (auto& loaded : ev->Get()->Pages) {
118112
partPages.emplace(pageId, TPinnedPageRef(loaded.Page).GetData());
119113
PageRefs.emplace_back(std::move(loaded.Page));
120114
}
@@ -142,21 +136,19 @@ class TTableStatsCoroBuilder : public TActorCoroImpl, private IPages, TTableStat
142136

143137
Subset->ColdParts.clear(); // stats won't include cold parts, if any
144138
Spent = new TSpent(TAppData::TimeProvider.Get());
139+
CoroutineDeadline = GetCycleCountFast() + DurationToCycles(MaxCoroutineExecutionTime);
145140

146141
BuildStats(*Subset, ev->Stats, RowCountResolution, DataSizeResolution, HistogramBucketsCount, this, [this](){
147142
const auto now = GetCycleCountFast();
148143

149144
if (now > CoroutineDeadline) {
150-
Spent->Alter(false); // pause measurement
151-
ReleaseResources();
152-
153145
Send(new IEventHandle(EvResume, 0, SelfActorId, {}, nullptr, 0));
146+
147+
Interrupt();
154148
WaitForSpecificEvent([](IEventHandle& ev) {
155149
return ev.Type == EvResume;
156150
}, &TTableStatsCoroBuilder::ProcessUnexpectedEvent);
157-
158-
ObtainResources();
159-
Spent->Alter(true); // resume measurement
151+
Resume();
160152
}
161153
}, TStringBuilder() << "Building stats at datashard " << TabletId << ", for tableId " << TableId << ": ");
162154

@@ -170,8 +162,6 @@ class TTableStatsCoroBuilder : public TActorCoroImpl, private IPages, TTableStat
170162
<< ", LoadedSize " << PagesSize << ", " << NFmt::Do(*Spent));
171163

172164
Send(ReplyTo, ev.Release());
173-
174-
ReleaseResources();
175165
}
176166

177167
void ProcessUnexpectedEvent(TAutoPtr<IEventHandle> ev) {
@@ -217,12 +207,15 @@ class TTableStatsCoroBuilder : public TActorCoroImpl, private IPages, TTableStat
217207
auto msg = ev->Get();
218208
Y_ENSURE(!msg->Cookie.Get(), "Unexpected cookie in TEvResourceAllocated");
219209
Y_ENSURE(msg->TaskId == 1, "Unexpected task id in TEvResourceAllocated");
210+
}
220211

221-
CoroutineDeadline = GetCycleCountFast() + DurationToCycles(MaxCoroutineExecutionTime);
212+
void Interrupt() {
213+
Spent->Alter(false); // pause measurement
222214
}
223215

224-
void ReleaseResources() {
225-
Send(MakeResourceBrokerID(), new TEvResourceBroker::TEvFinishTask(/* task id */ 1, /* cancelled */ false));
216+
void Resume() {
217+
Spent->Alter(true); // resume measurement
218+
CoroutineDeadline = GetCycleCountFast() + DurationToCycles(MaxCoroutineExecutionTime);
226219
}
227220

228221
THashMap<const TPart*, THashMap<TPageId, TSharedData>> Pages;

0 commit comments

Comments
 (0)