|
| 1 | +/* |
| 2 | + * Copyright 2026-present Alibaba Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#pragma once |
| 18 | + |
| 19 | +#include <map> |
| 20 | +#include <memory> |
| 21 | +#include <string> |
| 22 | +#include <vector> |
| 23 | + |
| 24 | +#include "paimon/result.h" |
| 25 | + |
| 26 | +namespace paimon { |
| 27 | + |
| 28 | +class CommitMessage; |
| 29 | +class FileSystem; |
| 30 | +class MemoryPool; |
| 31 | + |
| 32 | +/// Compact coordinator for append-only unaware-bucket tables. |
| 33 | +/// |
| 34 | +/// This coordinator scans the latest snapshot for small files, groups them by partition, |
| 35 | +/// and generates compaction tasks using a bin-packing algorithm. It then synchronously |
| 36 | +/// executes all tasks and returns the resulting commit messages. |
| 37 | +/// |
| 38 | +/// @note This implementation does not support deletion vectors or streaming mode. |
| 39 | +/// It only scans the current latest snapshot (batch mode). |
| 40 | +class PAIMON_EXPORT AppendCompactCoordinator { |
| 41 | + public: |
| 42 | + AppendCompactCoordinator() = delete; |
| 43 | + ~AppendCompactCoordinator() = delete; |
| 44 | + /// Run the compaction coordinator. |
| 45 | + /// |
| 46 | + /// Scans the latest snapshot for small files across the specified partitions, |
| 47 | + /// generates compact tasks via bin-packing, executes them synchronously, |
| 48 | + /// and returns the resulting commit messages. |
| 49 | + /// |
| 50 | + /// @param table_path The root path of the table. |
| 51 | + /// @param options User-defined options (will be merged with schema options). |
| 52 | + /// @param partitions Partition filters; each element is a partition spec as key-value pairs. |
| 53 | + /// Empty vector means all partitions. |
| 54 | + /// @param file_system The file system to use. If nullptr, will be created from options. |
| 55 | + /// @param pool The memory pool to use. If nullptr, will use default pool. |
| 56 | + /// @return Result containing a vector of commit messages from compaction tasks. |
| 57 | + static Result<std::vector<std::shared_ptr<CommitMessage>>> Run( |
| 58 | + const std::string& table_path, const std::map<std::string, std::string>& options, |
| 59 | + const std::vector<std::map<std::string, std::string>>& partitions, |
| 60 | + const std::shared_ptr<FileSystem>& file_system, const std::shared_ptr<MemoryPool>& pool); |
| 61 | +}; |
| 62 | + |
| 63 | +} // namespace paimon |
0 commit comments