Skip to content

HADOOP-16637. Fix findbugs warnings in hadoop-cos. #1640

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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,32 +63,27 @@ 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);
if (dir.mkdirs()) {
if (!dir.setWritable(true) || !dir.setReadable(true)
|| !dir.setExecutable(true)) {
LOG.warn("Set the buffer dir: [{}]'s permission [writable,"
+ "readable, executable] failed.", dir.getAbsolutePath());
}
LOG.debug("Buffer dir: [{}] is created successfully.",
dir.getAbsolutePath());
} else {
// Once again, check if it has been created successfully.
// Prevent problems created by multiple processes at the same time.
if (!dir.exists()) {
throw new IOException("buffer dir:" + dir.getAbsolutePath()
+ " is created unsuccessfully");
}
if (!dir.exists()) {
LOG.debug("Buffer dir: [{}] does not exists. create it first.",
dirPath);
if (dir.mkdirs()) {
if (!dir.setWritable(true) || !dir.setReadable(true)
|| !dir.setExecutable(true)) {
LOG.warn("Set the buffer dir: [{}]'s permission [writable,"
+ "readable, executable] failed.", dir.getAbsolutePath());
}
LOG.debug("Buffer dir: [{}] is created successfully.",
dir.getAbsolutePath());
} else {
LOG.debug("buffer dir: {} already exists.", dirPath);
// Once again, check if it has been created successfully.
// Prevent problems created by multiple processes at the same time.
if (!dir.exists()) {
throw new IOException("buffer dir:" + dir.getAbsolutePath()
+ " is created unsuccessfully");
}
}
} else {
throw new IOException("creating buffer dir: " + dir.getAbsolutePath()
+ "unsuccessfully.");
LOG.debug("buffer dir: {} already exists.", dirPath);
}
Copy link
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?

Copy link
Member Author

@cxorm cxorm Jan 12, 2020

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 @@ -68,6 +69,8 @@
import org.apache.hadoop.util.VersionInfo;
import org.apache.http.HttpStatus;

import javax.annotation.Nullable;

/**
* The class actually performs access operation to the COS blob store.
* It provides the bridging logic for the Hadoop's abstract filesystem and COS.
Expand Down Expand Up @@ -175,7 +178,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 +200,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 @@ -247,10 +250,19 @@ public void storeEmptyFile(String key) throws IOException {
}
}

@Nullable
public PartETag uploadPart(File file, String key, String uploadId,
int partNum) throws IOException {
InputStream inputStream = new FileInputStream(file);
return uploadPart(inputStream, key, uploadId, partNum, file.length());
InputStream inputStream = null;
Copy link
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) {
return uploadPart(inputStream, key, uploadId, partNum, file.length());
}
}
return null;
}

@Override
Expand Down