Return-Path: Delivered-To: apmail-lucene-dev-archive@www.apache.org Received: (qmail 46114 invoked from network); 29 Nov 2010 21:05:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 29 Nov 2010 21:05:15 -0000 Received: (qmail 69539 invoked by uid 500); 29 Nov 2010 21:05:11 -0000 Delivered-To: apmail-lucene-dev-archive@lucene.apache.org Received: (qmail 69449 invoked by uid 500); 29 Nov 2010 21:05:11 -0000 Mailing-List: contact dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list dev@lucene.apache.org Received: (qmail 69442 invoked by uid 99); 29 Nov 2010 21:05:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Nov 2010 21:05:11 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [85.25.71.29] (HELO mail.troja.net) (85.25.71.29) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Nov 2010 21:05:03 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.troja.net (Postfix) with ESMTP id 3D97B45F7E8 for ; Mon, 29 Nov 2010 22:04:43 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.troja.net Received: from mail.troja.net ([127.0.0.1]) by localhost (megaira.troja.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6OrgWRI82e66 for ; Mon, 29 Nov 2010 22:04:38 +0100 (CET) Received: from VEGA (port-83-236-62-54.dynamic.qsc.de [83.236.62.54]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail.troja.net (Postfix) with ESMTPSA id 8F4F845F705 for ; Mon, 29 Nov 2010 22:04:37 +0100 (CET) From: "Uwe Schindler" To: References: <20101129151844.4358B238890D@eris.apache.org> In-Reply-To: <20101129151844.4358B238890D@eris.apache.org> Subject: RE: svn commit: r1040145 - /lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMDirectory.java Date: Mon, 29 Nov 2010 22:05:09 +0100 Message-ID: <007801cb9009$1b6d6290$524827b0$@thetaphi.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQHIzzXJYxNidpJRTtv0H2m5DiF3XZOOc4/g Content-Language: de X-Virus-Checked: Checked by ClamAV on apache.org This commit broke backwards in MockRAMDir. A fix would be to change = MockRAMDir in backwards to use reflection to get the Map (like used at = another place in MockRAMDir already). Uwe ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: uwe@thetaphi.de > -----Original Message----- > From: shaie@apache.org [mailto:shaie@apache.org] > Sent: Monday, November 29, 2010 4:19 PM > To: commits@lucene.apache.org > Subject: svn commit: r1040145 - > /lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store > /RAMDirectory.java >=20 > Author: shaie > Date: Mon Nov 29 15:18:42 2010 > New Revision: 1040145 >=20 > URL: http://svn.apache.org/viewvc?rev=3D1040145&view=3Drev > Log: > LUCENE-2779: Use ConcurrentHashMap in RAMDirectory (3x) >=20 > Modified: >=20 > lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/ > RAMDirectory.java >=20 > Modified: > lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/ > RAMDirectory.java > URL: > http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/ > = java/org/apache/lucene/store/RAMDirectory.java?rev=3D1040145&r1=3D1040144= > &r2=3D1040145&view=3Ddiff > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- > lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/ > RAMDirectory.java (original) > +++ > lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/ > RAMDirectory.java Mon Nov 29 15:18:42 2010 > @@ -20,8 +20,8 @@ package org.apache.lucene.store; > import java.io.IOException; > import java.io.FileNotFoundException; > import java.io.Serializable; > -import java.util.HashMap; > -import java.util.Set; > +import java.util.Map; > +import java.util.concurrent.ConcurrentHashMap; > import java.util.concurrent.atomic.AtomicLong; >=20 > import org.apache.lucene.index.IndexFileNameFilter; > @@ -36,7 +36,7 @@ public class RAMDirectory extends Direct >=20 > private static final long serialVersionUID =3D 1l; >=20 > - protected HashMap fileMap =3D new > HashMap(); > + protected Map fileMap =3D new > ConcurrentHashMap(); > protected final AtomicLong sizeInBytes =3D new AtomicLong(); >=20 > // ***** > @@ -83,25 +83,16 @@ public class RAMDirectory extends Direct > } >=20 > @Override > - public synchronized final String[] listAll() { > + public final String[] listAll() { > ensureOpen(); > - Set fileNames =3D fileMap.keySet(); > - String[] result =3D new String[fileNames.size()]; > - int i =3D 0; > - for(final String fileName: fileNames) > - result[i++] =3D fileName; > - return result; > + return fileMap.keySet().toArray(new String[0]); > } >=20 > /** Returns true iff the named file exists in this directory. */ > @Override > public final boolean fileExists(String name) { > ensureOpen(); > - RAMFile file; > - synchronized (this) { > - file =3D fileMap.get(name); > - } > - return file !=3D null; > + return fileMap.containsKey(name); > } >=20 > /** Returns the time the named file was last modified. > @@ -110,12 +101,10 @@ public class RAMDirectory extends Direct > @Override > public final long fileModified(String name) throws IOException { > ensureOpen(); > - RAMFile file; > - synchronized (this) { > - file =3D fileMap.get(name); > - } > - if (file=3D=3Dnull) > + RAMFile file =3D fileMap.get(name); > + if (file =3D=3D null) { > throw new FileNotFoundException(name); > + } > return file.getLastModified(); > } >=20 > @@ -125,12 +114,10 @@ public class RAMDirectory extends Direct > @Override > public void touchFile(String name) throws IOException { > ensureOpen(); > - RAMFile file; > - synchronized (this) { > - file =3D fileMap.get(name); > - } > - if (file=3D=3Dnull) > + RAMFile file =3D fileMap.get(name); > + if (file =3D=3D null) { > throw new FileNotFoundException(name); > + } >=20 > long ts2, ts1 =3D System.currentTimeMillis(); > do { > @@ -151,19 +138,18 @@ public class RAMDirectory extends Direct > @Override > public final long fileLength(String name) throws IOException { > ensureOpen(); > - RAMFile file; > - synchronized (this) { > - file =3D fileMap.get(name); > - } > - if (file=3D=3Dnull) > + RAMFile file =3D fileMap.get(name); > + if (file =3D=3D null) { > throw new FileNotFoundException(name); > + } > return file.getLength(); > } >=20 > - /** Return total size in bytes of all files in this > - * directory. This is currently quantized to > - * RAMOutputStream.BUFFER_SIZE. */ > - public synchronized final long sizeInBytes() { > + /** > + * Return total size in bytes of all files in this directory. This = is > + * currently quantized to RAMOutputStream.BUFFER_SIZE. > + */ > + public final long sizeInBytes() { > ensureOpen(); > return sizeInBytes.get(); > } > @@ -172,14 +158,15 @@ public class RAMDirectory extends Direct > * @throws IOException if the file does not exist > */ > @Override > - public synchronized void deleteFile(String name) throws IOException = { > + public void deleteFile(String name) throws IOException { > ensureOpen(); > RAMFile file =3D fileMap.remove(name); > - if (file!=3Dnull) { > - file.directory =3D null; > - sizeInBytes.addAndGet(-file.sizeInBytes); > - } else > + if (file !=3D null) { > + file.directory =3D null; > + sizeInBytes.addAndGet(-file.sizeInBytes); > + } else { > throw new FileNotFoundException(name); > + } > } >=20 > /** Creates a new, empty file in the directory with the given name. = Returns > a stream writing this file. */ > @@ -187,14 +174,12 @@ public class RAMDirectory extends Direct > public IndexOutput createOutput(String name) throws IOException { > ensureOpen(); > RAMFile file =3D newRAMFile(); > - synchronized (this) { > - RAMFile existing =3D fileMap.get(name); > - if (existing!=3Dnull) { > - sizeInBytes.addAndGet(-existing.sizeInBytes); > - existing.directory =3D null; > - } > - fileMap.put(name, file); > + RAMFile existing =3D fileMap.remove(name); > + if (existing !=3D null) { > + sizeInBytes.addAndGet(-existing.sizeInBytes); > + existing.directory =3D null; > } > + fileMap.put(name, file); > return new RAMOutputStream(file); > } >=20 > @@ -211,12 +196,10 @@ public class RAMDirectory extends Direct > @Override > public IndexInput openInput(String name) throws IOException { > ensureOpen(); > - RAMFile file; > - synchronized (this) { > - file =3D fileMap.get(name); > - } > - if (file =3D=3D null) > + RAMFile file =3D fileMap.get(name); > + if (file =3D=3D null) { > throw new FileNotFoundException(name); > + } > return new RAMInputStream(file); > } >=20 >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org For additional commands, e-mail: dev-help@lucene.apache.org