Author: todd
Date: Thu Nov 3 01:00:17 2011
New Revision: 1196901
URL: http://svn.apache.org/viewvc?rev=1196901&view=rev
Log:
HDFS-2533. Remove needless synchronization on some FSDataSet methods.
Contributed by Todd Lipcon.
Modified:
hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java
Modified:
hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1196901&r1=1196900&r2=1196901&view=diff
==============================================================================
---
hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
(original)
+++
hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
Thu Nov 3 01:00:17 2011
@@ -791,6 +791,9 @@ Release 0.23.0 - 2011-11-01
HDFS-2130. Switch default checksum to CRC32C. (todd)
+ HDFS-2533. Remove needless synchronization on some FSDataSet methods.
+ (todd)
+
BUG FIXES
HDFS-2344. Fix the TestOfflineEditsViewer test failure in 0.23 branch.
Modified:
hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java?rev=1196901&r1=1196900&r2=1196901&view=diff
==============================================================================
---
hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java
(original)
+++
hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java
Thu Nov 3 01:00:17 2011
@@ -1259,7 +1259,7 @@ public class FSDataset implements FSData
/**
* Get File name for a given block.
*/
- public synchronized File getBlockFile(String bpid, Block b)
+ public File getBlockFile(String bpid, Block b)
throws IOException {
File f = validateBlockFile(bpid, b);
if(f == null) {
@@ -1272,16 +1272,44 @@ public class FSDataset implements FSData
}
@Override // FSDatasetInterface
- public synchronized InputStream getBlockInputStream(ExtendedBlock b)
+ public InputStream getBlockInputStream(ExtendedBlock b)
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
- public synchronized InputStream getBlockInputStream(ExtendedBlock b,
+ public InputStream getBlockInputStream(ExtendedBlock b,
long seekOffset) throws IOException {
- File blockFile = getBlockFile(b);
- RandomAccessFile blockInFile = new RandomAccessFile(blockFile, "r");
+ File blockFile = getBlockFileNoExistsCheck(b);
+ 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) {
blockInFile.seek(seekOffset);
}