wgtmac commented on code in PR #699: URL: https://github.com/apache/iceberg-cpp/pull/699#discussion_r3418870186
########## src/iceberg/update/merge_append.cc: ########## @@ -0,0 +1,64 @@ +/* + * 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. + */ + +#include "iceberg/update/merge_append.h" + +#include "iceberg/constants.h" +#include "iceberg/manifest/manifest_list.h" +#include "iceberg/snapshot.h" +#include "iceberg/table_metadata.h" +#include "iceberg/transaction.h" +#include "iceberg/util/error_collector.h" +#include "iceberg/util/macros.h" + +namespace iceberg { + +Result<std::unique_ptr<MergeAppend>> MergeAppend::Make( + std::string table_name, std::shared_ptr<TransactionContext> ctx) { + ICEBERG_PRECHECK(!table_name.empty(), "Table name cannot be empty"); + ICEBERG_PRECHECK(ctx != nullptr, "Cannot create MergeAppend without a context"); + return std::unique_ptr<MergeAppend>( + new MergeAppend(std::move(table_name), std::move(ctx))); +} + +MergeAppend::MergeAppend(std::string table_name, std::shared_ptr<TransactionContext> ctx) + : MergingSnapshotUpdate(std::move(table_name), std::move(ctx)) {} + +MergeAppend& MergeAppend::AppendFile(const std::shared_ptr<DataFile>& file) { + ICEBERG_BUILDER_RETURN_IF_ERROR(AddDataFile(file)); + return *this; +} + +MergeAppend& MergeAppend::AppendManifest(const ManifestFile& manifest) { + ICEBERG_BUILDER_CHECK(!manifest.has_existing_files(), + "Cannot append manifest with existing files"); + ICEBERG_BUILDER_CHECK(!manifest.has_deleted_files(), + "Cannot append manifest with deleted files"); + ICEBERG_BUILDER_CHECK(manifest.added_snapshot_id == kInvalidSnapshotId, + "Snapshot id must be assigned during commit"); + ICEBERG_BUILDER_CHECK(manifest.sequence_number == kInvalidSequenceNumber, + "Sequence number must be assigned during commit"); + + ICEBERG_BUILDER_RETURN_IF_ERROR(AddManifest(manifest)); Review Comment: This path can reuse a deleted copied manifest on retry. In v1, AddManifest immediately copies into rewritten_append_manifests_. If a commit retry refreshes to a new base, SnapshotUpdate::Apply first calls CleanUncommitted({}), which deletes those copied manifests but keeps the vector. The next Apply can then write a manifest list that points at the deleted path, or fail when merge reads it. FastAppend has the same pattern, but this PR exposes it through MergeAppend; this needs either clearing/re-copying or delaying cleanup until retry is done. -- 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]
