iceberg-cpp
Loading...
Searching...
No Matches
manifest_merge_manager.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <cstdint>
26#include <functional>
27#include <memory>
28#include <string>
29#include <unordered_map>
30#include <unordered_set>
31#include <vector>
32
33#include "iceberg/iceberg_export.h"
36#include "iceberg/result.h"
37#include "iceberg/type_fwd.h"
38
39namespace iceberg {
40
50class ICEBERG_EXPORT ManifestMergeManager {
51 public:
52 using SnapshotIdSupplier = std::function<int64_t()>;
53
63 static Result<std::unique_ptr<ManifestMergeManager>> Make(
64 ManifestContent content, int64_t target_size_bytes, int32_t min_count_to_merge,
65 bool merge_enabled, std::shared_ptr<FileIO> file_io,
66 SnapshotIdSupplier snapshot_id_supplier,
67 std::function<Status(const std::string&)> delete_file = {});
68
70 ManifestMergeManager& operator=(const ManifestMergeManager&) = delete;
71
84 Result<std::vector<ManifestFile>> MergeManifests(
85 const std::vector<ManifestFile>& existing_manifests,
86 const std::vector<ManifestFile>& new_manifests, const TableMetadata& metadata,
87 const ManifestWriterFactory& writer_factory);
88
90 int32_t ReplacedManifestsCount() const { return replaced_manifests_count_; }
91
94 Status CleanUncommitted(const std::unordered_set<std::string>& committed);
95
96 private:
97 ManifestMergeManager(ManifestContent content, int64_t target_size_bytes,
98 int32_t min_count_to_merge, bool merge_enabled,
99 std::shared_ptr<FileIO> file_io,
100 SnapshotIdSupplier snapshot_id_supplier,
101 std::function<Status(const std::string&)> delete_file);
102
103 struct MergedManifestCache {
104 struct Key {
105 std::vector<ManifestFile> bin;
106 bool operator==(const Key& other) const = default;
107 };
108
109 struct KeyHash {
110 size_t operator()(const Key& key) const;
111 };
112
113 const ManifestFile* Find(const std::vector<const ManifestFile*>& bin) const;
114 void Add(const std::vector<const ManifestFile*>& bin, const ManifestFile& manifest);
115 bool empty() const { return entries_.empty(); }
116 Result<int32_t> CleanUncommitted(
117 const std::unordered_set<std::string>& committed, int64_t snapshot_id,
118 const std::function<Status(const std::string&)>& delete_file);
119
120 private:
121 static Key MakeKey(const std::vector<const ManifestFile*>& bin);
122
123 std::unordered_map<Key, ManifestFile, KeyHash> entries_;
124 };
125
130 Result<std::vector<ManifestFile>> MergeGroup(
131 const std::vector<const ManifestFile*>& group, const ManifestFile* first,
132 const TableMetadata& metadata, const ManifestWriterFactory& writer_factory);
133
141 Result<ManifestFile> FlushBin(const std::vector<const ManifestFile*>& bin,
142 const TableMetadata& metadata,
143 const ManifestWriterFactory& writer_factory);
144
145 const ManifestContent manifest_content_;
146 const int64_t target_size_bytes_;
147 const int32_t min_count_to_merge_;
148 const bool merge_enabled_;
149 std::shared_ptr<FileIO> file_io_;
150 SnapshotIdSupplier snapshot_id_supplier_;
151 std::function<Status(const std::string&)> delete_file_;
152 int32_t replaced_manifests_count_{0};
153 MergedManifestCache merged_manifests_;
154};
155
156} // namespace iceberg
Merges small manifests into larger ones using greedy bin-packing.
Definition manifest_merge_manager.h:50
int32_t ReplacedManifestsCount() const
Returns the number of manifests replaced by cached merged outputs.
Definition manifest_merge_manager.h:90
ManifestContent
The type of files tracked by the manifest, either data or delete files; 0 for all v1 manifests.
Definition manifest_list.h:77
std::function< Result< std::unique_ptr< ManifestWriter > >(int32_t spec_id, ManifestContent content)> ManifestWriterFactory
Factory type for creating ManifestWriter instances.
Definition manifest_writer.h:169
Entry in a manifest list.
Definition manifest_list.h:85
Definition manifest_merge_manager.h:104
Represents the metadata for an Iceberg table.
Definition table_metadata.h:73