You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2009/12/02 19:44:04 UTC
svn commit: r886250 - in
/lucene/java/branches/lucene_3_0_back_compat_tests/src:
java/org/apache/lucene/store/RAMDirectory.java
java/org/apache/lucene/store/RAMFile.java
test/org/apache/lucene/store/MockRAMDirectory.java
Author: mikemccand
Date: Wed Dec 2 18:43:59 2009
New Revision: 886250
URL: http://svn.apache.org/viewvc?rev=886250&view=rev
Log:
LUCENE-2095 (on 3.0 back compat branch): fix thread safety issue with iw.commit()
Modified:
lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMDirectory.java
lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMFile.java
lucene/java/branches/lucene_3_0_back_compat_tests/src/test/org/apache/lucene/store/MockRAMDirectory.java
Modified: lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMDirectory.java?rev=886250&r1=886249&r2=886250&view=diff
==============================================================================
--- lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMDirectory.java (original)
+++ lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMDirectory.java Wed Dec 2 18:43:59 2009
@@ -22,6 +22,7 @@
import java.io.Serializable;
import java.util.HashMap;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.lucene.util.ThreadInterruptedException;
/**
@@ -34,7 +35,7 @@
private static final long serialVersionUID = 1l;
HashMap<String,RAMFile> fileMap = new HashMap<String,RAMFile>();
- long sizeInBytes = 0;
+ final AtomicLong sizeInBytes = new AtomicLong();
// *****
// Lock acquisition sequence: RAMDirectory, then RAMFile
@@ -153,7 +154,7 @@
* RAMOutputStream.BUFFER_SIZE. */
public synchronized final long sizeInBytes() {
ensureOpen();
- return sizeInBytes;
+ return sizeInBytes.get();
}
/** Removes an existing file in the directory.
@@ -166,7 +167,7 @@
if (file!=null) {
fileMap.remove(name);
file.directory = null;
- sizeInBytes -= file.sizeInBytes; // updates to RAMFile.sizeInBytes synchronized on directory
+ sizeInBytes.addAndGet(-file.sizeInBytes);
} else
throw new FileNotFoundException(name);
}
@@ -179,7 +180,7 @@
synchronized (this) {
RAMFile existing = fileMap.get(name);
if (existing!=null) {
- sizeInBytes -= existing.sizeInBytes;
+ sizeInBytes.addAndGet(existing.sizeInBytes);
existing.directory = null;
}
fileMap.put(name, file);
Modified: lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMFile.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMFile.java?rev=886250&r1=886249&r2=886250&view=diff
==============================================================================
--- lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMFile.java (original)
+++ lucene/java/branches/lucene_3_0_back_compat_tests/src/java/org/apache/lucene/store/RAMFile.java Wed Dec 2 18:43:59 2009
@@ -62,7 +62,7 @@
if (directory!=null)
synchronized (directory) { // Ensure addition of buffer and adjustment to directory size are atomic wrt directory
buffers.add(buffer);
- directory.sizeInBytes += size;
+ directory.sizeInBytes.getAndAdd(size);
sizeInBytes += size;
}
else
Modified: lucene/java/branches/lucene_3_0_back_compat_tests/src/test/org/apache/lucene/store/MockRAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0_back_compat_tests/src/test/org/apache/lucene/store/MockRAMDirectory.java?rev=886250&r1=886249&r2=886250&view=diff
==============================================================================
--- lucene/java/branches/lucene_3_0_back_compat_tests/src/test/org/apache/lucene/store/MockRAMDirectory.java (original)
+++ lucene/java/branches/lucene_3_0_back_compat_tests/src/test/org/apache/lucene/store/MockRAMDirectory.java Wed Dec 2 18:43:59 2009
@@ -213,7 +213,7 @@
throw new IOException("file " + name + " already exists");
else {
if (existing!=null) {
- sizeInBytes -= existing.sizeInBytes;
+ sizeInBytes.getAndAdd(-existing.sizeInBytes);
existing.directory = null;
}