This is an automated email from the ASF dual-hosted git repository.

FrankChen021 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 4ad1ddd2724 fix: `writeAtomically` fails for file names longer than 
217 bytes (#20493)
4ad1ddd2724 is described below

commit 4ad1ddd2724048f977bf5049437e25c0435175d0
Author: Rsh <[email protected]>
AuthorDate: Thu Oct 8 14:58:27 2026 +0200

    fix: `writeAtomically` fails for file names longer than 217 bytes (#20493)
    
    FileUtils.writeAtomically named its temporary file ".<fileName>.<uuid>",
    adding 38 characters to the target name. File names between 218 and 255
    bytes were valid, but their temporary names were not, so the write failed
    with "File name too long". WorkerTaskManager persists tasks this way using
    the task ID as the file name, so tasks with such IDs, such as kill tasks
    on datasources with long names, could never start.
    
    Name the temporary file ".<uuid>" instead. The UUID keeps it unique, and
    the target file keeps its full name after the move.
    
    Fixes #20492.
    
    Co-authored-by: Riccardo Sale <[email protected]>
---
 .../org/apache/druid/indexing/worker/WorkerTaskManagerTest.java   | 8 ++++++++
 .../main/java/org/apache/druid/java/util/common/FileUtils.java    | 2 +-
 .../java/org/apache/druid/java/util/common/FileUtilsTest.java     | 8 ++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git 
a/indexing-service/src/test/java/org/apache/druid/indexing/worker/WorkerTaskManagerTest.java
 
b/indexing-service/src/test/java/org/apache/druid/indexing/worker/WorkerTaskManagerTest.java
index 2eee7804561..75e5a677fc2 100644
--- 
a/indexing-service/src/test/java/org/apache/druid/indexing/worker/WorkerTaskManagerTest.java
+++ 
b/indexing-service/src/test/java/org/apache/druid/indexing/worker/WorkerTaskManagerTest.java
@@ -47,6 +47,7 @@ import 
org.apache.druid.indexing.common.task.TestAppenderatorsManager;
 import org.apache.druid.indexing.overlord.TestTaskRunner;
 import org.apache.druid.indexing.worker.config.WorkerConfig;
 import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.StringUtils;
 import 
org.apache.druid.java.util.http.client.response.StringFullResponseHolder;
 import org.apache.druid.query.policy.NoopPolicyEnforcer;
 import org.apache.druid.rpc.HttpResponseException;
@@ -309,6 +310,13 @@ public class WorkerTaskManagerTest
     
Assertions.assertNotNull(update4.getTaskAnnouncement().getTaskLocation().getHost());
   }
 
+  @Test
+  public void testAssignTaskWithMaxLengthTaskId() throws Exception
+  {
+    workerTaskManager.start();
+    Assertions.assertDoesNotThrow(() -> 
workerTaskManager.assignTask(createNoopTask(StringUtils.repeat("x", 255))));
+  }
+
   @Test
   @Timeout(value = 30_000L, unit = TimeUnit.MILLISECONDS)
   public void testTaskStatusWhenTaskRunnerFutureThrowsException() throws 
Exception
diff --git 
a/processing/src/main/java/org/apache/druid/java/util/common/FileUtils.java 
b/processing/src/main/java/org/apache/druid/java/util/common/FileUtils.java
index fee9217db61..df1c292b175 100644
--- a/processing/src/main/java/org/apache/druid/java/util/common/FileUtils.java
+++ b/processing/src/main/java/org/apache/druid/java/util/common/FileUtils.java
@@ -262,7 +262,7 @@ public class FileUtils
    */
   public static <T> T writeAtomically(final File file, final File tmpDir, 
OutputStreamConsumer<T> f) throws IOException
   {
-    final File tmpFile = new File(tmpDir, StringUtils.format(".%s.%s", 
file.getName(), UUID.randomUUID()));
+    final File tmpFile = new File(tmpDir, "." + UUID.randomUUID());
 
     //noinspection unused
     try (final Closeable ignoredDeleter = () -> 
Files.deleteIfExists(tmpFile.toPath())) {
diff --git 
a/processing/src/test/java/org/apache/druid/java/util/common/FileUtilsTest.java 
b/processing/src/test/java/org/apache/druid/java/util/common/FileUtilsTest.java
index ca23f891d33..ef318d74158 100644
--- 
a/processing/src/test/java/org/apache/druid/java/util/common/FileUtilsTest.java
+++ 
b/processing/src/test/java/org/apache/druid/java/util/common/FileUtilsTest.java
@@ -174,6 +174,14 @@ public class FileUtilsTest
     Assertions.assertEquals("baz", 
StringUtils.fromUtf8(Files.readAllBytes(tmpFile.toPath())));
   }
 
+  @Test
+  public void testWriteAtomicallyMaxLengthFileName() throws IOException
+  {
+    final File file = new File(temporaryFolder.getRoot(), 
StringUtils.repeat("a", 255));
+    FileUtils.writeAtomically(file, out -> true);
+    Assertions.assertTrue(file.exists());
+  }
+
   @Test
   public void testResolveFileWithinDirectory()
   {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to