cmcarthur commented on code in PR #1455:
URL: https://github.com/apache/iceberg-rust/pull/1455#discussion_r2159428085


##########
crates/iceberg/src/maintenance/expire_snapshots.rs:
##########
@@ -0,0 +1,1144 @@
+// 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.
+
+//! Expire snapshots maintenance operation
+//!
+//! This module implements the expire snapshots operation that removes old 
snapshots
+//! and their associated metadata files from the table while keeping the table
+//! in a consistent state.
+
+use std::collections::HashSet;
+
+use async_trait::async_trait;
+use serde::{Deserialize, Serialize};
+
+use crate::error::Result;
+use crate::runtime::JoinHandle;
+use crate::spec::SnapshotRef;
+use crate::table::Table;
+use crate::transaction::Transaction;
+use crate::{Catalog, Error, ErrorKind, TableUpdate};
+
+/// Result of the expire snapshots operation. Contains information about how 
many files were
+/// deleted.
+#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub struct ExpireSnapshotsResult {
+    /// Number of data files deleted. Data file deletion is not supported by 
this action yet, this
+    /// will always be 0.
+    pub deleted_data_files_count: u64,
+    /// Number of position delete files deleted. Position delete file deletion 
is not supported by
+    /// this action yet, this will always be 0.
+    pub deleted_position_delete_files_count: u64,
+    /// Number of equality delete files deleted. Equality delete file deletion 
is not supported by
+    /// this action yet, this will always be 0.
+    pub deleted_equality_delete_files_count: u64,
+    /// Number of manifest files deleted
+    pub deleted_manifest_files_count: u64,
+    /// Number of manifest list files deleted
+    pub deleted_manifest_lists_count: u64,
+    /// Number of statistics files deleted. Statistics file deletion is not 
supported by this action
+    /// yet, this will always be 0.
+    pub deleted_statistics_files_count: u64,
+}
+
+/// Configuration for the expire snapshots operation
+#[derive(Debug, Clone)]
+pub struct ExpireSnapshotsConfig {
+    /// Timestamp in milliseconds. Snapshots older than this will be expired
+    pub older_than_ms: Option<i64>,
+    /// Minimum number of snapshots to retain
+    pub retain_last: Option<u32>,
+    /// Maximum number of concurrent file deletions
+    pub max_concurrent_deletes: Option<u32>,
+    /// Specific snapshot IDs to expire
+    pub snapshot_ids: Vec<i64>,
+    /// Whether to perform a dry run. If true, the operation will not delete 
any files, but will
+    /// still identify the files to delete and return the result.
+    pub dry_run: bool,
+}
+
+impl Default for ExpireSnapshotsConfig {
+    fn default() -> Self {
+        Self {
+            older_than_ms: None,
+            retain_last: Some(1), // Default to retaining at least 1 snapshot
+            max_concurrent_deletes: None,
+            snapshot_ids: vec![],
+            dry_run: false,
+        }
+    }
+}
+
+/// Trait for performing expire snapshots operations
+///
+/// This trait provides a low-level API for expiring snapshots that can be
+/// extended with different implementations for different environments.
+#[async_trait]
+pub trait ExpireSnapshots: Send + Sync {
+    /// Execute the expire snapshots operation
+    async fn execute(&self, catalog: &dyn Catalog) -> 
Result<ExpireSnapshotsResult>;
+}
+
+/// Implementation of the expire snapshots operation
+pub struct ExpireSnapshotsAction {
+    table: Table,
+    config: ExpireSnapshotsConfig,
+}

Review Comment:
   I think I follow, let me give it a shot.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to