Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Fix uncorrect index file #92

Merged
merged 2 commits into from Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,21 +30,19 @@ public class LocalFileWriter implements Closeable {

private DataOutputStream dataOutputStream;
private FileOutputStream fileOutputStream;
private long initSize;
private long nextOffset;

public LocalFileWriter(File file) throws IOException {
fileOutputStream = new FileOutputStream(file, true);
// init fsDataOutputStream
dataOutputStream = new DataOutputStream(fileOutputStream);
initSize = file.length();
nextOffset = initSize;
nextOffset = file.length();
}

public void writeData(byte[] data) throws IOException {
if (data != null && data.length > 0) {
dataOutputStream.write(data);
nextOffset = initSize + dataOutputStream.size();
nextOffset = nextOffset + data.length;
}
}

Expand Down
Expand Up @@ -39,6 +39,7 @@
import com.tencent.rss.storage.handler.api.ShuffleWriteHandler;
import com.tencent.rss.storage.util.ShuffleStorageUtils;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Random;
Expand All @@ -53,6 +54,7 @@ public class LocalFileHandlerTest {
@Test
public void writeTest() throws Exception {
File tmpDir = Files.createTempDir();
tmpDir.deleteOnExit();
File dataDir1 = new File(tmpDir, "data1");
File dataDir2 = new File(tmpDir, "data2");
String[] basePaths = new String[]{dataDir1.getAbsolutePath(),
Expand Down Expand Up @@ -111,6 +113,21 @@ public void writeTest() throws Exception {
}
}

@Test
public void writeBigDataTest() throws IOException {
File tmpDir = Files.createTempDir();
tmpDir.deleteOnExit();
File writeFile = new File(tmpDir, "writetest");
LocalFileWriter writer = new LocalFileWriter(writeFile);
int size = Integer.MAX_VALUE / 100;
byte[] data = new byte[size];
for (int i = 0; i < 200; i++) {
writer.writeData(data);
}
long totalSize = 200L * size;
assertEquals(writer.nextOffset(), totalSize);
}


private void writeTestData(
ShuffleWriteHandler writeHandler,
Expand Down