Return-Path: Delivered-To: apmail-lucene-hadoop-commits-archive@locus.apache.org Received: (qmail 44935 invoked from network); 18 Apr 2006 19:18:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 Apr 2006 19:18:11 -0000 Received: (qmail 3445 invoked by uid 500); 18 Apr 2006 19:18:11 -0000 Delivered-To: apmail-lucene-hadoop-commits-archive@lucene.apache.org Received: (qmail 3428 invoked by uid 500); 18 Apr 2006 19:18:11 -0000 Mailing-List: contact hadoop-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hadoop-dev@lucene.apache.org Delivered-To: mailing list hadoop-commits@lucene.apache.org Received: (qmail 3419 invoked by uid 99); 18 Apr 2006 19:18:11 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Apr 2006 12:18:11 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 18 Apr 2006 12:18:10 -0700 Received: (qmail 44614 invoked by uid 65534); 18 Apr 2006 19:17:50 -0000 Message-ID: <20060418191750.44613.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r395003 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/LocalFileSystem.java Date: Tue, 18 Apr 2006 19:17:49 -0000 To: hadoop-commits@lucene.apache.org From: cutting@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: cutting Date: Tue Apr 18 12:17:47 2006 New Revision: 395003 URL: http://svn.apache.org/viewcvs?rev=395003&view=rev Log: Fix for HADOOP-139. Fix a potential deadlock in LocalFileSystem.lock(). Contributed by Igor Bolotin. Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/CHANGES.txt?rev=395003&r1=395002&r2=395003&view=diff ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Tue Apr 18 12:17:47 2006 @@ -46,6 +46,9 @@ 12. Fix HADOOP-138. Stop multiple tasks in a single heartbeat, rather than one per heartbeat. (Stefan via cutting) +13. Fix HADOOP-139. Remove a potential deadlock in + LocalFileSystem.lock(). (Igor Bolotin via cutting) + Release 0.1.1 - 2006-04-08 Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java?rev=395003&r1=395002&r2=395003&view=diff ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/LocalFileSystem.java Tue Apr 18 12:17:47 2006 @@ -224,45 +224,54 @@ return workingDir; } - public synchronized void lock(Path p, boolean shared) throws IOException { - File f = pathToFile(p); - f.createNewFile(); + public void lock(Path p, boolean shared) throws IOException { + File f = pathToFile(p); + f.createNewFile(); - FileLock lockObj = null; - if (shared) { - FileInputStream lockData = new FileInputStream(f); - lockObj = lockData.getChannel().lock(0L, Long.MAX_VALUE, shared); - sharedLockDataSet.put(f, lockData); - } else { - FileOutputStream lockData = new FileOutputStream(f); - lockObj = lockData.getChannel().lock(0L, Long.MAX_VALUE, shared); - nonsharedLockDataSet.put(f, lockData); + if (shared) { + FileInputStream lockData = new FileInputStream(f); + FileLock lockObj = + lockData.getChannel().lock(0L, Long.MAX_VALUE, shared); + synchronized (this) { + sharedLockDataSet.put(f, lockData); + lockObjSet.put(f, lockObj); } - lockObjSet.put(f, lockObj); + } else { + FileOutputStream lockData = new FileOutputStream(f); + FileLock lockObj = lockData.getChannel().lock(0L, Long.MAX_VALUE, shared); + synchronized (this) { + nonsharedLockDataSet.put(f, lockData); + lockObjSet.put(f, lockObj); + } + } } - public synchronized void release(Path p) throws IOException { - File f = pathToFile(p); - FileLock lockObj = (FileLock) lockObjSet.get(f); - FileInputStream sharedLockData = (FileInputStream) sharedLockDataSet.get(f); - FileOutputStream nonsharedLockData = (FileOutputStream) nonsharedLockDataSet.get(f); + public void release(Path p) throws IOException { + File f = pathToFile(p); - if (lockObj == null) { - throw new IOException("Given target not held as lock"); - } - if (sharedLockData == null && nonsharedLockData == null) { - throw new IOException("Given target not held as lock"); - } + FileLock lockObj; + FileInputStream sharedLockData; + FileOutputStream nonsharedLockData; + synchronized (this) { + lockObj = (FileLock) lockObjSet.remove(f); + sharedLockData = (FileInputStream) sharedLockDataSet.remove(f); + nonsharedLockData = (FileOutputStream) nonsharedLockDataSet.remove(f); + } + + if (lockObj == null) { + throw new IOException("Given target not held as lock"); + } + if (sharedLockData == null && nonsharedLockData == null) { + throw new IOException("Given target not held as lock"); + } - lockObj.release(); - lockObjSet.remove(f); - if (sharedLockData != null) { - sharedLockData.close(); - sharedLockDataSet.remove(f); - } else { - nonsharedLockData.close(); - nonsharedLockDataSet.remove(f); - } + lockObj.release(); + + if (sharedLockData != null) { + sharedLockData.close(); + } else { + nonsharedLockData.close(); + } } // In the case of the local filesystem, we can just rename the file.