This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 7a30ef580e [core] Report failed tag and branch renames (#11282)
7a30ef580e is described below

commit 7a30ef580e8d78b3130ba944fce4530b335f5724
Author: YueZhang <[email protected]>
AuthorDate: Thu Nov 19 23:19:19 2026 -0500

    [core] Report failed tag and branch renames (#11282)
---
 .../paimon/utils/FileSystemBranchManager.java      |   7 +-
 .../java/org/apache/paimon/utils/TagManager.java   |   7 +-
 .../apache/paimon/table/MetadataRenameTest.java    | 132 +++++++++++++++++++++
 3 files changed, 144 insertions(+), 2 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/utils/FileSystemBranchManager.java
 
b/paimon-core/src/main/java/org/apache/paimon/utils/FileSystemBranchManager.java
index c84b2559ca..2cd1ef62bd 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/utils/FileSystemBranchManager.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/utils/FileSystemBranchManager.java
@@ -44,6 +44,7 @@ import java.util.stream.Stream;
 
 import static org.apache.paimon.utils.FileUtils.listVersionedDirectories;
 import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.paimon.utils.Preconditions.checkState;
 
 /** A {@link BranchManager} implementation to manage branches via file system. 
*/
 public class FileSystemBranchManager implements BranchManager {
@@ -441,7 +442,11 @@ public class FileSystemBranchManager implements 
BranchManager {
 
         try {
             // Use rename for atomic operation and better performance
-            fileIO.rename(branchPath(fromBranch), branchPath(toBranch));
+            checkState(
+                    fileIO.rename(branchPath(fromBranch), 
branchPath(toBranch)),
+                    "Failed to rename branch '%s' to '%s'.",
+                    fromBranch,
+                    toBranch);
         } catch (IOException e) {
             throw new RuntimeException(
                     String.format(
diff --git a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java 
b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java
index 040046c09a..3c66772a0c 100644
--- a/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java
+++ b/paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java
@@ -53,6 +53,7 @@ import static 
org.apache.paimon.catalog.Identifier.DEFAULT_MAIN_BRANCH;
 import static org.apache.paimon.utils.BranchManager.branchPath;
 import static org.apache.paimon.utils.FileUtils.listVersionedFileStatus;
 import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.paimon.utils.Preconditions.checkState;
 
 /** Manager for {@code Tag}. */
 public class TagManager {
@@ -201,7 +202,11 @@ public class TagManager {
         checkArgument(!tagExists(targetTagName), "Tag '%s' already exists.", 
targetTagName);
 
         try {
-            fileIO.rename(tagPath(tagName), tagPath(targetTagName));
+            checkState(
+                    fileIO.rename(tagPath(tagName), tagPath(targetTagName)),
+                    "Failed to rename tag '%s' to '%s'.",
+                    tagName,
+                    targetTagName);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/table/MetadataRenameTest.java 
b/paimon-core/src/test/java/org/apache/paimon/table/MetadataRenameTest.java
new file mode 100644
index 0000000000..88ec5df459
--- /dev/null
+++ b/paimon-core/src/test/java/org/apache/paimon/table/MetadataRenameTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+
+package org.apache.paimon.table;
+
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.types.DataTypes;
+import org.apache.paimon.utils.FileSystemBranchManager;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.spy;
+
+/** Tests filesystem failures when renaming persisted table tags and branches. 
*/
+class MetadataRenameTest extends TableTestBase {
+
+    @Test
+    void testRejectedTagRenameCanBeRetried() throws Exception {
+        FileStoreTable original = createTaggedTable();
+        FileIO fileIO = spy(original.fileIO());
+        FileStoreTable table = FileStoreTableFactory.create(fileIO, 
original.location());
+        Path source = table.tagManager().tagPath("old");
+        Path target = table.tagManager().tagPath("new");
+        doReturn(false).when(fileIO).rename(source, target);
+
+        assertThatThrownBy(() -> table.renameTag("old", "new"))
+                .isInstanceOf(IllegalStateException.class)
+                .hasMessage("Failed to rename tag 'old' to 'new'.");
+        assertThat(table.tagManager().tagExists("old")).isTrue();
+        assertThat(table.tagManager().tagExists("new")).isFalse();
+
+        doCallRealMethod().when(fileIO).rename(source, target);
+        table.renameTag("old", "new");
+        assertThat(table.tagManager().tagExists("old")).isFalse();
+        assertThat(table.tagManager().getOrThrow("new").id())
+                .isEqualTo(original.latestSnapshot().get().id());
+    }
+
+    @Test
+    void testTagRenamePreservesIOException() throws Exception {
+        FileStoreTable original = createTaggedTable();
+        FileIO fileIO = spy(original.fileIO());
+        FileStoreTable table = FileStoreTableFactory.create(fileIO, 
original.location());
+        IOException failure = new IOException("rename unavailable");
+        doThrow(failure)
+                .when(fileIO)
+                .rename(table.tagManager().tagPath("old"), 
table.tagManager().tagPath("new"));
+
+        assertThatThrownBy(() -> table.renameTag("old", "new"))
+                .isInstanceOf(RuntimeException.class)
+                .hasCause(failure);
+        assertThat(table.tagManager().tagExists("old")).isTrue();
+        assertThat(table.tagManager().tagExists("new")).isFalse();
+    }
+
+    @Test
+    void testRejectedBranchRenameCanBeRetried() throws Exception {
+        FileStoreTable original = createTaggedTable();
+        original.createBranch("old", "old");
+        FileIO fileIO = spy(original.fileIO());
+        FileStoreTable table = FileStoreTableFactory.create(fileIO, 
original.location());
+        FileSystemBranchManager branches = (FileSystemBranchManager) 
table.branchManager();
+        Path source = branches.branchPath("old");
+        Path target = branches.branchPath("new");
+        doReturn(false).when(fileIO).rename(source, target);
+
+        assertThatThrownBy(() -> table.renameBranch("old", "new"))
+                .isInstanceOf(IllegalStateException.class)
+                .hasMessage("Failed to rename branch 'old' to 'new'.");
+        assertThat(branches.branchExists("old")).isTrue();
+        assertThat(branches.branchExists("new")).isFalse();
+
+        doCallRealMethod().when(fileIO).rename(source, target);
+        table.renameBranch("old", "new");
+        assertThat(branches.branchExists("old")).isFalse();
+        assertThat(table.switchToBranch("new").latestSnapshot().get().id())
+                .isEqualTo(original.latestSnapshot().get().id());
+    }
+
+    @Test
+    void testBranchRenamePreservesIOException() throws Exception {
+        FileStoreTable original = createTaggedTable();
+        original.createBranch("old", "old");
+        FileIO fileIO = spy(original.fileIO());
+        FileStoreTable table = FileStoreTableFactory.create(fileIO, 
original.location());
+        FileSystemBranchManager branches = (FileSystemBranchManager) 
table.branchManager();
+        IOException failure = new IOException("rename unavailable");
+        doThrow(failure)
+                .when(fileIO)
+                .rename(branches.branchPath("old"), 
branches.branchPath("new"));
+
+        assertThatThrownBy(() -> table.renameBranch("old", "new"))
+                .isInstanceOf(RuntimeException.class)
+                .hasCause(failure);
+        assertThat(branches.branchExists("old")).isTrue();
+        assertThat(branches.branchExists("new")).isFalse();
+    }
+
+    private FileStoreTable createTaggedTable() throws Exception {
+        catalog.createTable(
+                identifier(), Schema.newBuilder().column("id", 
DataTypes.INT()).build(), false);
+        FileStoreTable table = (FileStoreTable) catalog.getTable(identifier());
+        write(table, GenericRow.of(1));
+        table.createTag("old");
+        return table;
+    }
+}

Reply via email to