From 920c6640387a30fdbcd1460bbed5aad388e5842e Mon Sep 17 00:00:00 2001 From: voddle Date: Thu, 9 Nov 2023 23:58:58 +0800 Subject: [PATCH] Change file exist exception to runtime exception in PagedDoraWorker ### What changes are proposed in this pull request? The `RuntimeException(FileAlreadyExistException)` changed to `AlreadyExistException()` in `PagedDoraWorker` ### Why are the changes needed? `RuntimeException(FileAlreadyExistException)` seems won't be caught in `DoraWorkerClientServiceHandler` when convertin it to `AlluxioRuntimeException`, which willl cause the loss status code ### Does this PR introduce any user facing changes? no pr-link: Alluxio/alluxio#18337 change-id: cid-9a520c49579847bae6da21302f484ba713eeb4d9 --- .../java/alluxio/worker/dora/PagedDoraWorker.java | 13 ++++++------- .../fs/command/DoraMkdirCommandIntegrationTest.java | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dora/core/server/worker/src/main/java/alluxio/worker/dora/PagedDoraWorker.java b/dora/core/server/worker/src/main/java/alluxio/worker/dora/PagedDoraWorker.java index 8aaea5fc77fe..7fba2c64a632 100644 --- a/dora/core/server/worker/src/main/java/alluxio/worker/dora/PagedDoraWorker.java +++ b/dora/core/server/worker/src/main/java/alluxio/worker/dora/PagedDoraWorker.java @@ -32,10 +32,10 @@ import alluxio.conf.Configuration; import alluxio.conf.PropertyKey; import alluxio.exception.AccessControlException; -import alluxio.exception.FileAlreadyExistsException; import alluxio.exception.runtime.AlluxioRuntimeException; import alluxio.exception.runtime.FailedPreconditionRuntimeException; import alluxio.exception.runtime.UnavailableRuntimeException; +import alluxio.exception.status.AlreadyExistsException; import alluxio.exception.status.FailedPreconditionException; import alluxio.grpc.Command; import alluxio.grpc.CommandType; @@ -879,9 +879,8 @@ public OpenFileHandle createFile(String path, CreateFilePOptions options) boolean overWrite = options.hasOverwrite() ? options.getOverwrite() : false; boolean exists = ufs.exists(path); if (!overWrite && exists) { - throw new RuntimeException( - new FileAlreadyExistsException( - String.format("File %s already exists but no overwrite flag", path))); + throw new AlreadyExistsException(String.format("File %s already exists" + + "but no overwrite flag", path)); } else if (overWrite) { // client is going to overwrite this file. We need to invalidate the cached meta and data. mMetaManager.removeFromMetaStore(path); @@ -1010,11 +1009,11 @@ public void createDirectory(String path, CreateDirectoryPOptions options) mMetaManager.loadFromUfs(path); mMetaManager.invalidateListingCacheOfParent(path); if (!success) { - throw new RuntimeException( - new FileAlreadyExistsException(String.format("%s already exists", path))); + throw new AlreadyExistsException(String.format("%s already exists", path)); } } catch (IOException e) { - throw new RuntimeException(e); + // IOE would be caught by AlluxioRuntimeException + throw e; } } diff --git a/dora/tests/integration/src/test/java/alluxio/client/cli/fs/command/DoraMkdirCommandIntegrationTest.java b/dora/tests/integration/src/test/java/alluxio/client/cli/fs/command/DoraMkdirCommandIntegrationTest.java index 9985036db2a2..9f0e65d298f6 100644 --- a/dora/tests/integration/src/test/java/alluxio/client/cli/fs/command/DoraMkdirCommandIntegrationTest.java +++ b/dora/tests/integration/src/test/java/alluxio/client/cli/fs/command/DoraMkdirCommandIntegrationTest.java @@ -51,7 +51,7 @@ public void testMkdirExisting() { assertEquals(0, mFsShell.run("mkdir", uri.toString())); assertEquals(-1, mFsShell.run("mkdir", uri.toString())); assertTrue( - mOutput.toString().contains("UNKNOWN: alluxio.exception.FileAlreadyExistsException")); + mOutput.toString().contains("ALREADY_EXISTS")); } @Test @@ -76,7 +76,7 @@ public void testMkdirPathWithWhiteSpaces() throws Exception { public void testMkdirInvalidPath() { assertEquals(-1, mFsShell.run("mkdir", "")); assertTrue( - mOutput.toString().contains("UNKNOWN: alluxio.exception.FileAlreadyExistsException")); + mOutput.toString().contains("ALREADY_EXISTS")); } @Test