|
| 1 | +#pragma once |
| 2 | +#include "fetching.h" |
| 3 | + |
| 4 | +#include <ydb/core/tx/limiter/grouped_memory/usage/abstract.h> |
| 5 | + |
| 6 | +namespace NKikimr::NOlap::NReader::NCommon { |
| 7 | + |
| 8 | +class TAllocateMemoryStep: public IFetchingStep { |
| 9 | +private: |
| 10 | + using TBase = IFetchingStep; |
| 11 | + class TColumnsPack { |
| 12 | + private: |
| 13 | + YDB_READONLY_DEF(TColumnsSetIds, Columns); |
| 14 | + YDB_READONLY(EMemType, MemType, EMemType::Blob); |
| 15 | + |
| 16 | + public: |
| 17 | + TColumnsPack(const TColumnsSetIds& columns, const EMemType memType) |
| 18 | + : Columns(columns) |
| 19 | + , MemType(memType) { |
| 20 | + } |
| 21 | + }; |
| 22 | + std::vector<TColumnsPack> Packs; |
| 23 | + THashMap<ui32, THashSet<EMemType>> Control; |
| 24 | + const EStageFeaturesIndexes StageIndex; |
| 25 | + const std::optional<ui64> PredefinedSize; |
| 26 | + |
| 27 | +protected: |
| 28 | + class TFetchingStepAllocation: public NGroupedMemoryManager::IAllocation { |
| 29 | + private: |
| 30 | + using TBase = NGroupedMemoryManager::IAllocation; |
| 31 | + std::weak_ptr<IDataSource> Source; |
| 32 | + TFetchingScriptCursor Step; |
| 33 | + NColumnShard::TCounterGuard TasksGuard; |
| 34 | + const EStageFeaturesIndexes StageIndex; |
| 35 | + virtual bool DoOnAllocated(std::shared_ptr<NGroupedMemoryManager::TAllocationGuard>&& guard, |
| 36 | + const std::shared_ptr<NGroupedMemoryManager::IAllocation>& allocation) override; |
| 37 | + virtual void DoOnAllocationImpossible(const TString& errorMessage) override; |
| 38 | + |
| 39 | + public: |
| 40 | + TFetchingStepAllocation(const std::shared_ptr<IDataSource>& source, const ui64 mem, const TFetchingScriptCursor& step, |
| 41 | + const EStageFeaturesIndexes stageIndex); |
| 42 | + }; |
| 43 | + virtual TConclusion<bool> DoExecuteInplace(const std::shared_ptr<IDataSource>& source, const TFetchingScriptCursor& step) const override; |
| 44 | + virtual ui64 GetProcessingDataSize(const std::shared_ptr<IDataSource>& source) const override; |
| 45 | + virtual TString DoDebugString() const override { |
| 46 | + return TStringBuilder() << "stage=" << StageIndex << ";"; |
| 47 | + } |
| 48 | + |
| 49 | +public: |
| 50 | + void AddAllocation(const TColumnsSetIds& ids, const EMemType memType) { |
| 51 | + if (!ids.GetColumnsCount()) { |
| 52 | + return; |
| 53 | + } |
| 54 | + for (auto&& i : ids.GetColumnIds()) { |
| 55 | + AFL_VERIFY(Control[i].emplace(memType).second); |
| 56 | + } |
| 57 | + Packs.emplace_back(ids, memType); |
| 58 | + } |
| 59 | + EStageFeaturesIndexes GetStage() const { |
| 60 | + return StageIndex; |
| 61 | + } |
| 62 | + |
| 63 | + TAllocateMemoryStep(const TColumnsSetIds& columns, const EMemType memType, const EStageFeaturesIndexes stageIndex) |
| 64 | + : TBase("ALLOCATE_MEMORY::" + ::ToString(stageIndex)) |
| 65 | + , StageIndex(stageIndex) { |
| 66 | + AddAllocation(columns, memType); |
| 67 | + } |
| 68 | + |
| 69 | + TAllocateMemoryStep(const ui64 memSize, const EStageFeaturesIndexes stageIndex) |
| 70 | + : TBase("ALLOCATE_MEMORY::" + ::ToString(stageIndex)) |
| 71 | + , StageIndex(stageIndex) |
| 72 | + , PredefinedSize(memSize) { |
| 73 | + } |
| 74 | +}; |
| 75 | + |
| 76 | +class TAssemblerStep: public IFetchingStep { |
| 77 | +private: |
| 78 | + using TBase = IFetchingStep; |
| 79 | + YDB_READONLY_DEF(std::shared_ptr<TColumnsSet>, Columns); |
| 80 | + virtual TString DoDebugString() const override { |
| 81 | + return TStringBuilder() << "columns=" << Columns->DebugString() << ";"; |
| 82 | + } |
| 83 | + |
| 84 | +public: |
| 85 | + virtual ui64 GetProcessingDataSize(const std::shared_ptr<IDataSource>& source) const override; |
| 86 | + virtual TConclusion<bool> DoExecuteInplace(const std::shared_ptr<IDataSource>& source, const TFetchingScriptCursor& step) const override; |
| 87 | + TAssemblerStep(const std::shared_ptr<TColumnsSet>& columns, const TString& specName = Default<TString>()) |
| 88 | + : TBase("ASSEMBLER" + (specName ? "::" + specName : "")) |
| 89 | + , Columns(columns) { |
| 90 | + AFL_VERIFY(Columns); |
| 91 | + AFL_VERIFY(Columns->GetColumnsCount()); |
| 92 | + } |
| 93 | +}; |
| 94 | + |
| 95 | +class TBuildStageResultStep: public IFetchingStep { |
| 96 | +private: |
| 97 | + using TBase = IFetchingStep; |
| 98 | + |
| 99 | +public: |
| 100 | + virtual TConclusion<bool> DoExecuteInplace(const std::shared_ptr<IDataSource>& source, const TFetchingScriptCursor& /*step*/) const override; |
| 101 | + TBuildStageResultStep() |
| 102 | + : TBase("BUILD_STAGE_RESULT") { |
| 103 | + } |
| 104 | +}; |
| 105 | + |
| 106 | +class TOptionalAssemblerStep: public IFetchingStep { |
| 107 | +private: |
| 108 | + using TBase = IFetchingStep; |
| 109 | + YDB_READONLY_DEF(std::shared_ptr<TColumnsSet>, Columns); |
| 110 | + virtual TString DoDebugString() const override { |
| 111 | + return TStringBuilder() << "columns=" << Columns->DebugString() << ";"; |
| 112 | + } |
| 113 | + |
| 114 | +public: |
| 115 | + virtual ui64 GetProcessingDataSize(const std::shared_ptr<IDataSource>& source) const override; |
| 116 | + |
| 117 | + virtual TConclusion<bool> DoExecuteInplace(const std::shared_ptr<IDataSource>& source, const TFetchingScriptCursor& step) const override; |
| 118 | + TOptionalAssemblerStep(const std::shared_ptr<TColumnsSet>& columns, const TString& specName = Default<TString>()) |
| 119 | + : TBase("OPTIONAL_ASSEMBLER" + (specName ? "::" + specName : "")) |
| 120 | + , Columns(columns) { |
| 121 | + AFL_VERIFY(Columns); |
| 122 | + AFL_VERIFY(Columns->GetColumnsCount()); |
| 123 | + } |
| 124 | +}; |
| 125 | + |
| 126 | +class TColumnBlobsFetchingStep: public IFetchingStep { |
| 127 | +private: |
| 128 | + using TBase = IFetchingStep; |
| 129 | + TColumnsSetIds Columns; |
| 130 | + |
| 131 | +protected: |
| 132 | + virtual TConclusion<bool> DoExecuteInplace(const std::shared_ptr<IDataSource>& source, const TFetchingScriptCursor& step) const override; |
| 133 | + virtual TString DoDebugString() const override { |
| 134 | + return TStringBuilder() << "columns=" << Columns.DebugString() << ";"; |
| 135 | + } |
| 136 | + |
| 137 | +public: |
| 138 | + virtual ui64 GetProcessingDataSize(const std::shared_ptr<IDataSource>& source) const override; |
| 139 | + TColumnBlobsFetchingStep(const TColumnsSetIds& columns) |
| 140 | + : TBase("FETCHING_COLUMNS") |
| 141 | + , Columns(columns) { |
| 142 | + AFL_VERIFY(Columns.GetColumnsCount()); |
| 143 | + } |
| 144 | +}; |
| 145 | + |
| 146 | +} // namespace NKikimr::NOlap::NReader::NCommon |
0 commit comments