Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

merged with trunk

Simon Willnauerfeb9739bf778
diff --cc lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingCodec.java
index 57915da0675,996293dee14..f39ce3db518
--- a/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingCodec.java
+++ b/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingCodec.java
@@@ -154,6 -153,6 +153,6 @@@ public class AppendingCodec extends Cod
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), state.context);
}
}
diff --cc lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java
index 0e435c5eb29,a4c6301ee34..29d8998cfc8
--- a/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java
+++ b/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java
@@@ -68,9 -67,9 +68,9 @@@ public class WindowsDirectory extends F
}
@Override
- public IndexInput openInput(String name, int bufferSize) throws IOException {
+ public IndexInput openInput(String name, IOContext context) throws IOException {
ensureOpen();
- return new WindowsIndexInput(new File(getDirectory(), name), DEFAULT_BUFFERSIZE);
- return new WindowsIndexInput(new File(getDirectory(), name), Math.max(bufferSize, DEFAULT_BUFFERSIZE));
++ return new WindowsIndexInput(new File(getDirectory(), name), Math.max(BufferedIndexInput.bufferSize(context), DEFAULT_BUFFERSIZE));
}
protected static class WindowsIndexInput extends BufferedIndexInput {
diff --cc lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
index d10cdc7eb64,d2a3e7a0ff4..1cd79da8373
--- a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
+++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
@@@ -30,9 -30,6 +30,8 @@@ import org.apache.lucene.document.Docum
import org.apache.lucene.index.DocumentsWriterDeleteQueue.DeleteSlice;
import org.apache.lucene.search.SimilarityProvider;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FlushInfo;
+import org.apache.lucene.store.IOContext;
- import org.apache.lucene.store.IOContext.Context;
import org.apache.lucene.util.BitVector;
import org.apache.lucene.util.ByteBlockPool.Allocator;
import org.apache.lucene.util.ByteBlockPool.DirectTrackingAllocator;
@@@ -546,7 -543,7 +545,7 @@@ public class DocumentsWriterPerThread
PerDocWriteState newPerDocWriteState(int codecId) {
assert segment != null;
-- return new PerDocWriteState(infoStream, directory, segment, fieldInfos, bytesUsed, codecId);
++ return new PerDocWriteState(infoStream, directory, segment, fieldInfos, bytesUsed, codecId, IOContext.DEFAULT);
}
void setInfoStream(PrintStream infoStream) {
diff --cc lucene/src/java/org/apache/lucene/index/FieldsReader.java
index 1d23a72db81,6ac0d436ffe..f56769bef83
--- a/lucene/src/java/org/apache/lucene/index/FieldsReader.java
+++ b/lucene/src/java/org/apache/lucene/index/FieldsReader.java
@@@ -28,12 -28,14 +28,15 @@@ import org.apache.lucene.document.Numer
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.BufferedIndexInput;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.util.CloseableThreadLocal;
+ import org.apache.lucene.util.IOUtils;
+ import java.io.Closeable;
import java.io.IOException;
import java.io.Reader;
+ import java.util.ArrayList;
/**
* Class responsible for access to stored document fields.
diff --cc lucene/src/java/org/apache/lucene/index/PerDocWriteState.java
index e7b1d9339ed,e7b1d9339ed..8bf08f309ce
--- a/lucene/src/java/org/apache/lucene/index/PerDocWriteState.java
+++ b/lucene/src/java/org/apache/lucene/index/PerDocWriteState.java
@@@ -20,6 -20,6 +20,7 @@@ import java.util.concurrent.atomic.Atom
import org.apache.lucene.index.codecs.PerDocConsumer;
import org.apache.lucene.store.Directory;
++import org.apache.lucene.store.IOContext;
/**
* Encapsulates all necessary state to initiate a {@link PerDocConsumer} and
@@@ -35,10 -35,10 +36,11 @@@ public class PerDocWriteState
public final AtomicLong bytesUsed;
public final SegmentCodecs segmentCodecs;
public final int codecId;
++ public final IOContext context;
PerDocWriteState(PrintStream infoStream, Directory directory,
String segmentName, FieldInfos fieldInfos, AtomicLong bytesUsed,
-- int codecId) {
++ int codecId, IOContext context) {
this.infoStream = infoStream;
this.directory = directory;
this.segmentName = segmentName;
@@@ -46,6 -46,6 +48,7 @@@
this.segmentCodecs = fieldInfos.buildSegmentCodecs(false);
this.codecId = codecId;
this.bytesUsed = bytesUsed;
++ this.context = context;
}
PerDocWriteState(SegmentWriteState state) {
@@@ -56,6 -56,6 +59,7 @@@
fieldInfos = state.fieldInfos;
codecId = state.codecId;
bytesUsed = new AtomicLong(0);
++ context = state.context;
}
PerDocWriteState(PerDocWriteState state, int codecId) {
@@@ -66,5 -66,5 +70,6 @@@
this.segmentCodecs = state.segmentCodecs;
this.codecId = codecId;
this.bytesUsed = state.bytesUsed;
++ this.context = state.context;
}
}
diff --cc lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java
index d478f856b51,85341563d40..2e392e535fc
--- a/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java
+++ b/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java
@@@ -25,7 -25,7 +25,8 @@@ import org.apache.lucene.index.codecs.F
import org.apache.lucene.index.codecs.PerDocValues;
import org.apache.lucene.store.CompoundFileDirectory;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+ import org.apache.lucene.util.IOUtils;
/** Holds core readers that are shared (unchanged) when
* SegmentReader is cloned or reopened */
diff --cc lucene/src/java/org/apache/lucene/index/SegmentInfo.java
index 629165164da,e25f0807a28..f2180b0132b
--- a/lucene/src/java/org/apache/lucene/index/SegmentInfo.java
+++ b/lucene/src/java/org/apache/lucene/index/SegmentInfo.java
@@@ -30,9 -30,8 +30,8 @@@ import java.util.Set
import org.apache.lucene.index.codecs.Codec;
import org.apache.lucene.index.codecs.CodecProvider;
import org.apache.lucene.index.codecs.DefaultSegmentInfosWriter;
--import org.apache.lucene.store.BufferedIndexInput;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.util.Constants;
@@@ -248,7 -247,7 +247,7 @@@ public final class SegmentInfo implemen
}
final Directory dirToTest;
if (isCompoundFile) {
- dirToTest = dir.openCompoundInput(IndexFileNames.segmentFileName(storesSegment, "", ext), IOContext.READONCE );
- dirToTest = dir.openCompoundInput(IndexFileNames.segmentFileName(storesSegment, "", ext), BufferedIndexInput.BUFFER_SIZE);
++ dirToTest = dir.openCompoundInput(IndexFileNames.segmentFileName(storesSegment, "", ext), IOContext.READONCE);
} else {
dirToTest = dir;
}
diff --cc lucene/src/java/org/apache/lucene/index/TermVectorsReader.java
index ca9b628cb0e,0d6b7dcbaf1..b03463782ff
--- a/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java
+++ b/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java
@@@ -17,15 -17,14 +17,17 @@@ package org.apache.lucene.index
* limitations under the License.
*/
+import org.apache.lucene.index.MergePolicy.OneMerge;
import org.apache.lucene.store.BufferedIndexInput;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IOContext.Context;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
+ import org.apache.lucene.util.IOUtils;
+ import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
diff --cc lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesConsumer.java
index b02c9c91d49,af9c416b926..d1749fb320a
--- a/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesConsumer.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesConsumer.java
@@@ -29,34 -29,41 +29,46 @@@ import org.apache.lucene.index.PerDocWr
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.index.values.Writer;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
import org.apache.lucene.util.BytesRef;
+ /**
+ *
+ * @lucene.experimental
+ */
public class DefaultDocValuesConsumer extends PerDocConsumer {
private final String segmentName;
private final int codecId;
private final Directory directory;
private final AtomicLong bytesUsed;
private final Comparator<BytesRef> comparator;
-
- public DefaultDocValuesConsumer(PerDocWriteState state, Comparator<BytesRef> comparator) {
+ private boolean useCompoundFile;
++ private final IOContext context;
+
+ public DefaultDocValuesConsumer(PerDocWriteState state, Comparator<BytesRef> comparator, boolean useCompoundFile) throws IOException {
this.segmentName = state.segmentName;
this.codecId = state.codecId;
this.bytesUsed = state.bytesUsed;
- this.directory = state.directory;
++ this.context = state.context;
+ //TODO maybe we should enable a global CFS that all codecs can pull on demand to further reduce the number of files?
- this.directory = useCompoundFile ? state.directory.createCompoundOutput(IndexFileNames.segmentFileName(segmentName, state.codecId, IndexFileNames.COMPOUND_FILE_EXTENSION)) : state.directory;
++ this.directory = useCompoundFile ? state.directory.createCompoundOutput(
++ IndexFileNames.segmentFileName(segmentName, codecId,
++ IndexFileNames.COMPOUND_FILE_EXTENSION), context) : state.directory;
this.comparator = comparator;
+ this.useCompoundFile = useCompoundFile;
}
-
+
public void close() throws IOException {
+ if (useCompoundFile) {
+ this.directory.close();
+ }
}
@Override
public DocValuesConsumer addValuesField(FieldInfo field) throws IOException {
return Writer.create(field.getDocValues(),
docValuesId(segmentName, codecId, field.number),
- // TODO can we have a compound file per segment and codec for
- // docvalues?
- directory, comparator, bytesUsed, IOContext.DEFAULT);
- directory, comparator, bytesUsed);
++ directory, comparator, bytesUsed, context);
}
@SuppressWarnings("fallthrough")
diff --cc lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java
index 663df35c036,07477086784..6a3207d2b96
--- a/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java
@@@ -29,7 -33,8 +33,9 @@@ import org.apache.lucene.index.values.F
import org.apache.lucene.index.values.Ints;
import org.apache.lucene.index.values.ValueType;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+ import org.apache.lucene.util.BytesRef;
+ import org.apache.lucene.util.IOUtils;
/**
* Abstract base class for FieldsProducer implementations supporting
@@@ -56,9 -71,18 +72,18 @@@ public class DefaultDocValuesProducer e
* @throws IOException
* if an {@link IOException} occurs
*/
- public DefaultDocValuesProducer(SegmentInfo si, Directory dir,
- FieldInfos fieldInfo, int codecId, IOContext context) throws IOException {
- docValues = load(fieldInfo, si.name, si.docCount, dir, codecId, context);
+ public DefaultDocValuesProducer(SegmentInfo si, Directory dir,
- FieldInfos fieldInfo, int codecId, boolean useCompoundFile, Comparator<BytesRef> sortComparator) throws IOException {
++ FieldInfos fieldInfo, int codecId, boolean useCompoundFile, Comparator<BytesRef> sortComparator, IOContext context) throws IOException {
+ this.useCompoundFile = useCompoundFile;
+ this.sortComparator = sortComparator;
+ final Directory directory;
+ if (useCompoundFile) {
- cfs = directory = dir.openCompoundInput(IndexFileNames.segmentFileName(si.name, codecId, IndexFileNames.COMPOUND_FILE_EXTENSION), 1024);
++ cfs = directory = dir.openCompoundInput(IndexFileNames.segmentFileName(si.name, codecId, IndexFileNames.COMPOUND_FILE_EXTENSION), context);
+ } else {
+ cfs = null;
+ directory = dir;
+ }
- docValues = load(fieldInfo, si.name, si.docCount, directory, codecId);
++ docValues = load(fieldInfo, si.name, si.docCount, directory, codecId, context);
}
/**
@@@ -86,7 -110,7 +111,7 @@@
final String id = DefaultDocValuesConsumer.docValuesId(segment,
codecId, fieldInfo.number);
values.put(field,
- loadDocValues(docCount, dir, id, fieldInfo.getDocValues(), context));
- loadDocValues(docCount, dir, id, fieldInfo.getDocValues(), sortComparator));
++ loadDocValues(docCount, dir, id, fieldInfo.getDocValues(), sortComparator, context));
}
}
success = true;
@@@ -120,30 -145,30 +146,30 @@@
* if the given {@link ValueType} is not supported
*/
protected IndexDocValues loadDocValues(int docCount, Directory dir, String id,
- ValueType type, IOContext context) throws IOException {
- ValueType type, Comparator<BytesRef> sortComparator) throws IOException {
++ ValueType type, Comparator<BytesRef> sortComparator, IOContext context) throws IOException {
switch (type) {
case FIXED_INTS_16:
case FIXED_INTS_32:
case FIXED_INTS_64:
case FIXED_INTS_8:
case VAR_INTS:
- return Ints.getValues(dir, id, docCount);
+ return Ints.getValues(dir, id, docCount, context);
case FLOAT_32:
- return Floats.getValues(dir, id, docCount);
+ return Floats.getValues(dir, id, docCount, context);
case FLOAT_64:
- return Floats.getValues(dir, id, docCount);
+ return Floats.getValues(dir, id, docCount, context);
case BYTES_FIXED_STRAIGHT:
- return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, true, docCount, context);
- return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, true, docCount, sortComparator);
++ return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, true, docCount, sortComparator, context);
case BYTES_FIXED_DEREF:
- return Bytes.getValues(dir, id, Bytes.Mode.DEREF, true, docCount, context);
- return Bytes.getValues(dir, id, Bytes.Mode.DEREF, true, docCount, sortComparator);
++ return Bytes.getValues(dir, id, Bytes.Mode.DEREF, true, docCount, sortComparator, context);
case BYTES_FIXED_SORTED:
- return Bytes.getValues(dir, id, Bytes.Mode.SORTED, true, docCount, context);
- return Bytes.getValues(dir, id, Bytes.Mode.SORTED, true, docCount, sortComparator);
++ return Bytes.getValues(dir, id, Bytes.Mode.SORTED, true, docCount, sortComparator, context);
case BYTES_VAR_STRAIGHT:
- return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, false, docCount, context);
- return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, false, docCount, sortComparator);
++ return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, false, docCount, sortComparator, context);
case BYTES_VAR_DEREF:
- return Bytes.getValues(dir, id, Bytes.Mode.DEREF, false, docCount, context);
- return Bytes.getValues(dir, id, Bytes.Mode.DEREF, false, docCount, sortComparator);
++ return Bytes.getValues(dir, id, Bytes.Mode.DEREF, false, docCount, sortComparator, context);
case BYTES_VAR_SORTED:
- return Bytes.getValues(dir, id, Bytes.Mode.SORTED, false, docCount, context);
- return Bytes.getValues(dir, id, Bytes.Mode.SORTED, false, docCount, sortComparator);
++ return Bytes.getValues(dir, id, Bytes.Mode.SORTED, false, docCount, sortComparator, context);
default:
throw new IllegalStateException("unrecognized index values mode " + type);
}
diff --cc lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryCodec.java
index 79c1cab7e73,b165f623fe5..b4fed2dbabe
--- a/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryCodec.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryCodec.java
@@@ -795,6 -794,6 +795,6 @@@ public class MemoryCodec extends Codec
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, IOContext.READONCE);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), IOContext.READONCE);
}
}
diff --cc lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java
index e5c5283992b,1badc6f7e76..2bb6d97dfe3
--- a/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java
@@@ -173,6 -181,6 +181,6 @@@ public class PulsingCodec extends Code
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), state.context);
}
}
diff --cc lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextCodec.java
index 832b7e3bb20,d33cd1a5f8b..1bdb88fee48
--- a/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextCodec.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextCodec.java
@@@ -86,6 -86,6 +86,6 @@@ public class SimpleTextCodec extends Co
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), state.context);
}
}
diff --cc lucene/src/java/org/apache/lucene/index/codecs/standard/StandardCodec.java
index 47def928931,ffe18132261..eed2648e045
--- a/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardCodec.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardCodec.java
@@@ -163,6 -162,6 +162,6 @@@ public class StandardCodec extends Code
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), state.context);
}
}
diff --cc lucene/src/java/org/apache/lucene/index/values/Bytes.java
index 9735c69a0dc,cd4b06b8526..f92e6578bab
--- a/lucene/src/java/org/apache/lucene/index/values/Bytes.java
+++ b/lucene/src/java/org/apache/lucene/index/values/Bytes.java
@@@ -158,8 -157,7 +159,8 @@@ public final class Bytes
* if an {@link IOException} occurs
*/
public static IndexDocValues getValues(Directory dir, String id, Mode mode,
- boolean fixedSize, int maxDoc, IOContext context) throws IOException {
- boolean fixedSize, int maxDoc, Comparator<BytesRef> sortComparator) throws IOException {
++ boolean fixedSize, int maxDoc, Comparator<BytesRef> sortComparator, IOContext context) throws IOException {
+
// TODO -- I can peek @ header to determing fixed/mode?
if (fixedSize) {
if (mode == Mode.STRAIGHT) {
@@@ -171,11 -169,11 +172,11 @@@
}
} else {
if (mode == Mode.STRAIGHT) {
- return new VarStraightBytesImpl.Reader(dir, id, maxDoc);
+ return new VarStraightBytesImpl.Reader(dir, id, maxDoc, context);
} else if (mode == Mode.DEREF) {
- return new VarDerefBytesImpl.Reader(dir, id, maxDoc);
+ return new VarDerefBytesImpl.Reader(dir, id, maxDoc, context);
} else if (mode == Mode.SORTED) {
- return new VarSortedBytesImpl.Reader(dir, id, maxDoc, context);
- return new VarSortedBytesImpl.Reader(dir, id, maxDoc, sortComparator);
++ return new VarSortedBytesImpl.Reader(dir, id, maxDoc, sortComparator, context);
}
}
diff --cc lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java
index b452f45b006,e8e850023bb..3e884b391d2
--- a/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java
+++ b/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java
@@@ -168,8 -167,10 +168,11 @@@ class VarSortedBytesImpl
public static class Reader extends BytesReaderBase {
- Reader(Directory dir, String id, int maxDoc, IOContext context) throws IOException {
+ private final Comparator<BytesRef> defaultComp;
- Reader(Directory dir, String id, int maxDoc, Comparator<BytesRef> comparator) throws IOException {
- super(dir, id, CODEC_NAME, VERSION_START, true);
++
++ Reader(Directory dir, String id, int maxDoc, Comparator<BytesRef> comparator, IOContext context) throws IOException {
+ super(dir, id, CODEC_NAME, VERSION_START, true, context);
+ this.defaultComp = comparator;
}
@Override
diff --cc lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
index 371425f2c1b,40ec5659830..92c525604d6
--- a/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
+++ b/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
@@@ -59,11 -59,11 +59,11 @@@ public abstract class CompoundFileDirec
* <p>
* NOTE: subclasses must call {@link #initForRead(Map)} before the directory can be used.
*/
- public CompoundFileDirectory(Directory directory, String fileName, int readBufferSize) throws IOException {
+ public CompoundFileDirectory(Directory directory, String fileName, IOContext context) throws IOException {
- assert !(directory instanceof CompoundFileDirectory) : "compound file inside of compound file: " + fileName;
+
this.directory = directory;
this.fileName = fileName;
- this.readBufferSize = readBufferSize;
+ this.readBufferSize = BufferedIndexInput.bufferSize(context);
this.isOpen = false;
}
@@@ -261,10 -273,9 +267,9 @@@
}
@Override
- public IndexOutput createOutput(String name) throws IOException {
+ public IndexOutput createOutput(String name, IOContext context) throws IOException {
ensureOpen();
- initWriter();
- return writer.createOutput(name);
+ return writer.createOutput(name, context);
}
@Override
@@@ -279,29 -290,50 +284,50 @@@
throw new UnsupportedOperationException();
}
- /** Not implemented
- * @throws UnsupportedOperationException */
@Override
- public final CompoundFileDirectory openCompoundInput(String name, IOContext context) throws IOException {
- // NOTE: final to make nested compounding impossible.
- throw new UnsupportedOperationException();
- public CompoundFileDirectory openCompoundInput(String name, int bufferSize) throws IOException {
++ public CompoundFileDirectory openCompoundInput(String name, IOContext context) throws IOException {
+ FileEntry fileEntry = this.entries.get(IndexFileNames.stripSegmentName(name));
+ if (fileEntry == null) {
+ throw new FileNotFoundException("file " + name + " does not exists in this CFS");
+ }
- return new NestedCompoundFileDirectory(name, bufferSize, fileEntry.offset, fileEntry.length);
++ return new NestedCompoundFileDirectory(name, context, fileEntry.offset, fileEntry.length);
}
/** Not implemented
* @throws UnsupportedOperationException */
@Override
- public CompoundFileDirectory createCompoundOutput(String name)
+ public CompoundFileDirectory createCompoundOutput(String name, IOContext context)
throws IOException {
- // NOTE: final to make nested compounding impossible.
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("can not create nested CFS, create seperately and use Directory.copy instead");
}
-
- private final void initWriter() {
- assert openForWrite;
- assert entries == SENTINEL;
- if (writer == null) {
- writer = new CompoundFileWriter(directory, fileName);
+
+ private class NestedCompoundFileDirectory extends CompoundFileDirectory {
+
+ private final long cfsOffset;
+ private final long cfsLength;
+
- public NestedCompoundFileDirectory(String fileName, int readBufferSize, long offset, long length)
++ public NestedCompoundFileDirectory(String fileName, IOContext context, long offset, long length)
+ throws IOException {
- super(directory, fileName, readBufferSize);
++ super(directory, fileName, context);
+ this.cfsOffset = offset;
+ this.cfsLength = length;
+ IndexInput input = null;
+ try {
- input = CompoundFileDirectory.this.openInput(fileName, 128);
++ input = CompoundFileDirectory.this.openInput(fileName, IOContext.READONCE);
+ initForRead(CompoundFileDirectory.readEntries(input,
+ CompoundFileDirectory.this, fileName));
+ } finally {
+ IOUtils.closeSafely(false, input);
+ }
+ }
+
+ @Override
+ public IndexInput openInputSlice(String id, long offset, long length,
+ int readBufferSize) throws IOException {
+ assert offset + length <= cfsLength;
+ return CompoundFileDirectory.this.openInputSlice(id, cfsOffset + offset, length, readBufferSize);
}
+
}
-
+
}
diff --cc lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
index 7587a981310,19e1c77d04f..cd56d8fa7f6
--- a/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
+++ b/lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java
@@@ -135,10 -136,7 +136,7 @@@ final class CompoundFileWriter implemen
IOException priorException = null;
IndexOutput entryTableOut = null;
try {
- if (entries.isEmpty()) {
- throw new IllegalStateException("CFS has no entries");
- }
-
- initDataOut();
++ initDataOut(IOContext.DEFAULT);
if (!pendingEntries.isEmpty() || outputTaken.get()) {
throw new IllegalStateException("CFS has pending open files");
}
@@@ -147,7 -145,13 +145,13 @@@
assert dataOut != null;
long finalLength = dataOut.getFilePointer();
assert assertFileLength(finalLength, dataOut);
+ } catch (IOException e) {
+ priorException = e;
+ } finally {
+ IOUtils.closeSafely(priorException, dataOut);
+ }
+ try {
- entryTableOut = directory.createOutput(entryTableName);
+ entryTableOut = directory.createOutput(entryTableName, IOContext.DEFAULT);
writeEntryTable(entries.values(), entryTableOut);
} catch (IOException e) {
priorException = e;
diff --cc lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockCodec.java
index aa3c799c705,c533416f8c7..e665e82f02c
--- a/lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockCodec.java
+++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockCodec.java
@@@ -225,6 -224,6 +225,6 @@@ public class MockFixedIntBlockCodec ext
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), state.context);
}
}
diff --cc lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockCodec.java
index 3ba849ce75a,6bdac7e2e48..6d15b92cd43
--- a/lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockCodec.java
+++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockCodec.java
@@@ -46,9 -47,7 +47,8 @@@ import org.apache.lucene.index.codecs.B
import org.apache.lucene.index.codecs.BlockTermsWriter;
import org.apache.lucene.index.codecs.TermsIndexReaderBase;
import org.apache.lucene.index.codecs.TermsIndexWriterBase;
- import org.apache.lucene.index.codecs.standard.StandardCodec;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.util.BytesRef;
@@@ -248,6 -247,6 +248,6 @@@ public class MockVariableIntBlockCodec
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), state.context);
}
}
diff --cc lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.java
index d147694d60a,ac06feb79d4..c15865c7aa8
--- a/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.java
+++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.java
@@@ -386,6 -385,6 +386,6 @@@ public class MockRandomCodec extends Co
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), state.context);
}
}
diff --cc lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSepCodec.java
index 7454cab7b5c,75e3362512c..30cd3643657
--- a/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSepCodec.java
+++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSepCodec.java
@@@ -161,6 -161,6 +161,6 @@@ public class MockSepCodec extends Code
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), state.context);
}
}
diff --cc lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
index c7a592e89c7,f707f9c0353..cc465358750
--- a/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
+++ b/lucene/src/test-framework/org/apache/lucene/store/MockCompoundFileDirectoryWrapper.java
@@@ -145,7 -136,12 +136,14 @@@ public class MockCompoundFileDirectoryW
}
@Override
- public CompoundFileDirectory createCompoundOutput(String name) throws IOException {
- return delegate.createCompoundOutput(name);
+ public CompoundFileDirectory createCompoundOutput(String name, IOContext context) throws IOException {
+ return delegate.createCompoundOutput(name, context);
}
-
- public CompoundFileDirectory openCompoundInput(String name, int bufferSize) throws IOException {
- return delegate.openCompoundInput(name, bufferSize);
++
++ @Override
++ public CompoundFileDirectory openCompoundInput(String name, IOContext context)
++ throws IOException {
++ return delegate.openCompoundInput(name, context);
+ }
+
}
diff --cc lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
index 262a1a3d7e2,3eb59676d30..f6acb3b060f
--- a/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
+++ b/lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
@@@ -21,10 -21,8 +21,9 @@@ import java.io.IOException
import java.io.File;
import org.apache.lucene.util.LuceneTestCase;
- import junit.framework.TestSuite;
- import junit.textui.TestRunner;
import org.apache.lucene.store.CompoundFileDirectory;
++import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
@@@ -323,13 -304,13 +303,13 @@@ public class TestCompoundFile extends L
throws IOException
{
// Setup the test file - we need more than 1024 bytes
- IndexOutput os = fsdir.createOutput(file, newIOContext(random));
- IndexOutput os = fsdir.createOutput(file);
++ IndexOutput os = fsdir.createOutput(file, IOContext.DEFAULT);
for(int i=0; i<2000; i++) {
os.writeByte((byte) i);
}
os.close();
- IndexInput in = fsdir.openInput(file, newIOContext(random));
- IndexInput in = fsdir.openInput(file);
++ IndexInput in = fsdir.openInput(file, IOContext.DEFAULT);
// This read primes the buffer in IndexInput
in.readByte();
@@@ -717,5 -698,74 +697,74 @@@
cfr.close();
newDir.close();
}
+
+ public void testEmptyCFS() throws IOException {
+ Directory newDir = newDirectory();
- CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs");
++ CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs", newIOContext(random));
+ csw.close();
- CompoundFileDirectory csr = newDir.openCompoundInput("d.cfs", 1024);
++ CompoundFileDirectory csr = newDir.openCompoundInput("d.cfs", newIOContext(random));
+ assertEquals(0, csr.listAll().length);
+ csr.close();
+
+ newDir.close();
+ }
+
+ public void testReadNestedCFP() throws IOException {
+ Directory newDir = newDirectory();
- CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs");
- CompoundFileDirectory nested = newDir.createCompoundOutput("b.cfs");
- IndexOutput out = nested.createOutput("b.xyz");
- IndexOutput out1 = nested.createOutput("b_1.xyz");
++ CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs", newIOContext(random));
++ CompoundFileDirectory nested = newDir.createCompoundOutput("b.cfs", newIOContext(random));
++ IndexOutput out = nested.createOutput("b.xyz", newIOContext(random));
++ IndexOutput out1 = nested.createOutput("b_1.xyz", newIOContext(random));
+ out.writeInt(0);
+ out1.writeInt(1);
+ out.close();
+ out1.close();
+ nested.close();
- newDir.copy(csw, "b.cfs", "b.cfs");
- newDir.copy(csw, "b.cfe", "b.cfe");
++ newDir.copy(csw, "b.cfs", "b.cfs", newIOContext(random));
++ newDir.copy(csw, "b.cfe", "b.cfe", newIOContext(random));
+ newDir.deleteFile("b.cfs");
+ newDir.deleteFile("b.cfe");
+ csw.close();
+
+ assertEquals(2, newDir.listAll().length);
- csw = newDir.openCompoundInput("d.cfs", 1024);
++ csw = newDir.openCompoundInput("d.cfs", newIOContext(random));
+
+ assertEquals(2, csw.listAll().length);
- nested = csw.openCompoundInput("b.cfs", 1024);
++ nested = csw.openCompoundInput("b.cfs", newIOContext(random));
+
+ assertEquals(2, nested.listAll().length);
- IndexInput openInput = nested.openInput("b.xyz");
++ IndexInput openInput = nested.openInput("b.xyz", newIOContext(random));
+ assertEquals(0, openInput.readInt());
+ openInput.close();
- openInput = nested.openInput("b_1.xyz");
++ openInput = nested.openInput("b_1.xyz", newIOContext(random));
+ assertEquals(1, openInput.readInt());
+ openInput.close();
+ nested.close();
+ csw.close();
+ newDir.close();
+ }
+
+ public void testDoubleClose() throws IOException {
+ Directory newDir = newDirectory();
- CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs");
- IndexOutput out = csw.createOutput("d.xyz");
++ CompoundFileDirectory csw = newDir.createCompoundOutput("d.cfs", newIOContext(random));
++ IndexOutput out = csw.createOutput("d.xyz", newIOContext(random));
+ out.writeInt(0);
+ out.close();
+
+ csw.close();
+ // close a second time - must have no effect according to Closeable
+ csw.close();
+
- csw = newDir.openCompoundInput("d.cfs", 1024);
- IndexInput openInput = csw.openInput("d.xyz");
++ csw = newDir.openCompoundInput("d.cfs", newIOContext(random));
++ IndexInput openInput = csw.openInput("d.xyz", newIOContext(random));
+ assertEquals(0, openInput.readInt());
+ openInput.close();
+ csw.close();
+ // close a second time - must have no effect according to Closeable
+ csw.close();
+
+ newDir.close();
+
+ }
}
diff --cc lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java
index d1affdcedff,24413cb7f73..b568279d572
--- a/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java
+++ b/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java
@@@ -223,7 -224,7 +224,7 @@@ public class TestDocTermOrds extends Lu
@Override
public PerDocValues docsProducer(SegmentReadState state) throws IOException {
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context);
- return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator());
++ return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, getDocValuesUseCFS(), getDocValuesSortComparator(), state.context);
}
}
diff --cc lucene/src/test/org/apache/lucene/index/values/TestDocValues.java
index d4981aa3093,aed271eb080..2fc02a224b4
--- a/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java
+++ b/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java
@@@ -81,7 -81,7 +81,7 @@@ public class TestDocValues extends Luce
w.finish(maxDoc);
assertEquals(0, trackBytes.get());
- IndexDocValues r = Bytes.getValues(dir, "test", mode, fixedSize, maxDoc, newIOContext(random));
- IndexDocValues r = Bytes.getValues(dir, "test", mode, fixedSize, maxDoc, comp);
++ IndexDocValues r = Bytes.getValues(dir, "test", mode, fixedSize, maxDoc, comp, newIOContext(random));
for (int iter = 0; iter < 2; iter++) {
ValuesEnum bytesEnum = getEnum(r);
assertNotNull("enum is null", bytesEnum);