Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-6150: Remove staleFiles set and onIndexOutputClosed() from FSDirectory

Uwe Schindler23aa3e09064b
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 4c98a160804..6c1e3ba53a9 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -326,6 +326,9 @@ API Changes
* LUCENE-6147: Make the core Accountables.namedAccountable function public
(Ryan Ernst)
+* LUCENE-6150: Remove staleFiles set and onIndexOutputClosed() from FSDirectory.
+ (Uwe Schindler, Robert Muir, Mike McCandless)
+
Bug Fixes
* LUCENE-5650: Enforce read-only access to any path outside the temporary
diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
index a2ba2a68b8a..c96d682fc81 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
@@ -17,9 +17,6 @@ package org.apache.lucene.store;
* limitations under the License.
*/
-import org.apache.lucene.util.Constants;
-import org.apache.lucene.util.IOUtils;
-
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
@@ -29,12 +26,11 @@ import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import java.util.concurrent.Future;
-import static java.util.Collections.synchronizedSet;
+import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.IOUtils;
/**
* Base class for Directory implementations that store index
@@ -116,7 +112,6 @@ import static java.util.Collections.synchronizedSet;
public abstract class FSDirectory extends BaseDirectory {
protected final Path directory; // The underlying filesystem directory
- protected final Set<String> staleFiles = synchronizedSet(new HashSet<String>()); // Files written, but not yet sync'ed
/** Create a new FSDirectory for the named location (ctor for subclasses).
* @param path the path of the directory
@@ -208,7 +203,6 @@ public abstract class FSDirectory extends BaseDirectory {
public void deleteFile(String name) throws IOException {
ensureOpen();
Files.delete(directory.resolve(name));
- staleFiles.remove(name);
}
/** Creates an IndexOutput for the file with the given name. */
@@ -224,25 +218,13 @@ public abstract class FSDirectory extends BaseDirectory {
Files.deleteIfExists(directory.resolve(name)); // delete existing, if any
}
- /**
- * Sub classes should call this method on closing an open {@link IndexOutput}, reporting the name of the file
- * that was closed. {@code FSDirectory} needs this information to take care of syncing stale files.
- */
- protected void onIndexOutputClosed(String name) {
- staleFiles.add(name);
- }
-
@Override
public void sync(Collection<String> names) throws IOException {
ensureOpen();
- Set<String> toSync = new HashSet<>(names);
- toSync.retainAll(staleFiles);
- for (String name : toSync) {
+ for (String name : names) {
fsync(name);
}
-
- staleFiles.removeAll(toSync);
}
@Override
@@ -279,8 +261,6 @@ public abstract class FSDirectory extends BaseDirectory {
*/
static final int CHUNK_SIZE = 8192;
- private final String name;
-
public FSIndexOutput(String name) throws IOException {
super("FSIndexOutput(path=\"" + directory.resolve(name) + "\")", new FilterOutputStream(Files.newOutputStream(directory.resolve(name))) {
// This implementation ensures, that we never write more than CHUNK_SIZE bytes:
@@ -294,16 +274,6 @@ public abstract class FSDirectory extends BaseDirectory {
}
}
}, CHUNK_SIZE);
- this.name = name;
- }
-
- @Override
- public void close() throws IOException {
- try {
- onIndexOutputClosed(name);
- } finally {
- super.close();
- }
}
}