From 23aa3e09064b7147e3eb311283fe9e3410f9e39d Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Thu, 1 Jan 2015 10:43:29 +0000 Subject: [PATCH] LUCENE-6150: Remove staleFiles set and onIndexOutputClosed() from FSDirectory git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1648812 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 3 ++ .../org/apache/lucene/store/FSDirectory.java | 36 ++----------------- 2 files changed, 6 insertions(+), 33 deletions(-) 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 staleFiles = synchronizedSet(new HashSet()); // 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 names) throws IOException { ensureOpen(); - Set 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(); - } } }