HDFS-2533. Remove needless synchronization on some FSDataSet methods. Contributed by Todd Lipcon.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1196901 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
854c1e8794
commit
de2b8a0a61
|
@ -791,6 +791,9 @@ Release 0.23.0 - 2011-11-01
|
||||||
|
|
||||||
HDFS-2130. Switch default checksum to CRC32C. (todd)
|
HDFS-2130. Switch default checksum to CRC32C. (todd)
|
||||||
|
|
||||||
|
HDFS-2533. Remove needless synchronization on some FSDataSet methods.
|
||||||
|
(todd)
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
HDFS-2344. Fix the TestOfflineEditsViewer test failure in 0.23 branch.
|
HDFS-2344. Fix the TestOfflineEditsViewer test failure in 0.23 branch.
|
||||||
|
|
|
@ -1259,7 +1259,7 @@ public class FSDataset implements FSDatasetInterface {
|
||||||
/**
|
/**
|
||||||
* Get File name for a given block.
|
* Get File name for a given block.
|
||||||
*/
|
*/
|
||||||
public synchronized File getBlockFile(String bpid, Block b)
|
public File getBlockFile(String bpid, Block b)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
File f = validateBlockFile(bpid, b);
|
File f = validateBlockFile(bpid, b);
|
||||||
if(f == null) {
|
if(f == null) {
|
||||||
|
@ -1272,16 +1272,44 @@ public class FSDataset implements FSDatasetInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // FSDatasetInterface
|
@Override // FSDatasetInterface
|
||||||
public synchronized InputStream getBlockInputStream(ExtendedBlock b)
|
public InputStream getBlockInputStream(ExtendedBlock b)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return new FileInputStream(getBlockFile(b));
|
File f = getBlockFileNoExistsCheck(b);
|
||||||
|
try {
|
||||||
|
return new FileInputStream(f);
|
||||||
|
} catch (FileNotFoundException fnfe) {
|
||||||
|
throw new IOException("Block " + b + " is not valid. " +
|
||||||
|
"Expected block file at " + f + " does not exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the File associated with a block, without first
|
||||||
|
* checking that it exists. This should be used when the
|
||||||
|
* next operation is going to open the file for read anyway,
|
||||||
|
* and thus the exists check is redundant.
|
||||||
|
*/
|
||||||
|
private File getBlockFileNoExistsCheck(ExtendedBlock b)
|
||||||
|
throws IOException {
|
||||||
|
File f = getFile(b.getBlockPoolId(), b.getLocalBlock());
|
||||||
|
if (f == null) {
|
||||||
|
throw new IOException("Block " + b + " is not valid");
|
||||||
|
}
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // FSDatasetInterface
|
@Override // FSDatasetInterface
|
||||||
public synchronized InputStream getBlockInputStream(ExtendedBlock b,
|
public InputStream getBlockInputStream(ExtendedBlock b,
|
||||||
long seekOffset) throws IOException {
|
long seekOffset) throws IOException {
|
||||||
File blockFile = getBlockFile(b);
|
File blockFile = getBlockFileNoExistsCheck(b);
|
||||||
RandomAccessFile blockInFile = new RandomAccessFile(blockFile, "r");
|
RandomAccessFile blockInFile;
|
||||||
|
try {
|
||||||
|
blockInFile = new RandomAccessFile(blockFile, "r");
|
||||||
|
} catch (FileNotFoundException fnfe) {
|
||||||
|
throw new IOException("Block " + b + " is not valid. " +
|
||||||
|
"Expected block file at " + blockFile + " does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
if (seekOffset > 0) {
|
if (seekOffset > 0) {
|
||||||
blockInFile.seek(seekOffset);
|
blockInFile.seek(seekOffset);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue