|
1 | 1 | #include "tx_internal_scan.h"
|
2 |
| -#include <ydb/core/tx/columnshard/engines/reader/actor/actor.h> |
3 |
| -#include <ydb/core/tx/columnshard/engines/reader/sys_view/constructor/constructor.h> |
4 |
| -#include <ydb/core/tx/columnshard/engines/reader/plain_reader/constructor/constructor.h> |
| 2 | + |
5 | 3 | #include <ydb/core/formats/arrow/arrow_batch_builder.h>
|
6 | 4 | #include <ydb/core/sys_view/common/schema.h>
|
| 5 | +#include <ydb/core/tx/columnshard/engines/reader/actor/actor.h> |
| 6 | +#include <ydb/core/tx/columnshard/engines/reader/plain_reader/constructor/constructor.h> |
7 | 7 | #include <ydb/core/tx/columnshard/engines/reader/sys_view/abstract/policy.h>
|
| 8 | +#include <ydb/core/tx/columnshard/engines/reader/sys_view/constructor/constructor.h> |
8 | 9 |
|
9 | 10 | namespace NKikimr::NOlap::NReader {
|
10 | 11 |
|
11 |
| -bool TTxInternalScan::Execute(TTransactionContext& /*txc*/, const TActorContext& /*ctx*/) { |
12 |
| - TMemoryProfileGuard mpg("TTxInternalScan::Execute"); |
| 12 | +void TTxInternalScan::SendError(const TString& problem, const TString& details, const TActorContext& ctx) const { |
| 13 | + AFL_WARN(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "TTxScan failed")("problem", problem)("details", details); |
13 | 14 | auto& request = *InternalScanEvent->Get();
|
14 |
| - const TSnapshot snapshot = request.ReadToSnapshot.value_or(NOlap::TSnapshot(Self->LastPlannedStep, Self->LastPlannedTxId)); |
| 15 | + auto scanComputeActor = InternalScanEvent->Sender; |
15 | 16 |
|
16 |
| - TReadDescription read(snapshot, request.GetReverse()); |
17 |
| - read.PathId = request.GetPathId(); |
18 |
| - read.ReadNothing = !Self->TablesManager.HasTable(read.PathId); |
19 |
| - std::unique_ptr<IScannerConstructor> scannerConstructor(new NPlain::TIndexScannerConstructor(snapshot, request.GetItemsLimit(), request.GetReverse())); |
20 |
| - read.ColumnIds = request.GetColumnIds(); |
21 |
| - read.ColumnNames = request.GetColumnNames(); |
22 |
| - if (request.RangesFilter) { |
23 |
| - read.PKRangesFilter = std::move(*request.RangesFilter); |
24 |
| - } |
| 17 | + auto ev = MakeHolder<NKqp::TEvKqpCompute::TEvScanError>(ScanGen, Self->TabletID()); |
| 18 | + ev->Record.SetStatus(Ydb::StatusIds::BAD_REQUEST); |
| 19 | + auto issue = NYql::YqlIssue({}, NYql::TIssuesIds::KIKIMR_BAD_REQUEST, |
| 20 | + TStringBuilder() << "Table " << request.GetPathId() << " (shard " << Self->TabletID() << ") scan failed, reason: " << problem << "/" |
| 21 | + << details); |
| 22 | + NYql::IssueToMessage(issue, ev->Record.MutableIssues()->Add()); |
25 | 23 |
|
26 |
| - const TVersionedIndex* vIndex = Self->GetIndexOptional() ? &Self->GetIndexOptional()->GetVersionedIndex() : nullptr; |
27 |
| - AFL_VERIFY(vIndex); |
28 |
| - { |
29 |
| - TProgramContainer pContainer; |
30 |
| - pContainer.OverrideProcessingColumns(read.ColumnNames); |
31 |
| - read.SetProgram(std::move(pContainer)); |
32 |
| - } |
| 24 | + ctx.Send(scanComputeActor, ev.Release()); |
| 25 | +} |
33 | 26 |
|
34 |
| - { |
35 |
| - auto newRange = scannerConstructor->BuildReadMetadata(Self, read); |
36 |
| - if (!newRange) { |
37 |
| - ErrorDescription = newRange.GetErrorMessage(); |
38 |
| - ReadMetadataRange = nullptr; |
39 |
| - return true; |
40 |
| - } |
41 |
| - ReadMetadataRange = newRange.DetachResult(); |
42 |
| - } |
43 |
| - AFL_VERIFY(ReadMetadataRange); |
| 27 | +bool TTxInternalScan::Execute(TTransactionContext& /*txc*/, const TActorContext& /*ctx*/) { |
44 | 28 | return true;
|
45 | 29 | }
|
46 | 30 |
|
47 | 31 | void TTxInternalScan::Complete(const TActorContext& ctx) {
|
48 | 32 | TMemoryProfileGuard mpg("TTxInternalScan::Complete");
|
| 33 | + |
49 | 34 | auto& request = *InternalScanEvent->Get();
|
50 | 35 | auto scanComputeActor = InternalScanEvent->Sender;
|
51 |
| - const NActors::TLogContextGuard gLogging = NActors::TLogContextBuilder::Build()("tablet", Self->TabletID()); |
52 |
| - |
53 |
| - if (!ReadMetadataRange) { |
54 |
| - AFL_WARN(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "TTxScan failed")("reason", "no metadata")("error", ErrorDescription); |
| 36 | + const TSnapshot snapshot = request.ReadToSnapshot.value_or(NOlap::TSnapshot(Self->LastPlannedStep, Self->LastPlannedTxId)); |
| 37 | + const NActors::TLogContextGuard gLogging = |
| 38 | + NActors::TLogContextBuilder::Build()("tablet", Self->TabletID())("snapshot", snapshot.DebugString()); |
| 39 | + TReadMetadataPtr readMetadataRange; |
| 40 | + { |
| 41 | + TReadDescription read(snapshot, request.GetReverse()); |
| 42 | + read.PathId = request.GetPathId(); |
| 43 | + read.ReadNothing = !Self->TablesManager.HasTable(read.PathId); |
| 44 | + std::unique_ptr<IScannerConstructor> scannerConstructor( |
| 45 | + new NPlain::TIndexScannerConstructor(snapshot, request.GetItemsLimit(), request.GetReverse())); |
| 46 | + read.ColumnIds = request.GetColumnIds(); |
| 47 | + read.ColumnNames = request.GetColumnNames(); |
| 48 | + if (request.RangesFilter) { |
| 49 | + read.PKRangesFilter = std::move(*request.RangesFilter); |
| 50 | + } |
55 | 51 |
|
56 |
| - auto ev = MakeHolder<NKqp::TEvKqpCompute::TEvScanError>(ScanGen, Self->TabletID()); |
57 |
| - ev->Record.SetStatus(Ydb::StatusIds::BAD_REQUEST); |
58 |
| - auto issue = NYql::YqlIssue({}, NYql::TIssuesIds::KIKIMR_BAD_REQUEST, TStringBuilder() |
59 |
| - << "Table " << request.GetPathId() << " (shard " << Self->TabletID() << ") scan failed, reason: " << ErrorDescription ? ErrorDescription : "no metadata ranges"); |
60 |
| - NYql::IssueToMessage(issue, ev->Record.MutableIssues()->Add()); |
| 52 | + const TVersionedIndex* vIndex = Self->GetIndexOptional() ? &Self->GetIndexOptional()->GetVersionedIndex() : nullptr; |
| 53 | + AFL_VERIFY(vIndex); |
| 54 | + { |
| 55 | + TProgramContainer pContainer; |
| 56 | + pContainer.OverrideProcessingColumns(read.ColumnNames); |
| 57 | + read.SetProgram(std::move(pContainer)); |
| 58 | + } |
61 | 59 |
|
62 |
| - ctx.Send(scanComputeActor, ev.Release()); |
63 |
| - return; |
| 60 | + { |
| 61 | + auto newRange = scannerConstructor->BuildReadMetadata(Self, read); |
| 62 | + if (!newRange) { |
| 63 | + return SendError("cannot create read metadata", newRange.GetErrorMessage(), ctx); |
| 64 | + } |
| 65 | + readMetadataRange = TValidator::CheckNotNull(newRange.DetachResult()); |
| 66 | + } |
64 | 67 | }
|
| 68 | + |
65 | 69 | TStringBuilder detailedInfo;
|
66 | 70 | if (IS_LOG_PRIORITY_ENABLED(NActors::NLog::PRI_TRACE, NKikimrServices::TX_COLUMNSHARD)) {
|
67 |
| - detailedInfo << " read metadata: (" << *ReadMetadataRange << ")"; |
| 71 | + detailedInfo << " read metadata: (" << *readMetadataRange << ")"; |
68 | 72 | }
|
69 | 73 |
|
70 | 74 | const TVersionedIndex* index = nullptr;
|
71 | 75 | if (Self->HasIndex()) {
|
72 | 76 | index = &Self->GetIndexAs<TColumnEngineForLogs>().GetVersionedIndex();
|
73 | 77 | }
|
74 |
| - const TConclusion<ui64> requestCookie = Self->InFlightReadsTracker.AddInFlightRequest(ReadMetadataRange, index); |
75 |
| - if (!requestCookie) { |
76 |
| - AFL_ERROR(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "TTxScan failed")("reason", requestCookie.GetErrorMessage())("trace_details", detailedInfo); |
77 |
| - auto ev = MakeHolder<NKqp::TEvKqpCompute::TEvScanError>(ScanGen, Self->TabletID()); |
78 |
| - |
79 |
| - ev->Record.SetStatus(Ydb::StatusIds::INTERNAL_ERROR); |
80 |
| - auto issue = NYql::YqlIssue({}, NYql::TIssuesIds::KIKIMR_TEMPORARILY_UNAVAILABLE, TStringBuilder() |
81 |
| - << "Table " << request.GetPathId() << " (shard " << Self->TabletID() << ") scan failed, reason: " << requestCookie.GetErrorMessage()); |
82 |
| - NYql::IssueToMessage(issue, ev->Record.MutableIssues()->Add()); |
83 |
| - Self->Counters.GetScanCounters().OnScanFinished(NColumnShard::TScanCounters::EStatusFinish::CannotAddInFlight, TDuration::Zero()); |
84 |
| - ctx.Send(scanComputeActor, ev.Release()); |
85 |
| - return; |
86 |
| - } |
87 |
| - auto scanActor = ctx.Register(new TColumnShardScan(Self->SelfId(), scanComputeActor, Self->GetStoragesManager(), |
88 |
| - TComputeShardingPolicy(), ScanId, TxId, ScanGen, *requestCookie, Self->TabletID(), TDuration::Max(), ReadMetadataRange, |
89 |
| - NKikimrDataEvents::FORMAT_ARROW, Self->Counters.GetScanCounters())); |
| 78 | + const ui64 requestCookie = Self->InFlightReadsTracker.AddInFlightRequest(readMetadataRange, index); |
| 79 | + auto scanActor = ctx.Register(new TColumnShardScan(Self->SelfId(), scanComputeActor, Self->GetStoragesManager(), TComputeShardingPolicy(), |
| 80 | + ScanId, TxId, ScanGen, requestCookie, Self->TabletID(), TDuration::Max(), readMetadataRange, NKikimrDataEvents::FORMAT_ARROW, |
| 81 | + Self->Counters.GetScanCounters())); |
90 | 82 |
|
91 | 83 | AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "TTxInternalScan started")("actor_id", scanActor)("trace_detailed", detailedInfo);
|
92 | 84 | }
|
93 | 85 |
|
94 |
| -} |
| 86 | +} // namespace NKikimr::NOlap::NReader |
0 commit comments