Skip to content

Commit 1f6c060

Browse files
authored
Remove NPageCollection::TFetch class (#21476)
1 parent aaadd56 commit 1f6c060

22 files changed

+438
-437
lines changed

ydb/core/tablet_flat/flat_bio_actor.cpp

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ using TEvGet = TEvBlobStorage::TEvGet;
1414

1515
struct TBlockIO::TLoaded : public TEvBlobStorage::TEvGetResult::TResponse{ };
1616

17-
TBlockIO::TBlockIO(TActorId service, ui64 cookie)
17+
TBlockIO::TBlockIO(TActorId statActorId, ui64 eventCookie)
1818
: ::NActors::IActorCallback(static_cast<TReceiveFunc>(&TBlockIO::Inbox), NKikimrServices::TActivity::SAUSAGE_BIO_A)
19-
, Service(service)
20-
, Cookie(cookie)
19+
, StatActorId(statActorId)
20+
, EventCookie(eventCookie)
2121
{
2222
}
2323

@@ -42,10 +42,24 @@ void TBlockIO::Inbox(TEventHandlePtr &eh)
4242
Handle(eh->Cookie, { ptr, size_t(ev->ResponseSz) });
4343
}
4444
} else if (auto *ev = eh->CastAsLocal<NBlockIO::TEvFetch>()) {
45-
Y_ENSURE(!Owner, "TBlockIO actor now can hanle only one request");
45+
Y_ENSURE(!Sender, "TBlockIO actor now can handle only one request");
46+
Sender = eh->Sender;
47+
48+
Priority = ev->Priority;
49+
TraceId = std::move(ev->TraceId);
50+
RequestCookie = ev->Cookie;
51+
52+
PageCollection = std::move(ev->PageCollection);
53+
Pages = std::move(ev->Pages);
54+
Y_ENSURE(Pages, "Got TFetch request without pages list");
55+
PagesToBlobsConverter = new TPagesToBlobsConverter(*PageCollection, Pages);
56+
BlockStates.reserve(Pages.size());
57+
for (auto page: Pages) {
58+
ui64 size = PageCollection->Page(page).Size;
59+
BlockStates.emplace_back(size);
60+
}
4661

47-
Owner = eh->Sender;
48-
Bootstrap(ev->Priority, ev->Fetch);
62+
Dispatch();
4963
} else if (eh->CastAsLocal<TEvents::TEvUndelivered>()) {
5064
Terminate(NKikimrProto::UNKNOWN);
5165
} else if (eh->CastAsLocal<TEvents::TEvPoison>()) {
@@ -55,25 +69,6 @@ void TBlockIO::Inbox(TEventHandlePtr &eh)
5569
}
5670
}
5771

58-
void TBlockIO::Bootstrap(EPriority priority, TAutoPtr<NPageCollection::TFetch> origin)
59-
{
60-
Origin = origin;
61-
Priority = priority;
62-
63-
Y_ENSURE(Origin->Pages, "Got TFetch request without pages list");
64-
65-
PagesToBlobsConverter = new TPagesToBlobsConverter(*Origin->PageCollection, Origin->Pages);
66-
67-
BlockStates.reserve(Origin->Pages.size());
68-
69-
for (auto page: Origin->Pages) {
70-
ui64 size = Origin->PageCollection->Page(page).Size;
71-
BlockStates.emplace_back(size);
72-
}
73-
74-
Dispatch();
75-
}
76-
7772
void TBlockIO::Dispatch()
7873
{
7974
const auto ctx = ActorContext();
@@ -101,7 +96,7 @@ void TBlockIO::Dispatch()
10196
ui32 lastBlob = Max<ui32>();
10297
for (const auto on : xrange(+more)) {
10398
auto &brick = PagesToBlobsConverter->Queue[more.From + on];
104-
auto glob = Origin->PageCollection->Glob(brick.Blob);
99+
auto glob = PageCollection->Glob(brick.Blob);
105100

106101
if ((group = (on ? group : glob.Group)) != glob.Group) {
107102
Y_TABLET_ERROR("Cannot handle different groups in one request");
@@ -127,12 +122,12 @@ void TBlockIO::Dispatch()
127122

128123
auto *ev = new TEvGet(query, +more, TInstant::Max(), klass, false);
129124

130-
SendToBSProxy(ctx, group, ev, more.From /* cookie, request offset */, std::move(Origin->TraceId));
125+
SendToBSProxy(ctx, group, ev, more.From /* cookie, request offset */, std::move(TraceId));
131126
}
132127

133128
if (auto logl = Logger->Log(ELnLev::Debug)) {
134129
logl
135-
<< "NBlockIO pageCollection " << Origin->PageCollection->Label() << " cooked flow "
130+
<< "NBlockIO pageCollection " << PageCollection->Label() << " cooked flow "
136131
<< PagesToBlobsConverter->OnHold << "b " << PagesToBlobsConverter->Tail << "p" << " " << PagesToBlobsConverter->Queue.size()
137132
<< " bricks in " << Pending << " reads, " << BlockStates.size() << "p req";
138133
}
@@ -144,15 +139,15 @@ void TBlockIO::Handle(ui32 base, TArrayRef<TLoaded> items)
144139
{
145140
if (auto logl = Logger->Log(ELnLev::Debug)) {
146141
logl
147-
<< "NBlockIO pageCollection " << Origin->PageCollection->Label() << " got base"
142+
<< "NBlockIO pageCollection " << PageCollection->Label() << " got base"
148143
<< " " << items.size() << " bricks, left " << Pending;
149144
}
150145

151146
for (auto &piece: items) {
152147
if (piece.Status != NKikimrProto::OK) {
153148
if (auto logl = Logger->Log(ELnLev::Warn)) {
154149
logl
155-
<< "NBlockIO pageCollection " << Origin->PageCollection->Label() << " get failed"
150+
<< "NBlockIO pageCollection " << PageCollection->Label() << " get failed"
156151
<< ", " << piece.Id << " status " << piece.Status;
157152
}
158153

@@ -171,21 +166,21 @@ void TBlockIO::Handle(ui32 base, TArrayRef<TLoaded> items)
171166
return;
172167

173168
size_t index = 0;
174-
for (ui32 pageId : Origin->Pages) {
169+
for (auto pageId : Pages) {
175170
auto& state = BlockStates.at(index++);
176171
Y_ENSURE(state.Offset == state.Data.size());
177-
if (Origin->PageCollection->Verify(pageId, state.Data)) {
172+
if (PageCollection->Verify(pageId, state.Data)) {
178173
continue;
179174
} else if (auto logl = Logger->Log(ELnLev::Crit)) {
180-
const auto bnd = Origin->PageCollection->Bounds(pageId);
175+
const auto bnd = PageCollection->Bounds(pageId);
181176

182177
logl
183-
<< "NBlockIO pageCollection " << Origin->PageCollection->Label() << " verify failed"
178+
<< "NBlockIO pageCollection " << PageCollection->Label() << " verify failed"
184179
<< ", page " << pageId << " " << state.Data.size() << "b"
185180
<< " spans over {";
186181

187182
for (auto one: xrange(bnd.Lo.Blob, bnd.Up.Blob + 1)) {
188-
const auto glob = Origin->PageCollection->Glob(one);
183+
const auto glob = PageCollection->Glob(one);
189184

190185
logl << " " << glob.Group << " " << glob.Logo;
191186
}
@@ -203,26 +198,26 @@ void TBlockIO::Terminate(EStatus code)
203198
{
204199
if (auto logl = Logger->Log(code ? ELnLev::Warn : ELnLev::Debug)) {
205200
logl
206-
<< "NBlockIO pageCollection " << Origin->PageCollection->Label() << " end, status " << code
207-
<< ", cookie {req " << Origin->Cookie << " ev " << Cookie << "}"
201+
<< "NBlockIO pageCollection " << PageCollection->Label() << " end, status " << code
202+
<< ", cookie {req " << RequestCookie << " ev " << EventCookie << "}"
208203
<< ", " << BlockStates.size() << " pages";
209204
}
210205

211-
auto *ev = new TEvData(Origin, code);
206+
auto *ev = new TEvData(code, PageCollection, RequestCookie);
212207

213-
if (code == NKikimrProto::OK) {
214-
size_t index = 0;
215-
ev->Blocks.reserve(ev->Fetch->Pages.size());
216-
for (ui32 pageId : ev->Fetch->Pages) {
217-
auto& state = BlockStates.at(index++);
218-
ev->Blocks.emplace_back(pageId, std::move(state.Data));
208+
ev->Pages.resize(Pages.size());
209+
for (auto index : xrange(Pages.size())) {
210+
auto& page = ev->Pages[index];
211+
page.PageId = Pages[index];
212+
if (code == NKikimrProto::OK) {
213+
page.Data = std::move(BlockStates.at(index++).Data);
219214
}
220215
}
221216

222-
if (Service)
223-
Send(Service, new TEvStat(EDir::Read, Priority, PagesToBlobsConverter->OnHold, TotalOps, std::move(GroupBytes), std::move(GroupOps)));
217+
if (StatActorId)
218+
Send(StatActorId, new TEvStat(EDir::Read, Priority, PagesToBlobsConverter->OnHold, TotalOps, std::move(GroupBytes), std::move(GroupOps)));
224219

225-
Send(Owner, ev, 0, Cookie);
220+
Send(Sender, ev, 0, EventCookie);
226221

227222
return PassAway();
228223
}

ydb/core/tablet_flat/flat_bio_actor.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@ namespace NBlockIO {
2424
private:
2525
void Registered(TActorSystem*, const TActorId&) override;
2626
void Inbox(TEventHandlePtr &eh);
27-
void Bootstrap(EPriority priority, TAutoPtr<NPageCollection::TFetch>);
2827
void Dispatch();
2928
void Handle(ui32 offset, TArrayRef<TLoaded>);
3029
void Terminate(EStatus code);
3130

3231
private:
33-
const TActorId Service;
34-
const ui64 Cookie = Max<ui64>();
32+
const TActorId StatActorId;
33+
const ui64 EventCookie;
3534
TAutoPtr<NUtil::ILogger> Logger;
3635

3736
/*_ immutable request settings */
3837

39-
TActorId Owner;
40-
EPriority Priority = EPriority::None;
41-
TAutoPtr<NPageCollection::TFetch> Origin;
38+
TActorId Sender;
39+
EPriority Priority;
40+
TIntrusiveConstPtr<NPageCollection::IPageCollection> PageCollection;
41+
TVector<TPageId> Pages;
42+
NWilson::TTraceId TraceId;
43+
ui64 RequestCookie;
4244

4345
/*_ request operational state */
4446

@@ -59,13 +61,10 @@ namespace NBlockIO {
5961
NMetrics::TTabletIopsRawValue GroupOps;
6062
};
6163

62-
template<typename ... TArgs>
63-
inline void Start(NActors::IActorOps *ops, TActorId service,
64-
ui64 cookie, TArgs&& ... args)
64+
inline void Start(NActors::IActorOps *ops, TActorId statActorId, ui64 cookie, TEvFetch* fetch)
6565
{
66-
auto self = ops->Register(new TBlockIO(service, cookie));
67-
68-
ops->Send(self, new TEvFetch(std::forward<TArgs>(args)...));
66+
auto self = ops->Register(new TBlockIO(statActorId, cookie));
67+
ops->Send(self, fetch);
6968
}
7069

7170
}

ydb/core/tablet_flat/flat_bio_events.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

33
#include "flat_bio_eggs.h"
4-
#include "flat_sausage_packet.h"
54
#include "flat_sausage_fetch.h"
5+
#include "flat_sausage_gut.h"
66
#include <ydb/core/protos/base.pb.h>
77
#include <ydb/core/base/events.h>
88
#include <ydb/library/actors/core/event_local.h>
@@ -11,6 +11,8 @@ namespace NKikimr {
1111
namespace NTabletFlatExecutor {
1212
namespace NBlockIO {
1313

14+
using TPageId = NPageCollection::TPageId;
15+
1416
enum class EEv : ui32 {
1517
Base_ = EventSpaceBegin(TKikimrEvents::ES_FLAT_EXECUTOR) + 1088,
1618

@@ -20,47 +22,46 @@ namespace NBlockIO {
2022
};
2123

2224
struct TEvFetch : public TEventLocal<TEvFetch, ui32(EEv::Fetch)> {
23-
TEvFetch(EPriority priority, TAutoPtr<NPageCollection::TFetch> fetch)
25+
TEvFetch(EPriority priority, TIntrusiveConstPtr<NPageCollection::IPageCollection> pageCollection, TVector<TPageId> pages, ui64 cookie)
2426
: Priority(priority)
25-
, Fetch(fetch)
27+
, PageCollection(std::move(pageCollection))
28+
, Pages(std::move(pages))
29+
, Cookie(cookie)
2630
{
2731

2832
}
2933

30-
const EPriority Priority = EPriority::None;
31-
TAutoPtr<NPageCollection::TFetch> Fetch;
34+
const EPriority Priority;
35+
TIntrusiveConstPtr<NPageCollection::IPageCollection> PageCollection;
36+
TVector<TPageId> Pages;
37+
NWilson::TTraceId TraceId;
38+
const ui64 Cookie;
3239
};
3340

3441
struct TEvData: public TEventLocal<TEvData, ui32(EEv::Data)> {
3542
using EStatus = NKikimrProto::EReplyStatus;
3643

37-
TEvData(TAutoPtr<NPageCollection::TFetch> fetch, EStatus status)
44+
TEvData(EStatus status, TIntrusiveConstPtr<NPageCollection::IPageCollection> pageCollection, ui64 cookie)
3845
: Status(status)
39-
, Fetch(fetch)
46+
, PageCollection(std::move(pageCollection))
47+
, Cookie(cookie)
4048
{
4149

4250
}
4351

4452
void Describe(IOutputStream &out) const
4553
{
4654
out
47-
<< "Blocks{" << Blocks.size() << " pages"
48-
<< " " << Fetch->PageCollection->Label()
55+
<< "Blocks{" << Pages.size() << " pages"
56+
<< " " << PageCollection->Label()
4957
<< " " << (Status == NKikimrProto::OK ? "ok" : "fail")
5058
<< " " << NKikimrProto::EReplyStatus_Name(Status) << "}";
5159
}
5260

53-
ui64 Bytes() const
54-
{
55-
return
56-
std::accumulate(Blocks.begin(), Blocks.end(), ui64(0),
57-
[](ui64 bytes, const NPageCollection::TLoadedPage& block)
58-
{ return bytes + block.Data.size(); });
59-
}
60-
6161
const EStatus Status;
62-
TAutoPtr<NPageCollection::TFetch> Fetch;
63-
TVector<NPageCollection::TLoadedPage> Blocks;
62+
TIntrusiveConstPtr<NPageCollection::IPageCollection> PageCollection;
63+
TVector<NPageCollection::TLoadedPage> Pages;
64+
const ui64 Cookie;
6465
};
6566

6667
}

ydb/core/tablet_flat/flat_boot_bundle.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ namespace NBoot {
5858
LeftReads -= 1;
5959

6060
if (msg.Status == NKikimrProto::OK) {
61-
Loader->Save(msg.Cookie, msg.Pages);
61+
Y_ENSURE(msg.Cookie == 0);
62+
Loader->Save(std::move(msg.Pages));
6263

6364
TryFinalize();
6465

@@ -108,8 +109,8 @@ namespace NBoot {
108109
void TryFinalize()
109110
{
110111
if (!LeftReads) {
111-
for (auto req : Loader->Run({.PreloadIndex = true, .PreloadData = false})) {
112-
LeftReads += Logic->LoadPages(this, req);
112+
if (auto fetch = Loader->Run({.PreloadIndex = true, .PreloadData = false})) {
113+
LeftReads += Logic->LoadPages(this, std::move(fetch));
113114
}
114115
}
115116

0 commit comments

Comments
 (0)