Return-Path: Delivered-To: apmail-lucene-java-dev-archive@www.apache.org Received: (qmail 89483 invoked from network); 27 Nov 2009 16:38:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Nov 2009 16:38:26 -0000 Received: (qmail 78556 invoked by uid 500); 27 Nov 2009 16:38:25 -0000 Delivered-To: apmail-lucene-java-dev-archive@lucene.apache.org Received: (qmail 78432 invoked by uid 500); 27 Nov 2009 16:38:24 -0000 Mailing-List: contact java-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@lucene.apache.org Delivered-To: mailing list java-dev@lucene.apache.org Received: (qmail 78357 invoked by uid 99); 27 Nov 2009 16:38:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Nov 2009 16:38:24 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [209.85.217.216] (HELO mail-gx0-f216.google.com) (209.85.217.216) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Nov 2009 16:38:19 +0000 Received: by gxk8 with SMTP id 8so1377868gxk.11 for ; Fri, 27 Nov 2009 08:37:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.150.141.15 with SMTP id o15mr2076266ybd.86.1259339877269; Fri, 27 Nov 2009 08:37:57 -0800 (PST) Date: Fri, 27 Nov 2009 11:37:57 -0500 Message-ID: <9ac0c6aa0911270837s6ab343an9fb6386cea4dcd43@mail.gmail.com> Subject: deadlock in TestCrash From: Michael McCandless To: java-dev@lucene.apache.org Content-Type: text/plain; charset=ISO-8859-1 RAMFile has this method: final synchronized byte[] addBuffer(int size) { byte[] buffer = newBuffer(size); if (directory!=null) synchronized (directory) { // Ensure addition of buffer and adjustment to directory size are atomic wrt directory buffers.add(buffer); directory.sizeInBytes += size; sizeInBytes += size; } else buffers.add(buffer); return buffer; } But in working on LUCENE-2095, I'm seeing a deadlock, because that method first syncs on RAMFile and then tries to sync on directory, while the MockRAMDirectory.crash method, and I think maybe other places, do the reverse. I remember also hitting a different deadlock from this in the past, and working around it. I'd like to break the deadlock by changing RAMFile to this: final byte[] addBuffer(int size) { byte[] buffer = newBuffer(size); synchronized(this) { buffers.add(buffer); sizeInBytes += size; } if (directory != null) { synchronized (directory) { directory.sizeInBytes += size; } } return buffer; } But, then, the addition of the buffer and the change of sizeInBytes is no longer atomic wrt the directory (as the comment says). So my question is... is this change OK? Why is/was it so crucial that the sizeInBytes & RAMFile's buffers really change only atomically? Ie, it seems harmless if RAMDirectory.sizeInBytes() might not include a buffer that's in the process of being added...? (I do see TestRAMDirectory.testRAMDirectorySize requires this atomicity, but, I can fix the test to only check the size in the end...). Mike --------------------------------------------------------------------- To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org For additional commands, e-mail: java-dev-help@lucene.apache.org