Skip to content

Apache Lucene open-source search software

LUCENE-5621: remove IndexOutput.flush

Robert Muirec0a9f1f138e
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 2b6059e9916..04d8948f0d8 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -83,6 +83,9 @@ API Changes
IndexOutput.getFilePointer instead) and IndexOutput.setLength.
(Mike McCandless)
+* LUCENE-5621: Deprecate IndexOutput.flush: this is not used by Lucene.
+ (Robert Muir)
+
Optimizations
* LUCENE-5603: hunspell stemmer more efficiently strips prefixes
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java
index d33ccc2f50f..ab1009a5175 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java
@@ -383,7 +383,6 @@ public final class DirectPostingsFormat extends PostingsFormat {
final byte[] payloads;
if (hasPayloads) {
- ros.flush();
payloads = new byte[(int) ros.getFilePointer()];
ros.writeTo(payloads, 0);
} else {
diff --git a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java
index 849fde3e2ad..45f211a16b9 100644
--- a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java
@@ -100,8 +100,8 @@ public abstract class BufferedIndexOutput extends IndexOutput {
}
}
- @Override
- public void flush() throws IOException {
+ /** Forces any buffered output to be written. */
+ protected void flush() throws IOException {
crc.update(buffer, 0, bufferPosition);
flushBuffer(buffer, bufferPosition);
bufferStart += bufferPosition;
diff --git a/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java b/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
index ad1265ad894..076402cf352 100644
--- a/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
@@ -298,11 +298,6 @@ final class CompoundFileWriter implements Closeable{
}
- @Override
- public void flush() throws IOException {
- delegate.flush();
- }
-
@Override
public void close() throws IOException {
if (!closed) {
diff --git a/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java
index 0a2f608cb0b..618d1356075 100644
--- a/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java
@@ -31,9 +31,6 @@ import java.io.IOException;
*/
public abstract class IndexOutput extends DataOutput implements Closeable {
- /** Forces any buffered output to be written. */
- public abstract void flush() throws IOException;
-
/** Closes this stream to further operations. */
@Override
public abstract void close() throws IOException;
diff --git a/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java b/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java
index 400dcf93878..0a56508ed3d 100644
--- a/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java
+++ b/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java
@@ -154,8 +154,8 @@ public class RAMOutputStream extends IndexOutput {
}
}
- @Override
- public void flush() throws IOException {
+ /** Forces any buffered output to be written. */
+ protected void flush() throws IOException {
setFileLength();
}
diff --git a/lucene/core/src/java/org/apache/lucene/store/RateLimitedIndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/RateLimitedIndexOutput.java
index 296c7f1a216..b4ba1a001e3 100644
--- a/lucene/core/src/java/org/apache/lucene/store/RateLimitedIndexOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/RateLimitedIndexOutput.java
@@ -50,15 +50,6 @@ final class RateLimitedIndexOutput extends BufferedIndexOutput {
}
}
-
- @Override
- public void flush() throws IOException {
- try {
- super.flush();
- } finally {
- delegate.flush();
- }
- }
@Override
public void close() throws IOException {
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMockDirectoryWrapper.java b/lucene/core/src/test/org/apache/lucene/store/TestMockDirectoryWrapper.java
index 6fe699643d2..8c6371d218d 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestMockDirectoryWrapper.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestMockDirectoryWrapper.java
@@ -59,9 +59,10 @@ public class TestMockDirectoryWrapper extends LuceneTestCase {
final byte[] bytes = new byte[] { 1, 2};
IndexOutput out = dir.createOutput("foo", IOContext.DEFAULT);
out.writeBytes(bytes, bytes.length); // first write should succeed
- // flush() to ensure the written bytes are not buffered and counted
+ // close() to ensure the written bytes are not buffered and counted
// against the directory size
- out.flush();
+ out.close();
+ out = dir.createOutput("bar", IOContext.DEFAULT);
try {
out.writeBytes(bytes, bytes.length);
fail("should have failed on disk full");
@@ -76,9 +77,10 @@ public class TestMockDirectoryWrapper extends LuceneTestCase {
dir.setMaxSizeInBytes(3);
out = dir.createOutput("foo", IOContext.DEFAULT);
out.copyBytes(new ByteArrayDataInput(bytes), bytes.length); // first copy should succeed
- // flush() to ensure the written bytes are not buffered and counted
+ // close() to ensure the written bytes are not buffered and counted
// against the directory size
- out.flush();
+ out.close();
+ out = dir.createOutput("bar", IOContext.DEFAULT);
try {
out.copyBytes(new ByteArrayDataInput(bytes), bytes.length);
fail("should have failed on disk full");
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/SlowRAMDirectory.java b/lucene/facet/src/test/org/apache/lucene/facet/SlowRAMDirectory.java
index 4766dbfc766..fa7a33286ca 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/SlowRAMDirectory.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/SlowRAMDirectory.java
@@ -164,7 +164,6 @@ public class SlowRAMDirectory extends RAMDirectory {
}
@Override public void close() throws IOException { io.close(); }
- @Override public void flush() throws IOException { io.flush(); }
@Override public long getFilePointer() { return io.getFilePointer(); }
@Override public long getChecksum() throws IOException { return io.getChecksum(); }
}
diff --git a/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java b/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java
index cd288a3f65c..2ec35322dcb 100644
--- a/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java
+++ b/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java
@@ -198,11 +198,6 @@ public class NativeUnixDirectory extends FSDirectory {
// FileChannel provides an API?
//}
- @Override
- public void flush() {
- // TODO -- I don't think this method is necessary?
- }
-
private void dump() throws IOException {
buffer.flip();
final long limit = filePos + buffer.limit();
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 d426b1a6f39..371a0fd5f95 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
@@ -983,15 +983,6 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
io.writeBytes(b, offset, len);
}
- @Override
- public void flush() throws IOException {
- try {
- super.flush();
- } finally {
- io.flush();
- }
- }
-
@Override
public void close() throws IOException {
try {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java
index 4c056b2c9f7..b256c039a60 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java
@@ -105,12 +105,6 @@ public class MockIndexOutputWrapper extends IndexOutput {
}
}
- @Override
- public void flush() throws IOException {
- dir.maybeThrowDeterministicException();
- delegate.flush();
- }
-
@Override
public void writeByte(byte b) throws IOException {
singleByte[0] = b;
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/ThrottledIndexOutput.java b/lucene/test-framework/src/java/org/apache/lucene/util/ThrottledIndexOutput.java
index bcc23250ebf..1c93bf8ef7e 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/ThrottledIndexOutput.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/ThrottledIndexOutput.java
@@ -68,12 +68,6 @@ public class ThrottledIndexOutput extends IndexOutput {
this.minBytesWritten = minBytesWritten;
}
- @Override
- public void flush() throws IOException {
- sleep(flushDelayMillis);
- delegate.flush();
- }
-
@Override
public void close() throws IOException {
try {
diff --git a/solr/core/src/java/org/apache/solr/store/blockcache/CachedIndexOutput.java b/solr/core/src/java/org/apache/solr/store/blockcache/CachedIndexOutput.java
index 5c76a9848ac..28383b16d96 100644
--- a/solr/core/src/java/org/apache/solr/store/blockcache/CachedIndexOutput.java
+++ b/solr/core/src/java/org/apache/solr/store/blockcache/CachedIndexOutput.java
@@ -45,12 +45,7 @@ public class CachedIndexOutput extends ReusedBufferedIndexOutput {
this.location = directory.getFileCacheLocation(name);
this.cache = cache;
}
-
- @Override
- public void flushInternal() throws IOException {
- dest.flush();
- }
-
+
@Override
public void closeInternal() throws IOException {
dest.close();
@@ -91,7 +86,7 @@ public class CachedIndexOutput extends ReusedBufferedIndexOutput {
@Override
public long getChecksum() throws IOException {
- flush();
+ flushBufferToCache();
return dest.getChecksum();
}
}
diff --git a/solr/core/src/java/org/apache/solr/store/blockcache/ReusedBufferedIndexOutput.java b/solr/core/src/java/org/apache/solr/store/blockcache/ReusedBufferedIndexOutput.java
index bc251f0540a..06a5afea6de 100644
--- a/solr/core/src/java/org/apache/solr/store/blockcache/ReusedBufferedIndexOutput.java
+++ b/solr/core/src/java/org/apache/solr/store/blockcache/ReusedBufferedIndexOutput.java
@@ -64,7 +64,7 @@ public abstract class ReusedBufferedIndexOutput extends IndexOutput {
}
/** Write the buffered bytes to cache */
- private void flushBufferToCache() throws IOException {
+ protected void flushBufferToCache() throws IOException {
writeInternal(buffer, 0, bufferLength);
bufferStart += bufferLength;
@@ -72,14 +72,6 @@ public abstract class ReusedBufferedIndexOutput extends IndexOutput {
bufferPosition = 0;
}
- protected abstract void flushInternal() throws IOException;
-
- @Override
- public void flush() throws IOException {
- flushBufferToCache();
- flushInternal();
- }
-
protected abstract void closeInternal() throws IOException;
@Override
diff --git a/solr/core/src/java/org/apache/solr/store/hdfs/NullIndexOutput.java b/solr/core/src/java/org/apache/solr/store/hdfs/NullIndexOutput.java
index 5a21ea7e5f0..9e658c91d17 100644
--- a/solr/core/src/java/org/apache/solr/store/hdfs/NullIndexOutput.java
+++ b/solr/core/src/java/org/apache/solr/store/hdfs/NullIndexOutput.java
@@ -34,11 +34,6 @@ public class NullIndexOutput extends IndexOutput {
}
- @Override
- public void flush() throws IOException {
-
- }
-
@Override
public long getFilePointer() {
return pos;
diff --git a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java
index e55e5b9f75f..7289d736863 100644
--- a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java
+++ b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java
@@ -92,7 +92,6 @@ public class HdfsDirectoryTest extends SolrTestCaseJ4 {
IndexOutput output = directory.createOutput("testing.test", new IOContext());
output.writeInt(12345);
- output.flush();
output.close();
IndexInput input = directory.openInput("testing.test", new IOContext());