This is an automated email from the ASF dual-hosted git repository.
maobaolong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push:
new 995de6d00 [MINOR] improvement(server): LocalFileNioWriter support
writeIndex api (#2320)
995de6d00 is described below
commit 995de6d000e5ef45f6e9da19da9a908e6e2f9090
Author: maobaolong <[email protected]>
AuthorDate: Mon Jan 6 18:30:12 2025 +0800
[MINOR] improvement(server): LocalFileNioWriter support writeIndex api
(#2320)
### What changes were proposed in this pull request?
Support WriteIndex api for LocalFileNioWriter.
### Why are the changes needed?
- Finish the suggestion left in
https://github.com/apache/incubator-uniffle/pull/2223#discussion_r1818333247
- Introduce the `LocalFileNullDeviceWriter` in the follow up PR.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
No need.
---
.../uniffle/storage/handler/impl/LocalFileNioWriter.java | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git
a/storage/src/main/java/org/apache/uniffle/storage/handler/impl/LocalFileNioWriter.java
b/storage/src/main/java/org/apache/uniffle/storage/handler/impl/LocalFileNioWriter.java
index e3ef08ea4..57a9227c6 100644
---
a/storage/src/main/java/org/apache/uniffle/storage/handler/impl/LocalFileNioWriter.java
+++
b/storage/src/main/java/org/apache/uniffle/storage/handler/impl/LocalFileNioWriter.java
@@ -17,6 +17,8 @@
package org.apache.uniffle.storage.handler.impl;
+import java.io.BufferedOutputStream;
+import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -30,6 +32,7 @@ import
org.apache.uniffle.storage.common.FileBasedShuffleSegment;
public class LocalFileNioWriter implements FileWriter {
+ private DataOutputStream dataOutputStream;
private FileOutputStream fileOutputStream;
private long nextOffset;
@@ -40,6 +43,8 @@ public class LocalFileNioWriter implements FileWriter {
public LocalFileNioWriter(File file, int bufferSize) throws IOException {
fileOutputStream = new FileOutputStream(file, true);
+ // init fsDataOutputStream
+ dataOutputStream = new DataOutputStream(new
BufferedOutputStream(fileOutputStream, bufferSize));
nextOffset = file.length();
}
@@ -61,7 +66,12 @@ public class LocalFileNioWriter implements FileWriter {
@Override
public void writeIndex(FileBasedShuffleSegment segment) throws IOException {
- throw new UnsupportedOperationException("LocalFileNioWriter does not
support index");
+ dataOutputStream.writeLong(segment.getOffset());
+ dataOutputStream.writeInt(segment.getLength());
+ dataOutputStream.writeInt(segment.getUncompressLength());
+ dataOutputStream.writeLong(segment.getCrc());
+ dataOutputStream.writeLong(segment.getBlockId());
+ dataOutputStream.writeLong(segment.getTaskAttemptId());
}
@Override
@@ -71,8 +81,8 @@ public class LocalFileNioWriter implements FileWriter {
@Override
public synchronized void close() throws IOException {
- if (fileOutputStream != null) {
- fileOutputStream.close();
+ if (dataOutputStream != null) {
+ dataOutputStream.close();
}
}
}