This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 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 2d825d5e4e [VFS] Fix PVFS trash behavior for Hadoop TrashPolicy (#5975)
2d825d5e4e is described below
commit 2d825d5e4eafd2e34b5a7300503a1ae79a60dac0
Author: timmyyao <[email protected]>
AuthorDate: Tue Jul 29 21:12:28 2025 +0800
[VFS] Fix PVFS trash behavior for Hadoop TrashPolicy (#5975)
---
.../paimon/vfs/hadoop/PaimonVirtualFileSystem.java | 11 ++++++++++-
.../paimon/vfs/hadoop/VirtualFileSystemTest.java | 19 +++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git
a/paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/PaimonVirtualFileSystem.java
b/paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/PaimonVirtualFileSystem.java
index e18d3f5f59..5cac693539 100644
---
a/paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/PaimonVirtualFileSystem.java
+++
b/paimon-vfs/paimon-vfs-hadoop/src/main/java/org/apache/paimon/vfs/hadoop/PaimonVirtualFileSystem.java
@@ -393,7 +393,16 @@ public class PaimonVirtualFileSystem extends FileSystem {
@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
- VFSIdentifier vfsIdentifier =
vfsOperations.getVFSIdentifier(getVirtualPath(f));
+ String virtualPath = getVirtualPath(f);
+ // Hadoop TrashPolicy will mkdir /user/<root>/.Trash, and we should
reject this operation
+ // and return false, which indicates trash is not supported for
TrashPolicy
+ for (String component : virtualPath.split("/")) {
+ if (component.equals(".Trash")) {
+ LOG.info("PVFS do not support trash directory {}", f);
+ return false;
+ }
+ }
+ VFSIdentifier vfsIdentifier =
vfsOperations.getVFSIdentifier(virtualPath);
if (vfsIdentifier instanceof VFSCatalogIdentifier) {
throw new IOException("Cannot mkdirs for virtual path " + f + "
which is a catalog");
} else if (vfsIdentifier instanceof VFSDatabaseIdentifier) {
diff --git
a/paimon-vfs/paimon-vfs-hadoop/src/test/java/org/apache/paimon/vfs/hadoop/VirtualFileSystemTest.java
b/paimon-vfs/paimon-vfs-hadoop/src/test/java/org/apache/paimon/vfs/hadoop/VirtualFileSystemTest.java
index 0154589c11..d6e50d1fb0 100644
---
a/paimon-vfs/paimon-vfs-hadoop/src/test/java/org/apache/paimon/vfs/hadoop/VirtualFileSystemTest.java
+++
b/paimon-vfs/paimon-vfs-hadoop/src/test/java/org/apache/paimon/vfs/hadoop/VirtualFileSystemTest.java
@@ -34,11 +34,13 @@ import org.apache.paimon.table.Table;
import org.apache.paimon.table.object.ObjectTable;
import org.apache.paimon.types.DataTypes;
+import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.TrashPolicy;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -468,4 +470,21 @@ public abstract class VirtualFileSystemTest {
Assert.assertEquals(
new Path(vfsPath, "schema").toString(),
fileStatuses[0].getPath().toString());
}
+
+ @Test
+ public void testTrash() throws Exception {
+ String databaseName = "test_db";
+ String tableName = "object_table";
+ createObjectTable(databaseName, tableName);
+
+ Path vfsPath = new Path(vfsRoot, databaseName + "/" + tableName +
"/test_dir/file.txt");
+ FSDataOutputStream out = vfs.create(vfsPath);
+ out.write("hello".getBytes());
+ out.close();
+
+ // Trash vfsPath, return false and trash action not executed
+ TrashPolicy trashPolicy = TrashPolicy.getInstance(new Configuration(),
vfs);
+ Assert.assertFalse(trashPolicy.moveToTrash(vfsPath));
+ Assert.assertTrue(vfs.exists(vfsPath));
+ }
}