Return-Path: X-Original-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3536E9A11 for ; Thu, 3 Nov 2011 01:00:47 +0000 (UTC) Received: (qmail 54538 invoked by uid 500); 3 Nov 2011 01:00:47 -0000 Delivered-To: apmail-hadoop-hdfs-commits-archive@hadoop.apache.org Received: (qmail 54499 invoked by uid 500); 3 Nov 2011 01:00:47 -0000 Mailing-List: contact hdfs-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hdfs-dev@hadoop.apache.org Delivered-To: mailing list hdfs-commits@hadoop.apache.org Received: (qmail 54490 invoked by uid 99); 3 Nov 2011 01:00:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2011 01:00:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2011 01:00:45 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BE10F2388CFF; Thu, 3 Nov 2011 01:00:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1196902 - in /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs: CHANGES.txt src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java Date: Thu, 03 Nov 2011 01:00:25 -0000 To: hdfs-commits@hadoop.apache.org From: todd@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111103010025.BE10F2388CFF@eris.apache.org> Author: todd Date: Thu Nov 3 01:00:25 2011 New Revision: 1196902 URL: http://svn.apache.org/viewvc?rev=1196902&view=rev Log: HDFS-2533. Remove needless synchronization on some FSDataSet methods. Contributed by Todd Lipcon. Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1196902&r1=1196901&r2=1196902&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Thu Nov 3 01:00:25 2011 @@ -877,6 +877,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-2347. Fix checkpointTxnCount's comment about editlog size. Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java?rev=1196902&r1=1196901&r2=1196902&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java Thu Nov 3 01:00:25 2011 @@ -1258,7 +1258,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) { @@ -1271,16 +1271,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); }