Skip to content

Commit 91c2833

Browse files
authored
YDB-6486 Implement external blob precharge in read iterator (#5758)
Closes #6486
1 parent a2040b4 commit 91c2833

13 files changed

+757
-44
lines changed

ydb/core/kqp/ut/common/kqp_ut_common.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,6 @@ THolder<NSchemeCache::TSchemeCacheNavigate> Navigate(TTestActorRuntime& runtime,
12881288
{
12891289
auto &runtime = *server->GetRuntime();
12901290
TAutoPtr<IEventHandle> handle;
1291-
TVector<ui64> shards;
12921291

12931292
auto request = MakeHolder<TEvTxUserProxy::TEvNavigate>();
12941293
request->Record.MutableDescribePath()->SetPath(path);

ydb/core/scheme/scheme_tablecell.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,7 @@ size_t TOwnedCellVecBatch::Append(TConstArrayRef<TCell> cells) {
349349
return 0;
350350
}
351351

352-
size_t size = sizeof(TCell) * cellsSize;
353-
for (auto& cell : cells) {
354-
if (!cell.IsNull() && !cell.IsInline()) {
355-
const size_t cellSize = cell.Size();
356-
size += AlignUp(cellSize);
357-
}
358-
}
352+
size_t size = EstimateSize(cells);
359353

360354
char * allocatedBuffer = reinterpret_cast<char *>(Pool->Allocate(size));
361355

ydb/core/scheme/scheme_tablecell.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ struct TCell {
169169
static_assert(sizeof(TCell) == 12, "TCell must be 12 bytes");
170170
using TCellsRef = TConstArrayRef<const TCell>;
171171

172+
inline size_t EstimateSize(TCellsRef cells) {
173+
size_t cellsSize = cells.size();
174+
175+
size_t size = sizeof(TCell) * cellsSize;
176+
for (auto& cell : cells) {
177+
if (!cell.IsNull() && !cell.IsInline()) {
178+
const size_t cellSize = cell.Size();
179+
size += AlignUp(cellSize);
180+
}
181+
}
182+
183+
return size;
184+
}
185+
172186
inline int CompareCellsAsByteString(const TCell& a, const TCell& b, bool isDescending) {
173187
const char* pa = (const char*)a.Data();
174188
const char* pb = (const char*)b.Data();

ydb/core/tablet_flat/flat_executor_tx_env.h

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ namespace NTabletFlatExecutor {
2929
{
3030
auto *partStore = CheckedCast<const NTable::TPartStore*>(part);
3131

32-
return { true, Lookup(partStore->Locate(lob, ref), ref) };
32+
const TSharedData* page = Lookup(partStore->Locate(lob, ref), ref);
33+
34+
if (!page && ReadMissingReferences) {
35+
MissingReferencesSize_ += Max<ui64>(1, part->GetPageSize(lob, ref));
36+
}
37+
38+
return { !ReadMissingReferences, page };
3339
}
3440

3541
const TSharedData* TryGetPage(const TPart* part, TPageId page, TGroupId groupId) override
@@ -39,6 +45,20 @@ namespace NTabletFlatExecutor {
3945
return Lookup(partStore->PageCollections.at(groupId.Index).Get(), page);
4046
}
4147

48+
void EnableReadMissingReferences() noexcept {
49+
ReadMissingReferences = true;
50+
}
51+
52+
void DisableReadMissingReferences() noexcept {
53+
ReadMissingReferences = false;
54+
MissingReferencesSize_ = 0;
55+
}
56+
57+
ui64 MissingReferencesSize() const noexcept
58+
{
59+
return MissingReferencesSize_;
60+
}
61+
4262
private:
4363
const TSharedData* Lookup(TPrivatePageCache::TInfo *info, TPageId pageId) noexcept
4464
{
@@ -47,6 +67,11 @@ namespace NTabletFlatExecutor {
4767

4868
public:
4969
TPrivatePageCache& Cache;
70+
71+
private:
72+
bool ReadMissingReferences = false;
73+
74+
ui64 MissingReferencesSize_ = 0;
5075
};
5176

5277
struct TPageCollectionTxEnv : public TPageCollectionReadEnv, public IExecuting {
@@ -187,6 +212,20 @@ namespace NTabletFlatExecutor {
187212
LoanConfirmation.insert(std::make_pair(bundle, TLoanConfirmation{borrow}));
188213
}
189214

215+
void EnableReadMissingReferences() noexcept override
216+
{
217+
TPageCollectionReadEnv::EnableReadMissingReferences();
218+
}
219+
220+
void DisableReadMissingReferences() noexcept override
221+
{
222+
TPageCollectionReadEnv::DisableReadMissingReferences();
223+
}
224+
225+
ui64 MissingReferencesSize() const noexcept override
226+
{
227+
return TPageCollectionReadEnv::MissingReferencesSize();
228+
}
190229
protected:
191230
NTable::TDatabase& DB;
192231

ydb/core/tablet_flat/flat_part_iter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,7 @@ namespace NTable {
13191319

13201320
if (ref >> (sizeof(ui32) * 8))
13211321
Y_ABORT("Upper bits of ELargeObj ref now isn't used");
1322+
13221323
if (auto blob = Env->Locate(Part, ref, op)) {
13231324
const auto got = NPage::TLabelWrapper().Read(**blob);
13241325

@@ -1332,13 +1333,12 @@ namespace NTable {
13321333
} else {
13331334
Y_ABORT_UNLESS(ref < (*Part->Blobs)->size(), "out of blobs catalog");
13341335

1336+
op = TCellOp(blob.Need ? ECellOp::Null : ECellOp(op), ELargeObj::GlobId);
1337+
13351338
/* Have to preserve reference to memory with TGlobId until
13361339
of next iterator alteration method invocation. This is
13371340
why here direct array of TGlobId is used.
13381341
*/
1339-
1340-
op = TCellOp(blob.Need ? ECellOp::Null : ECellOp(op), ELargeObj::GlobId);
1341-
13421342
row.Set(pin.To, op, TCell::Make((**Part->Blobs)[ref]));
13431343
}
13441344
} else {

ydb/core/tablet_flat/flat_part_store.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class TPartStore : public TPart, public IBundle {
7979
return PageCollections[groupId.Index]->GetPageSize(pageId);
8080
}
8181

82+
ui64 GetPageSize(ELargeObj lob, ui64 ref) const override
83+
{
84+
auto* cache = Locate(lob, ref);
85+
86+
return cache->PageCollection->Page(ref).Size;
87+
}
88+
8289
NPage::EPage GetPageType(NPage::TPageId pageId, NPage::TGroupId groupId) const override
8390
{
8491
Y_ABORT_UNLESS(groupId.Index < PageCollections.size());

ydb/core/tablet_flat/flat_table_part.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ namespace NTable {
156156
virtual ui64 DataSize() const = 0;
157157
virtual ui64 BackingSize() const = 0;
158158
virtual ui64 GetPageSize(NPage::TPageId pageId, NPage::TGroupId groupId) const = 0;
159+
virtual ui64 GetPageSize(ELargeObj lob, ui64 ref) const = 0;
159160
virtual NPage::EPage GetPageType(NPage::TPageId pageId, NPage::TGroupId groupId) const = 0;
160161
virtual ui8 GetGroupChannel(NPage::TGroupId groupId) const = 0;
161162
virtual ui8 GetPageChannel(ELargeObj lob, ui64 ref) const = 0;

ydb/core/tablet_flat/tablet_flat_executor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ struct IExecuting {
103103
virtual void LoanTable(ui32 tableId, const TString &partsInfo) = 0; // attach table parts to table (called on part destination)
104104
virtual void CleanupLoan(const TLogoBlobID &bundleId, ui64 from) = 0; // mark loan completion (called on part source)
105105
virtual void ConfirmLoan(const TLogoBlobID &bundleId, const TLogoBlobID &borrowId) = 0; // confirm loan update delivery (called on part destination)
106+
virtual void EnableReadMissingReferences() noexcept = 0;
107+
virtual void DisableReadMissingReferences() noexcept = 0;
108+
virtual ui64 MissingReferencesSize() const noexcept = 0;
106109
};
107110

108111
class TTxMemoryProviderBase : TNonCopyable {

ydb/core/tablet_flat/test/libs/table/test_part.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ namespace NTest {
5252
return Store->GetPageSize(groupId.Index, pageId);
5353
}
5454

55+
ui64 GetPageSize(ELargeObj lob, ui64 ref) const override
56+
{
57+
Y_UNUSED(lob);
58+
Y_UNUSED(ref);
59+
return 0;
60+
}
61+
5562
NPage::EPage GetPageType(NPage::TPageId pageId, NPage::TGroupId groupId) const override
5663
{
5764
return Store->GetPageType(groupId.Index, pageId);

0 commit comments

Comments
 (0)