wgtmac commented on code in PR #652:
URL: https://github.com/apache/iceberg-cpp/pull/652#discussion_r3231910580


##########
src/iceberg/manifest/manifest_merge_manager.h:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+/// \file iceberg/manifest/manifest_merge_manager.h
+/// Merges small manifests into fewer larger ones according to table 
properties.
+
+#include <cstdint>
+#include <memory>
+#include <vector>
+
+#include "iceberg/iceberg_export.h"
+#include "iceberg/manifest/manifest_filter_manager.h"
+#include "iceberg/manifest/manifest_list.h"
+#include "iceberg/result.h"
+#include "iceberg/type_fwd.h"
+
+namespace iceberg {
+
+/// \brief Merges small manifests into larger ones using greedy bin-packing.
+///
+/// Manifests are grouped by partition_spec_id before merging; manifests with
+/// different spec IDs are never merged together.  Within a group, manifests 
are
+/// accumulated into bins until a bin would exceed target_size_bytes, at which
+/// point the bin is flushed (written) and a new one started.  Manifests 
already
+/// larger than target_size_bytes pass through unchanged.
+///
+/// \note This class is non-copyable and non-movable.
+class ICEBERG_EXPORT ManifestMergeManager {
+ public:
+  /// \brief Construct a merge manager with the given configuration.
+  ///
+  /// \param target_size_bytes Target output manifest size in bytes
+  /// \param min_count_to_merge Minimum number of manifests before any merging 
occurs
+  /// \param merge_enabled Whether merging is enabled at all
+  ManifestMergeManager(int64_t target_size_bytes, int32_t min_count_to_merge,
+                       bool merge_enabled);
+
+  ManifestMergeManager(const ManifestMergeManager&) = delete;
+  ManifestMergeManager& operator=(const ManifestMergeManager&) = delete;
+
+  /// \brief Merge existing and new manifests according to configured 
thresholds.
+  ///
+  /// \param existing_manifests Manifests already in the base snapshot
+  /// \param new_manifests Newly written manifests to incorporate
+  /// \param snapshot_id The ID of the snapshot being committed.  Used to 
preserve
+  ///   ADDED/DELETED status for entries written by this snapshot and to 
suppress
+  ///   stale DELETED tombstones from prior snapshots.
+  /// \param metadata Table metadata (provides specs and schema for readers)
+  /// \param file_io File IO used to open existing manifests for reading
+  /// \param writer_factory Factory to create new ManifestWriter instances
+  /// \return The merged manifest list, or an error
+  Result<std::vector<ManifestFile>> MergeManifests(

Review Comment:
   Could this manager expose the lifecycle state Java relies on for retries? 
Java ManifestMergeManager caches merged manifests, reports 
replacedManifestsCount(), and has cleanUncommitted(committed) so 
MergingSnapshotProducer can delete manifests produced by failed retry attempts 
and build created/kept/replaced summary accurately. This API only returns the 
final vector, so the later snapshot update layer has no way to distinguish 
committed vs uncommitted merged outputs or count replaced manifests 
consistently with Java tests such as transaction retry merge cleanup. The same 
lifecycle surface is also needed on the filter side for rewritten manifests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to