yuqi1129 opened a new pull request, #11940:
URL: https://github.com/apache/gravitino/pull/11940

   ### What changes were proposed in this pull request?
   
   Add `DirectoryUtils.ensureDirectory(File)` in `common` (backed by 
`Files.createDirectories`, which is atomic and idempotent) and replace the racy 
`!dir.exists() && !dir.mkdirs()` / bare `!dir.mkdirs()` patterns with it in:
   
   - `KerberosAuthUtils.fetchKeytabFromUri` (`catalogs/hadoop-auth`)
   - `JobManager` constructor and `JobManager.runJob` (`core`), keeping the 
original exception types at both call sites
   
   ### Why are the changes needed?
   
   `File.mkdirs()` returns `false` when the directory already exists, so two 
threads racing to create the same directory (TOCTOU between `exists()` and 
`mkdirs()`) make the loser fail spuriously even though the directory was 
created. For `KerberosAuthUtils` this surfaces as `IOException("Failed to 
create keytab directory .../keytabs")` → HTTP 500 when concurrent 
Kerberos-enabled Hive clients initialize, seen as flaky 
`HudiCatalogKerberosHiveIT.testHudiCatalogWithKerberos`. `JobManager.runJob` 
additionally fails misleadingly whenever the job staging directory already 
exists.
   
   Fix: #11939
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   New unit tests, each written first and verified to fail before the fix:
   
   - 
`TestKerberosAuthUtils.testConcurrentFetchKeytabCreatesParentDirectoryOnce`: 4 
threads × 200 iterations racing `fetchKeytabFromUri` on a fresh parent 
directory via `CyclicBarrier`. Reproduces the exact CI failure on the first 
iteration before the fix; passes after.
   - `TestJobManager.testRunJobSucceedsWhenStagingDirectoryAlreadyExists`: with 
a fixed job ID, running the same job twice hits an existing staging directory; 
threw `RuntimeException("Failed to create staging directory ...")` before the 
fix.
   - `TestDirectoryUtils` (4 tests): nested creation, idempotency, rejecting a 
regular file at the path, and barrier-synchronized concurrent creation.
   
   `./gradlew :common:test :catalogs:hadoop-auth:test -PskipITs` and 
`TestJobManager` all pass.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to