CTTY commented on code in PR #3564: URL: https://github.com/apache/iceberg-rust/pull/3564#discussion_r4766506514
########## crates/iceberg/src/transaction/snapshot/manifest_filter.rs: ########## @@ -0,0 +1,316 @@ +// 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. + +//! Rewrites existing manifests to mark files as deleted. + +use std::collections::{HashMap, HashSet}; + +use uuid::Uuid; + +use super::{manifest_path, new_manifest_writer}; +use crate::error::{Result, invalid_data}; +use crate::io::object_cache::ManifestKey; +use crate::spec::{DataFile, DataFileFormat, FormatVersion, ManifestContentType, ManifestFile}; +use crate::table::Table; + +/// Identifies one entry to mark as `Deleted`, a data file or a delete file. +/// +/// A path alone is not enough: a Puffin file may hold several deletion +/// vectors, each its own entry at a distinct blob offset. Data files and +/// non-DV delete files have no offset, so for them this is the path. +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +struct RemovedFileIdentity { + /// The absolute path, as stored in the manifest entry. Comparison is + /// textual, so a relative path would not match the entry it names. + path: String, + content_offset: Option<i64>, + content_size_in_bytes: Option<i64>, +} + +impl RemovedFileIdentity { + fn of(file: &DataFile) -> Self { + Self { + path: file.file_path().to_string(), + content_offset: file.content_offset(), + content_size_in_bytes: file.content_size_in_bytes(), + } + } +} + +impl std::fmt::Display for RemovedFileIdentity { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match (self.content_offset, self.content_size_in_bytes) { + (Some(offset), Some(size)) => write!(f, "{}@{offset}+{size}", self.path), + _ => f.write_str(&self.path), + } + } +} + +/// Removes a fixed set of files from the manifests of one content type. +/// +/// One manager lives for one logical execution of an action and is driven +/// once per attempt via [`ManifestFilterManager::filter`]. A manifest that +/// references none of the files passes through untouched. One that does is +/// rewritten with those entries marked `Deleted` and the rest `Existing`. +/// +/// A rewrite is reused across attempts while its inputs are unchanged. Its +/// entries carry the sequence numbers and row ids the source's entries +/// inherited from the manifest list when they were read, so the reuse key is +/// the source's [`ManifestKey`], not its path alone: a transaction-local +/// source manifest keeps its path across attempts but inherits new values +/// after a rebase. +pub(crate) struct ManifestFilterManager { + content: ManifestContentType, + /// The files to remove, by absolute path (and blob range for deletion + /// vectors). Fixed for the execution. + files_to_remove: HashSet<RemovedFileIdentity>, + /// Whether a file to remove that is not live in any manifest fails the + /// attempt. Off lets a retry succeed after a concurrent commit removed the + /// same file; the action decides which it needs. + fail_missing_delete_paths: bool, + /// Absolute paths of the data files the commit removes. A deletion vector + /// referencing one of them is dangling and is marked `Deleted` too. Not + /// required to be found, unlike `files_to_remove`. Only set on the delete + /// filter; see [`Self::with_dangling_dvs_for`]. + removed_data_file_paths: HashSet<String>, + /// Source manifest → rewritten result. + filtered: HashMap<ManifestKey, FilteredManifest>, + /// Format version the rewrites were written under. Per spec, v1 entries + /// cannot inherit sequence numbers, so an upgrade invalidates them. + format_version: Option<FormatVersion>, Review Comment: We cannot initialize the format version when initializing this struct, because there may be format upgrade that could invalidate our cache -- 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]
