This is an automated email from the ASF dual-hosted git repository.
gian 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 548d0d0bb2 Add more information to exceptions occurred while writing
temporary data (#13217)
548d0d0bb2 is described below
commit 548d0d0bb2a54d151e8bb7283bb03f43e37e582e
Author: Abhishek Agarwal <[email protected]>
AuthorDate: Thu Oct 13 05:53:51 2022 +0530
Add more information to exceptions occurred while writing temporary data
(#13217)
* Add more information to exceptions when writing tmp data to disk
* Better error message
---
.../druid/segment/writeout/FileWriteOutBytes.java | 8 +++++++-
.../druid/segment/writeout/FileWriteOutBytesTest.java | 18 +++++++++++++++++-
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git
a/processing/src/main/java/org/apache/druid/segment/writeout/FileWriteOutBytes.java
b/processing/src/main/java/org/apache/druid/segment/writeout/FileWriteOutBytes.java
index 696e7954fd..e41a362fda 100644
---
a/processing/src/main/java/org/apache/druid/segment/writeout/FileWriteOutBytes.java
+++
b/processing/src/main/java/org/apache/druid/segment/writeout/FileWriteOutBytes.java
@@ -22,6 +22,7 @@ package org.apache.druid.segment.writeout;
import com.google.common.io.ByteStreams;
import org.apache.druid.io.Channels;
import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.java.util.common.IOE;
import java.io.File;
import java.io.FileInputStream;
@@ -59,7 +60,12 @@ final class FileWriteOutBytes extends WriteOutBytes
public void flush() throws IOException
{
buffer.flip();
- Channels.writeFully(ch, buffer);
+ try {
+ Channels.writeFully(ch, buffer);
+ }
+ catch (IOException e) {
+ throw new IOE(e, "Failed to write to file: %s. Current size of file:
%d", file.getAbsolutePath(), writeOutBytes);
+ }
buffer.clear();
}
diff --git
a/processing/src/test/java/org/apache/druid/segment/writeout/FileWriteOutBytesTest.java
b/processing/src/test/java/org/apache/druid/segment/writeout/FileWriteOutBytesTest.java
index 8be3a4b21c..da6b3c481a 100644
---
a/processing/src/test/java/org/apache/druid/segment/writeout/FileWriteOutBytesTest.java
+++
b/processing/src/test/java/org/apache/druid/segment/writeout/FileWriteOutBytesTest.java
@@ -34,12 +34,14 @@ public class FileWriteOutBytesTest
{
private FileWriteOutBytes fileWriteOutBytes;
private FileChannel mockFileChannel;
+ private File mockFile;
@Before
public void setUp()
{
mockFileChannel = EasyMock.mock(FileChannel.class);
- fileWriteOutBytes = new FileWriteOutBytes(EasyMock.mock(File.class),
mockFileChannel);
+ mockFile = EasyMock.mock(File.class);
+ fileWriteOutBytes = new FileWriteOutBytes(mockFile, mockFileChannel);
}
@Test
@@ -192,4 +194,18 @@ public class FileWriteOutBytesTest
Assert.assertThrows(IAE.class, () -> fileWriteOutBytes.readFully(5000,
destination));
EasyMock.verify(mockFileChannel);
}
+
+ @Test
+ public void testIOExceptionHasFileInfo() throws Exception
+ {
+ IOException cause = new IOException("Too many bytes");
+
EasyMock.expect(mockFileChannel.write(EasyMock.anyObject(ByteBuffer.class))).andThrow(cause);
+ EasyMock.expect(mockFile.getAbsolutePath()).andReturn("/tmp/file");
+ EasyMock.replay(mockFileChannel, mockFile);
+ fileWriteOutBytes.writeInt(10);
+ fileWriteOutBytes.write(new byte[30]);
+ IOException actual = Assert.assertThrows(IOException.class, () ->
fileWriteOutBytes.flush());
+ Assert.assertEquals(String.valueOf(actual.getCause()), actual.getCause(),
cause);
+ Assert.assertEquals(actual.getMessage(), actual.getMessage(), "Failed to
write to file: /tmp/file. Current size of file: 34");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]