This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 1c0e5793 feat(catalog): allow deleting tags after their snapshots
expire (#1367)
1c0e5793 is described below
commit 1c0e579392288e13133ef384c1ff60c97534f298
Author: AuroraVoyage <[email protected]>
AuthorDate: Wed Nov 11 10:58:53 2026 +0800
feat(catalog): allow deleting tags after their snapshots expire (#1367)
---
crates/paimon/src/catalog/filesystem.rs | 141 +++++++++++++++++++++-----------
crates/paimon/src/catalog/mod.rs | 5 +-
2 files changed, 94 insertions(+), 52 deletions(-)
diff --git a/crates/paimon/src/catalog/filesystem.rs
b/crates/paimon/src/catalog/filesystem.rs
index 0689545b..1240f0c9 100644
--- a/crates/paimon/src/catalog/filesystem.rs
+++ b/crates/paimon/src/catalog/filesystem.rs
@@ -645,7 +645,10 @@ impl Catalog for FileSystemCatalog {
) -> Result<()> {
let table = self.get_table(identifier).await?;
let manager = table.tag_manager();
- let Some(snapshot) = manager.get(tag_name).await? else {
+ // Match Java TagManager.deleteTag: delete the tag meta file only.
+ // Referenced data files are left for orphan cleanup, and an expired
+ // snapshot must not block deleting the tag.
+ if manager.get(tag_name).await?.is_none() {
return if ignore_if_not_exists {
Ok(())
} else {
@@ -653,15 +656,8 @@ impl Catalog for FileSystemCatalog {
tag_name: tag_name.to_string(),
})
};
- };
- match table.snapshot_manager().get_snapshot(snapshot.id()).await {
- Ok(_) => manager.delete(tag_name).await,
- Err(Error::SnapshotNotExist { .. }) => Err(Error::Unsupported {
- message: "deleting a tag after its snapshot expired is not
supported by FileSystemCatalog"
- .to_string(),
- }),
- Err(error) => Err(error),
}
+ manager.delete(tag_name).await
}
}
@@ -1466,47 +1462,6 @@ mod tests {
assert_eq!(tag.tag_time_retained.as_deref(), Some("PT24H"));
}
- #[tokio::test]
- async fn test_delete_expired_tag_is_unsupported() {
- let (_temp_dir, catalog) = create_test_catalog();
- catalog
- .create_database("db1", false, HashMap::new())
- .await
- .unwrap();
- let identifier = Identifier::new("db1", "t");
- catalog
- .create_table(&identifier, testing_schema(), false)
- .await
- .unwrap();
- give_the_table_a_snapshot(&catalog, &identifier).await;
- catalog
- .create_tag(&identifier, "release-1", Some(1), false)
- .await
- .unwrap();
-
- catalog
- .get_table(&identifier)
- .await
- .unwrap()
- .snapshot_manager()
- .delete_snapshot(1)
- .await
- .unwrap();
- assert!(matches!(
- catalog.delete_tag(&identifier, "release-1", false).await,
- Err(Error::Unsupported { .. })
- ));
- assert_eq!(
- catalog
- .get_tag(&identifier, "release-1")
- .await
- .unwrap()
- .snapshot
- .id(),
- 1
- );
- }
-
#[test]
fn test_format_tag_time_retained() {
for (seconds, expected) in [
@@ -2737,3 +2692,89 @@ mod tests {
);
}
}
+
+/// Tag-cleanup coverage that must also run on Windows. Uses the in-memory
+/// warehouse so it is not blocked by the local-fs directory listing skip
above.
+#[cfg(test)]
+mod delete_expired_tag_tests {
+ use super::*;
+ use crate::spec::{CommitKind, Snapshot};
+ use crate::table::SnapshotManager;
+ use std::collections::HashMap;
+
+ fn create_memory_catalog() -> FileSystemCatalog {
+ let mut options = Options::new();
+ options.set(CatalogOptions::WAREHOUSE,
"memory:/warehouse-tag-cleanup");
+ FileSystemCatalog::new(options).unwrap()
+ }
+
+ fn testing_schema() -> Schema {
+ Schema::builder()
+ .column(
+ "id",
+ crate::spec::DataType::Int(crate::spec::IntType::new()),
+ )
+ .build()
+ .unwrap()
+ }
+
+ async fn give_the_table_a_snapshot(catalog: &FileSystemCatalog,
identifier: &Identifier) {
+ let table_path = catalog.table_path(identifier);
+ let snapshot = Snapshot::builder()
+ .version(3)
+ .id(1)
+ .schema_id(0)
+ .base_manifest_list("base-list".to_string())
+ .delta_manifest_list("delta-list".to_string())
+ .commit_user("test-user".to_string())
+ .commit_identifier(0)
+ .commit_kind(CommitKind::APPEND)
+ .time_millis(1000)
+ .build();
+ assert!(
+ SnapshotManager::new(catalog.file_io.clone(), table_path)
+ .commit_snapshot(&snapshot)
+ .await
+ .unwrap(),
+ "the fixture snapshot must be the table's first"
+ );
+ }
+
+ #[tokio::test]
+ async fn test_delete_expired_tag_removes_tag_file() {
+ let catalog = create_memory_catalog();
+ catalog
+ .create_database("db1", false, HashMap::new())
+ .await
+ .unwrap();
+ let identifier = Identifier::new("db1", "t");
+ catalog
+ .create_table(&identifier, testing_schema(), false)
+ .await
+ .unwrap();
+ give_the_table_a_snapshot(&catalog, &identifier).await;
+ catalog
+ .create_tag(&identifier, "release-1", Some(1), false)
+ .await
+ .unwrap();
+
+ catalog
+ .get_table(&identifier)
+ .await
+ .unwrap()
+ .snapshot_manager()
+ .delete_snapshot(1)
+ .await
+ .unwrap();
+ // Java TagManager.deleteTag only removes the tag meta file; orphan
data
+ // cleanup is separate. Expired snapshots must not block tag deletion.
+ catalog
+ .delete_tag(&identifier, "release-1", false)
+ .await
+ .unwrap();
+ assert!(matches!(
+ catalog.get_tag(&identifier, "release-1").await,
+ Err(Error::TagNotExist { .. })
+ ));
+ }
+}
diff --git a/crates/paimon/src/catalog/mod.rs b/crates/paimon/src/catalog/mod.rs
index 3c5923b1..3cf2cf97 100644
--- a/crates/paimon/src/catalog/mod.rs
+++ b/crates/paimon/src/catalog/mod.rs
@@ -557,8 +557,9 @@ pub trait Catalog: Send + Sync {
/// Delete a tag.
///
- /// `FileSystemCatalog` returns [`crate::Error::Unsupported`] when the
tagged snapshot has
- /// expired because Rust does not yet implement Java's tag file cleanup.
+ /// Deletes the tag meta file even when the tagged snapshot has already
+ /// expired (Java `TagManager.deleteTag`). Referenced data files are left
+ /// for orphan cleanup.
async fn delete_tag(
&self,
_identifier: &Identifier,