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 60e45f6014 [core] Report failed filesystem table directory deletion
(#11336)
60e45f6014 is described below
commit 60e45f60145393a77e30cfd458664f545b332b45
Author: YueZhang <[email protected]>
AuthorDate: Sun Nov 22 05:52:28 2026 -0500
[core] Report failed filesystem table directory deletion (#11336)
---
.../org/apache/paimon/catalog/CachingCatalog.java | 8 +-
.../apache/paimon/catalog/FileSystemCatalog.java | 20 ++-
.../FileSystemCatalogDeleteFailureTest.java | 195 +++++++++++++++++++++
3 files changed, 219 insertions(+), 4 deletions(-)
diff --git
a/paimon-core/src/main/java/org/apache/paimon/catalog/CachingCatalog.java
b/paimon-core/src/main/java/org/apache/paimon/catalog/CachingCatalog.java
index 037f7ea2bf..9b98a605fb 100644
--- a/paimon-core/src/main/java/org/apache/paimon/catalog/CachingCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/catalog/CachingCatalog.java
@@ -220,8 +220,12 @@ public class CachingCatalog extends DelegateCatalog {
@Override
public void dropTable(Identifier identifier, boolean ignoreIfNotExists)
throws TableNotExistException {
- super.dropTable(identifier, ignoreIfNotExists);
- invalidateTable(identifier);
+ try {
+ super.dropTable(identifier, ignoreIfNotExists);
+ } finally {
+ // a failed drop may already have removed the table
+ invalidateTable(identifier);
+ }
// clear all branch tables of this table
for (Identifier i : tableCache.asMap().keySet()) {
diff --git
a/paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java
b/paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java
index 771dbdfe32..2a20e48836 100644
--- a/paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/catalog/FileSystemCatalog.java
@@ -28,6 +28,7 @@ import org.apache.paimon.schema.SchemaChange;
import org.apache.paimon.schema.SchemaManager;
import org.apache.paimon.schema.TableSchema;
import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -121,9 +122,24 @@ public class FileSystemCatalog extends AbstractCatalog {
@Override
protected void dropTableImpl(Identifier identifier, List<Path>
externalPaths) {
Path path = getTableLocation(identifier);
- uncheck(() -> fileIO.delete(path, true));
+ deleteDirectory(path);
+ // The drop cannot be retried once the table is gone, so attempt every
external path.
+ RuntimeException failure = null;
for (Path externalPath : externalPaths) {
- uncheck(() -> fileIO.delete(externalPath, true));
+ try {
+ deleteDirectory(externalPath);
+ } catch (RuntimeException e) {
+ failure = ExceptionUtils.firstOrSuppressed(e, failure);
+ }
+ }
+ if (failure != null) {
+ throw failure;
+ }
+ }
+
+ private void deleteDirectory(Path path) {
+ if (!uncheck(() -> fileIO.delete(path, true)) && uncheck(() ->
fileIO.exists(path))) {
+ throw new RuntimeException(String.format("Failed to delete
directory %s.", path));
}
}
diff --git
a/paimon-core/src/test/java/org/apache/paimon/catalog/FileSystemCatalogDeleteFailureTest.java
b/paimon-core/src/test/java/org/apache/paimon/catalog/FileSystemCatalogDeleteFailureTest.java
new file mode 100644
index 0000000000..5b73c62c89
--- /dev/null
+++
b/paimon-core/src/test/java/org/apache/paimon/catalog/FileSystemCatalogDeleteFailureTest.java
@@ -0,0 +1,195 @@
+/*
+ * 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.catalog;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.fs.local.LocalFileIO;
+import org.apache.paimon.options.Options;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.types.DataTypes;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.catchThrowable;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+/** Tests that filesystem catalog drops do not report success after failed
deletions. */
+class FileSystemCatalogDeleteFailureTest {
+
+ private static final Identifier IDENTIFIER = Identifier.create("db", "t");
+
+ @TempDir java.nio.file.Path tempDir;
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testFailedTableDirectoryDeletion(boolean ignoreIfNotExists) throws
Exception {
+ FileIO fileIO = spy(LocalFileIO.create());
+ Path external = new Path(tempDir.resolve("external").toUri());
+ fileIO.mkdirs(external);
+ FileSystemCatalog catalog = createCatalog(fileIO, external);
+ Path tablePath = catalog.getTableLocation(IDENTIFIER);
+ doReturn(false).when(fileIO).delete(tablePath, true);
+
+ assertThatThrownBy(() -> catalog.dropTable(IDENTIFIER,
ignoreIfNotExists))
+ .isInstanceOf(RuntimeException.class)
+ .hasStackTraceContaining(tablePath.toString());
+ assertThat(fileIO.exists(tablePath)).isTrue();
+ assertThat(fileIO.exists(external)).isTrue();
+ assertThat(catalog.getTable(IDENTIFIER)).isNotNull();
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testFailedExternalDirectoryDeletion(boolean ignoreIfNotExists) throws
Exception {
+ FileIO fileIO = spy(LocalFileIO.create());
+ Path external = new Path(tempDir.resolve("external").toUri());
+ fileIO.mkdirs(external);
+ FileSystemCatalog catalog = createCatalog(fileIO, external);
+ doReturn(false).when(fileIO).delete(external, true);
+
+ assertThatThrownBy(() -> catalog.dropTable(IDENTIFIER,
ignoreIfNotExists))
+ .isInstanceOf(RuntimeException.class)
+ .hasStackTraceContaining(external.toString());
+ assertThat(fileIO.exists(external)).isTrue();
+ }
+
+ @Test
+ void testFailedExternalDeletionStillCompletesDrop() throws Exception {
+ FileIO fileIO = spy(LocalFileIO.create());
+ Path first = new Path(tempDir.resolve("first").toUri());
+ Path second = new Path(tempDir.resolve("second").toUri());
+ fileIO.mkdirs(first);
+ fileIO.mkdirs(second);
+ FileSystemCatalog catalog = createCatalog(fileIO, first);
+ catalog.alterTable(
+ IDENTIFIER,
+ SchemaChange.setOption(
+ CoreOptions.DATA_FILE_EXTERNAL_PATHS.key(),
second.toString()),
+ false);
+ Catalog cachingCatalog = new CachingCatalog(catalog, new Options());
+ cachingCatalog.getTable(IDENTIFIER);
+ // The iteration order is unspecified, so fail whichever external path
is deleted first.
+ AtomicBoolean failed = new AtomicBoolean();
+ doAnswer(
+ invocation -> {
+ Path path = invocation.getArgument(0);
+ if ((path.equals(first) || path.equals(second))
+ && failed.compareAndSet(false, true)) {
+ return false;
+ }
+ return invocation.callRealMethod();
+ })
+ .when(fileIO)
+ .delete(any(Path.class), eq(true));
+
+ assertThatThrownBy(() -> cachingCatalog.dropTable(IDENTIFIER, false))
+ .hasStackTraceContaining("Failed to delete directory");
+ assertThat(new boolean[] {fileIO.exists(first), fileIO.exists(second)})
+ .containsExactlyInAnyOrder(true, false);
+ assertThatThrownBy(() -> cachingCatalog.getTable(IDENTIFIER))
+ .isInstanceOf(Catalog.TableNotExistException.class);
+ }
+
+ @Test
+ void testMissingExternalDirectoryDoesNotFailDrop() throws Exception {
+ FileIO fileIO = LocalFileIO.create();
+ Path external = new Path(tempDir.resolve("absent-external").toUri());
+ FileSystemCatalog catalog = createCatalog(fileIO, external);
+ catalog.dropTable(IDENTIFIER, false);
+
assertThat(fileIO.exists(catalog.getTableLocation(IDENTIFIER))).isFalse();
+ catalog.dropTable(IDENTIFIER, true);
+ }
+
+ @Test
+ void testAlreadyRemovedDirectoryDoesNotFailDrop() throws Exception {
+ LocalFileIO delegate = LocalFileIO.create();
+ FileIO fileIO = spy(delegate);
+ FileSystemCatalog catalog = createCatalog(fileIO, null);
+ Path tablePath = catalog.getTableLocation(IDENTIFIER);
+ doAnswer(
+ invocation -> {
+ delegate.delete(tablePath, true);
+ return false;
+ })
+ .when(fileIO)
+ .delete(tablePath, true);
+
+ catalog.dropTable(IDENTIFIER, false);
+ assertThat(fileIO.exists(tablePath)).isFalse();
+ }
+
+ @Test
+ void testRealReadOnlySchemaDirectory() throws Exception {
+
assumeTrue(Files.getFileStore(tempDir).supportsFileAttributeView("posix"));
+ FileIO fileIO = LocalFileIO.create();
+ FileSystemCatalog catalog = createCatalog(fileIO, null);
+ Path tablePath = catalog.getTableLocation(IDENTIFIER);
+ java.nio.file.Path schemaDirectory = Paths.get(new Path(tablePath,
"schema").toUri());
+ Set<PosixFilePermission> originalPermissions =
+ Files.getPosixFilePermissions(schemaDirectory);
+ try {
+ Files.setPosixFilePermissions(
+ schemaDirectory,
PosixFilePermissions.fromString("r-xr-xr-x"));
+ // Root can still remove these files. Keep portable failure tests
above for that case.
+ assumeFalse(Files.isWritable(schemaDirectory));
+ assertThat(catalog.getTable(IDENTIFIER)).isNotNull();
+ Throwable failure = catchThrowable(() ->
catalog.dropTable(IDENTIFIER, false));
+ assertThat(catalog.getTable(IDENTIFIER)).isNotNull();
+ assertThat(failure)
+ .isInstanceOf(RuntimeException.class)
+ .hasStackTraceContaining(tablePath.toString());
+ } finally {
+ Files.setPosixFilePermissions(schemaDirectory,
originalPermissions);
+ }
+ }
+
+ private FileSystemCatalog createCatalog(FileIO fileIO, Path external)
throws Exception {
+ FileSystemCatalog catalog =
+ new FileSystemCatalog(fileIO, new
Path(tempDir.resolve("warehouse").toUri()));
+ catalog.createDatabase(IDENTIFIER.getDatabaseName(), false);
+ Schema.Builder schema =
+ Schema.newBuilder().column("id",
DataTypes.INT()).option("bucket", "-1");
+ if (external != null) {
+ schema.option(CoreOptions.DATA_FILE_EXTERNAL_PATHS.key(),
external.toString());
+ }
+ catalog.createTable(IDENTIFIER, schema.build(), false);
+ return catalog;
+ }
+}