This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new e6b1730459 [#10168] Fail fast when file: URI source is missing in
JobManager.fetchFileFromUri (#10212)
e6b1730459 is described below
commit e6b17304592d1d9f4f74372696d153f786eec95f
Author: Ramesh Reddy Adutla
<[email protected]>
AuthorDate: Thu Mar 5 01:00:51 2026 +0000
[#10168] Fail fast when file: URI source is missing in
JobManager.fetchFileFromUri (#10212)
### What changes were proposed in this pull request?
Validate that the source path exists before creating a symlink in
`fetchFileFromUri`. Previously, a dangling symlink was silently created
when the source file did not exist, causing failures downstream instead
of at fetch time.
### Why are the changes needed?
`JobManager.fetchFileFromUri` currently reports success for `file:` URIs
by creating a symlink in the staging directory, even when the source
path does not exist. This creates a dangling symlink and returns a
seemingly valid staged path, causing failures later when the file is
consumed instead of failing at fetch time.
### Does this PR introduce _any_ user-facing change?
No. This is an internal defensive check — the external API is unchanged.
Jobs that previously failed late with a confusing error will now fail
early with a clear message.
### How was this patch tested?
Added unit test `testFetchFileFromUriWithMissingLocalFileShouldFail` (as
suggested in #10168) that:
1. Creates a staging directory
2. Constructs a `file:` URI pointing to a non-existent path
3. Asserts that `fetchFileFromUri` throws `RuntimeException`
Closes #10168
---------
Co-authored-by: Copilot <[email protected]>
---
.../src/main/java/org/apache/gravitino/job/JobManager.java | 7 ++++++-
.../test/java/org/apache/gravitino/job/TestJobManager.java | 14 ++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/gravitino/job/JobManager.java
b/core/src/main/java/org/apache/gravitino/job/JobManager.java
index dd68b6c161..17246645c7 100644
--- a/core/src/main/java/org/apache/gravitino/job/JobManager.java
+++ b/core/src/main/java/org/apache/gravitino/job/JobManager.java
@@ -809,7 +809,12 @@ public class JobManager implements JobOperationDispatcher {
break;
case "file":
- Files.createSymbolicLink(destFile.toPath(), new
File(fileUri.getPath()).toPath());
+ java.nio.file.Path sourcePath = new File(fileUri.getPath()).toPath();
+ if (!Files.exists(sourcePath)) {
+ throw new IOException(
+ String.format("Source file does not exist: %s",
sourcePath.toAbsolutePath()));
+ }
+ Files.createSymbolicLink(destFile.toPath(), sourcePath);
break;
default:
diff --git a/core/src/test/java/org/apache/gravitino/job/TestJobManager.java
b/core/src/test/java/org/apache/gravitino/job/TestJobManager.java
index 48f15f2b67..9bf06875ca 100644
--- a/core/src/test/java/org/apache/gravitino/job/TestJobManager.java
+++ b/core/src/test/java/org/apache/gravitino/job/TestJobManager.java
@@ -33,6 +33,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
@@ -899,4 +900,17 @@ public class TestJobManager {
AuditInfo.builder().withCreator("test").withCreateTime(Instant.now()).build())
.build();
}
+
+ @Test
+ public void testFetchFileFromUriWithMissingLocalFileShouldFail() throws
IOException {
+ File stagingDir = new File(testStagingDir);
+ Assertions.assertTrue(stagingDir.mkdirs() || stagingDir.exists());
+
+ Path missingFilePath =
+ Path.of(System.getProperty("java.io.tmpdir"), "missing-job-file-" +
UUID.randomUUID());
+ String uri = missingFilePath.toUri().toString();
+
+ Assertions.assertThrows(
+ RuntimeException.class, () -> JobManager.fetchFileFromUri(uri,
stagingDir, 1000));
+ }
}