lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject lucene-solr:branch_6x: LUCENE-7345: RAMDirectory now enforces write-once as well
Date Mon, 20 Jun 2016 14:07:18 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 0a0865b2c -> 07920c4fd


LUCENE-7345: RAMDirectory now enforces write-once as well


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/07920c4f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/07920c4f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/07920c4f

Branch: refs/heads/branch_6x
Commit: 07920c4fdaaa12255fc3700459043018ad73af0e
Parents: 0a0865b
Author: Mike McCandless <mikemccand@apache.org>
Authored: Mon Jun 20 10:03:19 2016 -0400
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Mon Jun 20 10:03:39 2016 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                                  |  3 +++
 .../java/org/apache/lucene/store/RAMDirectory.java  | 15 +++++++++------
 .../apache/lucene/store/MockDirectoryWrapper.java   | 16 ----------------
 3 files changed, 12 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/07920c4f/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 5ee8140..47bc213 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -43,6 +43,9 @@ Improvements
   module into core and is now the default analyzer in
   IndexWriterConfig (Robert Muir, Mike McCandless)
 
+* LUCENE-7345: RAMDirectory now enforces write-once files as well
+  (Robert Muir, Mike McCandless)
+
 Optimizations
 
 * LUCENE-7330: Speed up conjunction queries. (Adrien Grand)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/07920c4f/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java b/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java
index a4bc2ea..54375e6 100644
--- a/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java
@@ -19,6 +19,7 @@ package org.apache.lucene.store;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -177,12 +178,9 @@ public class RAMDirectory extends BaseDirectory implements Accountable
{
   public IndexOutput createOutput(String name, IOContext context) throws IOException {
     ensureOpen();
     RAMFile file = newRAMFile();
-    RAMFile existing = fileMap.remove(name);
-    if (existing != null) {
-      sizeInBytes.addAndGet(-existing.sizeInBytes);
-      existing.directory = null;
+    if (fileMap.putIfAbsent(name, file) != null) {
+      throw new FileAlreadyExistsException(name);
     }
-    fileMap.put(name, file);
     return new RAMOutputStream(name, file, true);
   }
 
@@ -222,7 +220,12 @@ public class RAMDirectory extends BaseDirectory implements Accountable
{
     if (file == null) {
       throw new FileNotFoundException(source);
     }
-    fileMap.put(dest, file);
+    if (fileMap.putIfAbsent(dest, file) != null) {
+      throw new FileAlreadyExistsException(dest);
+    }
+    if (!fileMap.remove(source, file)) {
+      throw new IllegalStateException("file was unexpectedly replaced: " + source);
+    }
     fileMap.remove(source);
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/07920c4f/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
index 209ee80..193d877 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
@@ -636,22 +636,6 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
     unSyncedFiles.add(name);
     createdFiles.add(name);
     
-    if (in instanceof RAMDirectory) {
-      RAMDirectory ramdir = (RAMDirectory) in;
-      RAMFile file = new RAMFile(ramdir);
-      RAMFile existing = ramdir.fileMap.get(name);
-    
-      // Enforce write once:
-      if (existing!=null && !name.equals("segments.gen")) {
-        throw new IOException("file " + name + " already exists");
-      } else {
-        if (existing!=null) {
-          ramdir.sizeInBytes.getAndAdd(-existing.sizeInBytes);
-          existing.directory = null;
-        }
-        ramdir.fileMap.put(name, file);
-      }
-    }
     //System.out.println(Thread.currentThread().getName() + ": MDW: create " + name);
     IndexOutput delegateOutput = in.createOutput(name, LuceneTestCase.newIOContext(randomState,
context));
     final IndexOutput io = new MockIndexOutputWrapper(this, delegateOutput, name);


Mime
View raw message