|
| 1 | +#include "clean_inserted_portions.h" |
| 2 | + |
| 3 | +#include <ydb/core/formats/arrow/arrow_helpers.h> |
| 4 | +#include <ydb/core/tx/columnshard/columnshard_schema.h> |
| 5 | +#include <ydb/core/tx/columnshard/engines/portions/data_accessor.h> |
| 6 | +#include <ydb/core/tx/columnshard/engines/portions/read_with_blobs.h> |
| 7 | +#include <ydb/core/tx/columnshard/engines/scheme/filtered_scheme.h> |
| 8 | +#include <ydb/core/tx/columnshard/tables_manager.h> |
| 9 | + |
| 10 | +#include <util/string/vector.h> |
| 11 | + |
| 12 | +namespace NKikimr::NOlap::NNormalizer::NCleanInsertedPortions { |
| 13 | + |
| 14 | +class TCleanInsertedPortionsNormalizer::TNormalizerResult: public INormalizerChanges { |
| 15 | + std::vector<TPortionDataAccessor> InsertedPortions; |
| 16 | + |
| 17 | +public: |
| 18 | + TNormalizerResult(std::vector<TPortionDataAccessor>&& portions) |
| 19 | + : InsertedPortions(std::move(portions)) { |
| 20 | + } |
| 21 | + |
| 22 | + bool ApplyOnExecute(NTabletFlatExecutor::TTransactionContext& txc, const TNormalizationController& normController) const override { |
| 23 | + NOlap::TBlobManagerDb blobManagerDb(txc.DB); |
| 24 | + TDbWrapper db(txc.DB, nullptr); |
| 25 | + for (auto&& portionInfo : InsertedPortions) { |
| 26 | + auto copy = portionInfo.GetPortionInfo().MakeCopy(); |
| 27 | + copy->SetRemoveSnapshot(TSnapshot(1, 1)); |
| 28 | + db.WritePortion(portionInfo.GetBlobIds(), *copy); |
| 29 | + } |
| 30 | + if (InsertedPortions.size()) { |
| 31 | + NIceDb::TNiceDb db(txc.DB); |
| 32 | + normController.AddNormalizerEvent(db, "REMOVE_PORTIONS", DebugString()); |
| 33 | + } |
| 34 | + return true; |
| 35 | + } |
| 36 | + |
| 37 | + void ApplyOnComplete(const TNormalizationController& /* normController */) const override { |
| 38 | + } |
| 39 | + |
| 40 | + ui64 GetSize() const override { |
| 41 | + return InsertedPortions.size(); |
| 42 | + } |
| 43 | + |
| 44 | + TString DebugString() const override { |
| 45 | + TStringBuilder sb; |
| 46 | + ui64 recordsCount = 0; |
| 47 | + sb << "path_ids=["; |
| 48 | + for (auto&& p : InsertedPortions) { |
| 49 | + sb << p.GetPortionInfo().GetPathId() << ","; |
| 50 | + recordsCount += p.GetPortionInfo().GetRecordsCount(); |
| 51 | + } |
| 52 | + sb << "]"; |
| 53 | + sb << ";records_count=" << recordsCount; |
| 54 | + sb << ";inserted_portions_count=" << InsertedPortions.size(); |
| 55 | + return sb; |
| 56 | + } |
| 57 | +}; |
| 58 | + |
| 59 | +bool TCleanInsertedPortionsNormalizer::CheckPortion(const NColumnShard::TTablesManager& /*tablesManager*/, const TPortionDataAccessor& /*portionInfo*/) const { |
| 60 | + return false; |
| 61 | +} |
| 62 | + |
| 63 | +INormalizerTask::TPtr TCleanInsertedPortionsNormalizer::BuildTask( |
| 64 | + std::vector<TPortionDataAccessor>&& portions, std::shared_ptr<THashMap<ui64, ISnapshotSchema::TPtr>>) const { |
| 65 | + std::vector<TPortionDataAccessor> insertedPortions; |
| 66 | + for (auto&& portion : portions) { |
| 67 | + if (portion.GetPortionInfo().GetProduced() == NPortion::EProduced::INSERTED) { |
| 68 | + insertedPortions.push_back(std::move(portion)); |
| 69 | + } |
| 70 | + } |
| 71 | + auto taskResult = std::make_shared<TNormalizerResult>(std::move(insertedPortions)); |
| 72 | + ACFL_WARN("normalizer", "TCleanInsertedPortionsNormalizer")("message", taskResult->DebugString()); |
| 73 | + ACFL_WARN("normalizer", "TCleanInsertedPortionsNormalizer")("all portions", portions.size()); |
| 74 | + return std::make_shared<TTrivialNormalizerTask>(taskResult); |
| 75 | +} |
| 76 | + |
| 77 | +TConclusion<bool> TCleanInsertedPortionsNormalizer::DoInitImpl(const TNormalizationController&, NTabletFlatExecutor::TTransactionContext&) { |
| 78 | + return true; |
| 79 | +} |
| 80 | + |
| 81 | +} // namespace NKikimr::NOlap::NNormalizer::NCleanInsertedPortions |
0 commit comments