Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private BufferPool() {

private File createDir(String dirPath) throws IOException {
File dir = new File(dirPath);
if (null != dir) {
if (!dir.exists()) {
LOG.debug("Buffer dir: [{}] does not exists. create it first.",
dirPath);
Expand All @@ -86,10 +85,6 @@ private File createDir(String dirPath) throws IOException {
} else {
LOG.debug("buffer dir: {} already exists.", dirPath);
}
} else {
throw new IOException("creating buffer dir: " + dir.getAbsolutePath()
+ "unsuccessfully.");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you fix indent?

@cxorm cxorm Jan 12, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aajisaka for the review.
Yes I would fix it, and run the test on this issue.


return dir;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.apache.hadoop.fs.FSInputStream;
import org.apache.hadoop.fs.FileSystem;

import javax.annotation.Nullable;

/**
* The input stream for the COS blob store.
* Optimized sequential read flow based on a forward read-ahead queue
Expand Down Expand Up @@ -83,8 +85,15 @@ public void signalAll() {
readyCondition.signalAll();
}

@Nullable
public byte[] getBuffer() {
return this.buffer;
if (this.buffer.length == 0) return null;

byte[] tempBuffer = new byte[this.buffer.length];
for (int index = 0; index < this.buffer.length; index++) {
tempBuffer[index] = this.buffer[index];
}
return tempBuffer;
}

public int getStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -175,7 +176,7 @@ private void storeFileWithRetry(String key, InputStream inputStream,
PutObjectResult putObjectResult =
(PutObjectResult) callCOSClientWithRetry(putObjectRequest);
LOG.debug("Store file successfully. COS key: [{}], ETag: [{}], "
+ "MD5: [{}].", key, putObjectResult.getETag(), new String(md5Hash));
+ "MD5: [{}].", key, putObjectResult.getETag(), Charset.defaultCharset());
} catch (Exception e) {
String errMsg = String.format("Store file failed. COS key: [%s], "
+ "exception: [%s]", key, e.toString());
Expand All @@ -197,7 +198,7 @@ public void storeFile(String key, File file, byte[] md5Hash)
throws IOException {
LOG.info("Store file from local path: [{}]. file length: [{}] COS key: " +
"[{}] MD5: [{}].", file.getCanonicalPath(), file.length(), key,
new String(md5Hash));
Charset.defaultCharset());
storeFileWithRetry(key, new BufferedInputStream(new FileInputStream(file)),
md5Hash, file.length());
}
Expand Down Expand Up @@ -249,7 +250,15 @@ public void storeEmptyFile(String key) throws IOException {

public PartETag uploadPart(File file, String key, String uploadId,
int partNum) throws IOException {
InputStream inputStream = new FileInputStream(file);
InputStream inputStream = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks broken, as L262 will always get a closed stream

try {
inputStream = new FileInputStream(file);
}
finally {
if (inputStream != null) {
inputStream.close();
}
}
return uploadPart(inputStream, key, uploadId, partNum, file.length());
}

Expand Down