Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-430: Delay allocation of the buffer after a clone of BufferedIndexInput.

Michael Busch393b4525dbfd
diff --git a/CHANGES.txt b/CHANGES.txt
index fe90a72c860..e6365292ed2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -180,6 +180,10 @@ Optimizations
4. LUCENE-882: Spellchecker doesn't store the ngrams anymore but only indexes
them to keep the spell index small. (Daniel Naber)
+
+ 5. LUCENE-430: Delay allocation of the buffer after a clone of BufferedIndexInput.
+ Together with LUCENE-888 this will allow to adjust the buffer size
+ dynamically. (Paul Elschot, Michael Busch)
Documentation
diff --git a/src/java/org/apache/lucene/store/BufferedIndexInput.java b/src/java/org/apache/lucene/store/BufferedIndexInput.java
index 9ea130bd427..fb151ab3c7b 100644
--- a/src/java/org/apache/lucene/store/BufferedIndexInput.java
+++ b/src/java/org/apache/lucene/store/BufferedIndexInput.java
@@ -88,8 +88,10 @@ public abstract class BufferedIndexInput extends IndexInput {
if (bufferLength <= 0)
throw new IOException("read past EOF");
- if (buffer == null)
+ if (buffer == null) {
buffer = new byte[BUFFER_SIZE]; // allocate buffer lazily
+ seekInternal(bufferStart);
+ }
readInternal(buffer, 0, bufferLength);
bufferStart = start;
@@ -127,10 +129,10 @@ public abstract class BufferedIndexInput extends IndexInput {
public Object clone() {
BufferedIndexInput clone = (BufferedIndexInput)super.clone();
- if (buffer != null) {
- clone.buffer = new byte[BUFFER_SIZE];
- System.arraycopy(buffer, 0, clone.buffer, 0, bufferLength);
- }
+ clone.buffer = null;
+ clone.bufferLength = 0;
+ clone.bufferPosition = 0;
+ clone.bufferStart = getFilePointer();
return clone;
}