From e9937378c92134b0dd680df97bc1706799513f15 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 30 Jun 2011 16:03:28 +0000 Subject: [PATCH] LUCENE-2793: next iteration on IOContext git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/LUCENE2793@1141592 13f79535-47bb-0310-9956-ffa450edef68 --- .../codecs/appending/AppendingCodec.java | 5 +- .../AppendingSegmentInfosReader.java | 2 +- .../AppendingSegmentInfosWriter.java | 2 +- .../appending/AppendingTermsDictReader.java | 2 +- .../appending/AppendingTermsIndexReader.java | 6 +- .../lucene/store/DirectIOLinuxDirectory.java | 1 - .../lucene/store/NRTCachingDirectory.java | 2 - .../apache/lucene/store/WindowsDirectory.java | 1 - .../codecs/appending/TestAppendingCodec.java | 2 +- .../lucene/store/TestNRTCachingDirectory.java | 1 - .../lucene/index/BufferedDeletesStream.java | 4 +- .../org/apache/lucene/index/CheckIndex.java | 3 +- .../lucene/index/CompoundFileReader.java | 1 + .../lucene/index/CompoundFileWriter.java | 1 + .../apache/lucene/index/DirectoryReader.java | 2 +- .../index/DocumentsWriterPerThread.java | 6 +- .../org/apache/lucene/index/FieldInfos.java | 1 + .../org/apache/lucene/index/FieldsReader.java | 3 +- .../org/apache/lucene/index/FieldsWriter.java | 1 + .../org/apache/lucene/index/IndexReader.java | 1 - .../org/apache/lucene/index/IndexWriter.java | 19 +++-- .../org/apache/lucene/index/MergePolicy.java | 1 + .../org/apache/lucene/index/NormsWriter.java | 2 +- .../lucene/index/PerFieldCodecWrapper.java | 1 + .../lucene/index/SegmentCoreReaders.java | 1 + .../org/apache/lucene/index/SegmentInfo.java | 1 + .../org/apache/lucene/index/SegmentInfos.java | 2 +- .../apache/lucene/index/SegmentMerger.java | 19 +++-- .../org/apache/lucene/index/SegmentNorms.java | 8 +- .../apache/lucene/index/SegmentReadState.java | 1 + .../apache/lucene/index/SegmentReader.java | 1 + .../lucene/index/SegmentWriteState.java | 1 + .../lucene/index/StoredFieldsWriter.java | 11 ++- .../lucene/index/TermVectorsReader.java | 3 +- .../lucene/index/TermVectorsTermsWriter.java | 6 +- .../lucene/index/TermVectorsWriter.java | 1 + .../lucene/index/codecs/BlockTermsReader.java | 2 +- .../codecs/DefaultDocValuesConsumer.java | 3 +- .../codecs/DefaultDocValuesProducer.java | 32 ++++---- .../codecs/DefaultSegmentInfosReader.java | 3 +- .../codecs/DefaultSegmentInfosWriter.java | 3 +- .../codecs/FixedGapTermsIndexReader.java | 4 +- .../index/codecs/SegmentInfosReader.java | 2 +- .../index/codecs/SegmentInfosWriter.java | 2 +- .../codecs/VariableGapTermsIndexReader.java | 4 +- .../index/codecs/memory/MemoryCodec.java | 6 +- .../index/codecs/preflex/PreFlexFields.java | 2 +- .../index/codecs/preflex/TermInfosReader.java | 2 +- .../index/codecs/pulsing/PulsingCodec.java | 2 +- .../index/codecs/sep/IntStreamFactory.java | 5 +- .../codecs/sep/SepPostingsReaderImpl.java | 2 +- .../codecs/sep/SepPostingsWriterImpl.java | 6 +- .../codecs/simpletext/SimpleTextCodec.java | 2 +- .../index/codecs/standard/StandardCodec.java | 2 +- .../standard/StandardPostingsReader.java | 2 +- .../org/apache/lucene/index/values/Bytes.java | 32 ++++---- .../index/values/FixedDerefBytesImpl.java | 15 ++-- .../index/values/FixedSortedBytesImpl.java | 15 ++-- .../index/values/FixedStraightBytesImpl.java | 11 ++- .../apache/lucene/index/values/Floats.java | 22 +++-- .../org/apache/lucene/index/values/Ints.java | 11 ++- .../apache/lucene/index/values/IntsImpl.java | 2 +- .../index/values/VarDerefBytesImpl.java | 15 ++-- .../index/values/VarSortedBytesImpl.java | 15 ++-- .../index/values/VarStraightBytesImpl.java | 15 ++-- .../apache/lucene/index/values/Writer.java | 21 ++--- .../org/apache/lucene/store/Directory.java | 1 - .../org/apache/lucene/store/FSDirectory.java | 1 - .../lucene/store/FileSwitchDirectory.java | 1 - .../org/apache/lucene/store/FlushInfo.java | 45 +++++++++++ .../lucene/{index => store}/IOContext.java | 20 ++++- .../apache/lucene/store/MMapDirectory.java | 1 - .../lucene/{index => store}/MergeInfo.java | 18 ++++- .../apache/lucene/store/NIOFSDirectory.java | 1 - .../org/apache/lucene/store/RAMDirectory.java | 1 - .../lucene/store/SimpleFSDirectory.java | 1 - .../org/apache/lucene/util/BitVector.java | 4 +- .../mockintblock/MockFixedIntBlockCodec.java | 7 +- .../MockVariableIntBlockCodec.java | 8 +- .../codecs/mockrandom/MockRandomCodec.java | 8 +- .../index/codecs/mocksep/MockSepCodec.java | 2 +- .../codecs/mocksep/MockSingleIntFactory.java | 6 +- .../mocksep/MockSingleIntIndexInput.java | 2 +- .../mocksep/MockSingleIntIndexOutput.java | 7 +- .../codecs/preflexrw/TermInfosWriter.java | 2 +- .../lucene/store/MockDirectoryWrapper.java | 9 +-- .../apache/lucene/util/LuceneTestCase.java | 35 ++++++++ .../apache/lucene/index/TestAddIndexes.java | 7 +- .../index/TestBackwardsCompatibility.java | 5 +- .../org/apache/lucene/index/TestCodecs.java | 9 ++- .../apache/lucene/index/TestCompoundFile.java | 81 ++++++++++--------- .../test/org/apache/lucene/index/TestDoc.java | 11 ++- .../apache/lucene/index/TestDocTermOrds.java | 2 +- .../lucene/index/TestDocumentWriter.java | 11 +-- .../apache/lucene/index/TestFieldInfos.java | 3 +- .../apache/lucene/index/TestFieldsReader.java | 1 + .../lucene/index/TestIndexFileDeleter.java | 7 +- .../apache/lucene/index/TestIndexInput.java | 4 +- .../index/TestIndexReaderOnDiskFull.java | 2 +- .../apache/lucene/index/TestIndexWriter.java | 3 +- .../lucene/index/TestIndexWriterDelete.java | 2 +- .../index/TestIndexWriterExceptions.java | 15 ++-- .../index/TestIndexWriterOnDiskFull.java | 3 +- .../lucene/index/TestIndexWriterReader.java | 5 +- .../lucene/index/TestLazyProxSkipping.java | 1 + .../lucene/index/TestMultiLevelSkipList.java | 1 + .../apache/lucene/index/TestMultiReader.java | 6 +- .../lucene/index/TestSegmentMerger.java | 15 ++-- .../lucene/index/TestSegmentReader.java | 5 +- .../lucene/index/TestSegmentTermDocs.java | 7 +- .../index/TestSnapshotDeletionPolicy.java | 3 +- .../lucene/index/TestTermVectorsReader.java | 17 ++-- .../lucene/index/TestTermVectorsWriter.java | 2 +- .../codecs/intblock/TestIntBlockCodec.java | 9 +-- .../lucene/index/values/TestDocValues.java | 13 +-- .../apache/lucene/search/TestBoolean2.java | 2 +- .../lucene/store/TestBufferedIndexInput.java | 5 +- .../apache/lucene/store/TestCopyBytes.java | 47 ++++++----- .../apache/lucene/store/TestDirectory.java | 13 ++- .../apache/lucene/store/TestMultiMMap.java | 13 ++- .../apache/lucene/store/TestRAMDirectory.java | 13 ++- .../org/apache/lucene/util/TestBitVector.java | 16 ++-- .../org/apache/lucene/util/fst/TestFSTs.java | 10 ++- .../lucene/util/packed/TestPackedInts.java | 13 ++- .../apache/solr/core/RefCntRamDirectory.java | 2 +- 125 files changed, 529 insertions(+), 420 deletions(-) create mode 100644 lucene/src/java/org/apache/lucene/store/FlushInfo.java rename lucene/src/java/org/apache/lucene/{index => store}/IOContext.java (80%) rename lucene/src/java/org/apache/lucene/{index => store}/MergeInfo.java (75%) diff --git 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 index 2d1617bea4c..57915da0675 100644 --- 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 @@ -99,13 +99,12 @@ public class AppendingCodec extends Codec { boolean success = false; try { - //nocommit we should pass the IOContext down to the TermIndexReader indexReader = new AppendingTermsIndexReader(state.dir, state.fieldInfos, state.segmentInfo.name, state.termsIndexDivisor, BytesRef.getUTF8SortedAsUnicodeComparator(), - state.codecId); + state.codecId, state.context); success = true; } finally { if (!success) { @@ -155,6 +154,6 @@ public class AppendingCodec extends Codec { @Override public PerDocValues docsProducer(SegmentReadState state) throws IOException { - return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context); } } diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingSegmentInfosReader.java b/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingSegmentInfosReader.java index 65217972232..aac8be1707d 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingSegmentInfosReader.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingSegmentInfosReader.java @@ -20,9 +20,9 @@ package org.apache.lucene.index.codecs.appending; import java.io.IOException; import org.apache.lucene.index.CorruptIndexException; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.codecs.DefaultSegmentInfosReader; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; public class AppendingSegmentInfosReader extends DefaultSegmentInfosReader { diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingSegmentInfosWriter.java b/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingSegmentInfosWriter.java index 0a6ee864cbe..2850037ab53 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingSegmentInfosWriter.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingSegmentInfosWriter.java @@ -19,9 +19,9 @@ package org.apache.lucene.index.codecs.appending; import java.io.IOException; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.codecs.DefaultSegmentInfosWriter; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; public class AppendingSegmentInfosWriter extends DefaultSegmentInfosWriter { diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictReader.java b/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictReader.java index 9c10ddaf91e..7f885eeace7 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictReader.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictReader.java @@ -20,12 +20,12 @@ package org.apache.lucene.index.codecs.appending; import java.io.IOException; import org.apache.lucene.index.FieldInfos; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.codecs.PostingsReaderBase; import org.apache.lucene.index.codecs.BlockTermsReader; import org.apache.lucene.index.codecs.BlockTermsWriter; import org.apache.lucene.index.codecs.TermsIndexReaderBase; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.CodecUtil; diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexReader.java b/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexReader.java index 20ecbe7f7bf..205dc154fba 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexReader.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexReader.java @@ -21,9 +21,9 @@ import java.io.IOException; import java.util.Comparator; import org.apache.lucene.index.FieldInfos; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.codecs.FixedGapTermsIndexReader; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CodecUtil; @@ -31,9 +31,9 @@ import org.apache.lucene.util.CodecUtil; public class AppendingTermsIndexReader extends FixedGapTermsIndexReader { public AppendingTermsIndexReader(Directory dir, FieldInfos fieldInfos, - String segment, int indexDivisor, Comparator termComp, int codecId) + String segment, int indexDivisor, Comparator termComp, int codecId, IOContext context) throws IOException { - super(dir, fieldInfos, segment, indexDivisor, termComp, codecId, IOContext.DEFAULT); + super(dir, fieldInfos, segment, indexDivisor, termComp, codecId, context); } @Override diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java b/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java index 9f3bc1d10a3..8d7a5f2c41f 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java @@ -25,7 +25,6 @@ import java.io.FileOutputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import org.apache.lucene.index.IOContext; import org.apache.lucene.store.Directory; // javadoc import org.apache.lucene.store.NativeFSLockFactory; // javadoc diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java b/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java index feee0121598..e36fbb9f516 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java @@ -24,10 +24,8 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.apache.lucene.index.ConcurrentMergeScheduler; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.IndexWriter; // javadocs -import org.apache.lucene.index.MergeInfo; import org.apache.lucene.index.MergePolicy; import org.apache.lucene.index.MergeScheduler; import org.apache.lucene.store.RAMDirectory; // javadocs diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java b/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java index 1f34755422e..03d0b9b2b57 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java @@ -20,7 +20,6 @@ package org.apache.lucene.store; import java.io.File; import java.io.IOException; -import org.apache.lucene.index.IOContext; import org.apache.lucene.store.Directory; // javadoc import org.apache.lucene.store.NativeFSLockFactory; // javadoc diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/index/codecs/appending/TestAppendingCodec.java b/lucene/contrib/misc/src/test/org/apache/lucene/index/codecs/appending/TestAppendingCodec.java index d127685089b..c0738fc67d4 100644 --- a/lucene/contrib/misc/src/test/org/apache/lucene/index/codecs/appending/TestAppendingCodec.java +++ b/lucene/contrib/misc/src/test/org/apache/lucene/index/codecs/appending/TestAppendingCodec.java @@ -27,7 +27,6 @@ import org.apache.lucene.document.Field.Store; import org.apache.lucene.document.Field.TermVector; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.Fields; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; @@ -41,6 +40,7 @@ import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.index.codecs.SegmentInfosReader; import org.apache.lucene.index.codecs.SegmentInfosWriter; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.RAMDirectory; diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java b/lucene/contrib/misc/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java index 48a7162b91f..ed27e1c43d9 100644 --- a/lucene/contrib/misc/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java +++ b/lucene/contrib/misc/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java @@ -24,7 +24,6 @@ import java.util.List; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; diff --git a/lucene/src/java/org/apache/lucene/index/BufferedDeletesStream.java b/lucene/src/java/org/apache/lucene/index/BufferedDeletesStream.java index 800fad98321..98da68b6b27 100644 --- a/lucene/src/java/org/apache/lucene/index/BufferedDeletesStream.java +++ b/lucene/src/java/org/apache/lucene/index/BufferedDeletesStream.java @@ -32,6 +32,7 @@ import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Query; import org.apache.lucene.search.QueryWrapperFilter; +import org.apache.lucene.store.IOContext; /* Tracks the stream of {@link BufferedDeletes}. * When DocumentsWriterPerThread flushes, its buffered @@ -224,8 +225,7 @@ class BufferedDeletesStream { // Lock order: IW -> BD -> RP assert readerPool.infoIsLive(info); - //nocommit is IOContext.DEFAULT the right thing to do here? - final SegmentReader reader = readerPool.get(info, false, IOContext.DEFAULT); + final SegmentReader reader = readerPool.get(info, false, IOContext.READ); int delCount = 0; final boolean segAllDeletes; try { diff --git a/lucene/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/src/java/org/apache/lucene/index/CheckIndex.java index f037ce730f1..de1ade56183 100644 --- a/lucene/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/src/java/org/apache/lucene/index/CheckIndex.java @@ -22,11 +22,10 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.document.AbstractField; // for javadocs import org.apache.lucene.document.Document; -import org.apache.lucene.index.IOContext.Context; -import org.apache.lucene.index.MergePolicy.OneMerge; import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.index.codecs.DefaultSegmentInfosWriter; import org.apache.lucene.index.codecs.PerDocValues; diff --git a/lucene/src/java/org/apache/lucene/index/CompoundFileReader.java b/lucene/src/java/org/apache/lucene/index/CompoundFileReader.java index 1af43b19887..12fb5b3d8bb 100644 --- a/lucene/src/java/org/apache/lucene/index/CompoundFileReader.java +++ b/lucene/src/java/org/apache/lucene/index/CompoundFileReader.java @@ -18,6 +18,7 @@ package org.apache.lucene.index; */ import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.BufferedIndexInput; import org.apache.lucene.store.IndexOutput; diff --git a/lucene/src/java/org/apache/lucene/index/CompoundFileWriter.java b/lucene/src/java/org/apache/lucene/index/CompoundFileWriter.java index 451bb4a1629..095091111e6 100644 --- a/lucene/src/java/org/apache/lucene/index/CompoundFileWriter.java +++ b/lucene/src/java/org/apache/lucene/index/CompoundFileWriter.java @@ -23,6 +23,7 @@ import java.util.LinkedList; import org.apache.lucene.index.codecs.MergeState; 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.IOUtils; diff --git a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java index 7b3132d24ce..00e53068c18 100644 --- a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java +++ b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java @@ -32,9 +32,9 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldSelector; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.Lock; import org.apache.lucene.store.LockObtainFailedException; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.util.Bits; diff --git a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java index 2a12b2f812f..c6f28b7c57e 100644 --- a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java +++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java @@ -28,9 +28,11 @@ import java.util.concurrent.atomic.AtomicLong; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.DocumentsWriterDeleteQueue.DeleteSlice; -import org.apache.lucene.index.IOContext.Context; 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; @@ -429,7 +431,7 @@ public class DocumentsWriterPerThread { assert deleteSlice == null : "all deletes must be applied in prepareFlush"; flushState = new SegmentWriteState(infoStream, directory, segment, fieldInfos, numDocsInRAM, writer.getConfig().getTermIndexInterval(), - fieldInfos.buildSegmentCodecs(true), pendingDeletes, new IOContext(Context.FLUSH)); + fieldInfos.buildSegmentCodecs(true), pendingDeletes, new IOContext(new FlushInfo(numDocsInRAM, bytesUsed()))); final double startMBUsed = parent.flushControl.netBytes() / 1024. / 1024.; // Apply delete-by-docID now (delete-byDocID only // happens when an exception is hit processing that diff --git a/lucene/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/src/java/org/apache/lucene/index/FieldInfos.java index b98af343468..b7e6cd6fd3d 100644 --- a/lucene/src/java/org/apache/lucene/index/FieldInfos.java +++ b/lucene/src/java/org/apache/lucene/index/FieldInfos.java @@ -33,6 +33,7 @@ import org.apache.lucene.index.SegmentCodecs.SegmentCodecsBuilder; import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.index.values.ValueType; 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.CodecUtil; diff --git a/lucene/src/java/org/apache/lucene/index/FieldsReader.java b/lucene/src/java/org/apache/lucene/index/FieldsReader.java index 01348af0c87..359356f1dd0 100644 --- a/lucene/src/java/org/apache/lucene/index/FieldsReader.java +++ b/lucene/src/java/org/apache/lucene/index/FieldsReader.java @@ -25,11 +25,10 @@ import org.apache.lucene.document.FieldSelector; import org.apache.lucene.document.FieldSelectorResult; import org.apache.lucene.document.Fieldable; import org.apache.lucene.document.NumericField; -import org.apache.lucene.index.IOContext.Context; -import org.apache.lucene.index.MergePolicy.OneMerge; 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; diff --git a/lucene/src/java/org/apache/lucene/index/FieldsWriter.java b/lucene/src/java/org/apache/lucene/index/FieldsWriter.java index 649aa54571b..e44cfd13834 100644 --- a/lucene/src/java/org/apache/lucene/index/FieldsWriter.java +++ b/lucene/src/java/org/apache/lucene/index/FieldsWriter.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Fieldable; import org.apache.lucene.document.NumericField; 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.IOUtils; diff --git a/lucene/src/java/org/apache/lucene/index/IndexReader.java b/lucene/src/java/org/apache/lucene/index/IndexReader.java index eacfd083112..fa876265fdf 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexReader.java +++ b/lucene/src/java/org/apache/lucene/index/IndexReader.java @@ -21,7 +21,6 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldSelector; import org.apache.lucene.search.FieldCache; // javadocs import org.apache.lucene.search.Similarity; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.index.codecs.PerDocValues; diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.java index aca12e5ac40..4d235830d50 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java @@ -39,9 +39,7 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.DocumentsWriterPerThread.FlushedSegment; import org.apache.lucene.index.FieldInfos.FieldNumberBiMap; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.index.IndexWriterConfig.OpenMode; -import org.apache.lucene.index.MergePolicy.OneMerge; import org.apache.lucene.index.PayloadProcessorProvider.DirPayloadProcessor; import org.apache.lucene.index.SegmentCodecs.SegmentCodecsBuilder; import org.apache.lucene.index.codecs.CodecProvider; @@ -49,8 +47,12 @@ import org.apache.lucene.search.Query; import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.BufferedIndexInput; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FlushInfo; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.Lock; import org.apache.lucene.store.LockObtainFailedException; +import org.apache.lucene.store.MergeInfo; +import org.apache.lucene.store.IOContext.Context; import org.apache.lucene.util.BitVector; import org.apache.lucene.util.Bits; import org.apache.lucene.util.Constants; @@ -2188,7 +2190,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { setDiagnostics(newSegment, "flush"); - IOContext context = new IOContext(Context.FLUSH); + IOContext context = new IOContext(new FlushInfo(newSegment.docCount, newSegment.sizeInBytes(true))); boolean success = false; try { @@ -2447,6 +2449,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { */ public void addIndexes(IndexReader... readers) throws CorruptIndexException, IOException { ensureOpen(); + int numDocs = 0; try { if (infoStream != null) @@ -2454,11 +2457,16 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { flush(false, true); String mergedName = newSegmentName(); + for (IndexReader indexReader : readers) { + numDocs += indexReader.numDocs(); + } + final IOContext context = new IOContext(new MergeInfo(numDocs, -1, true, false)); + // TODO: somehow we should fix this merge so it's // abortable so that IW.close(false) is able to stop it SegmentMerger merger = new SegmentMerger(directory, config.getTermIndexInterval(), mergedName, null, payloadProcessorProvider, - globalFieldNumberMap.newFieldInfos(SegmentCodecsBuilder.create(codecs))); + globalFieldNumberMap.newFieldInfos(SegmentCodecsBuilder.create(codecs)), context); for (IndexReader reader : readers) // add new indexes merger.add(reader); @@ -2483,7 +2491,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { // Now create the compound file if needed if (useCompoundFile) { - IOContext context = new IOContext(new MergeInfo(info.docCount, info.sizeInBytes(true), true, false)); merger.createCompoundFile(mergedName + ".cfs", info, context); // delete new non cfs files directly: they were never @@ -3429,7 +3436,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { IOContext context = new IOContext(merge.getMergeInfo()); SegmentMerger merger = new SegmentMerger(directory, config.getTermIndexInterval(), mergedName, merge, - payloadProcessorProvider, merge.info.getFieldInfos()); + payloadProcessorProvider, merge.info.getFieldInfos(), context); if (infoStream != null) { message("merging " + merge.segString(directory) + " mergeVectors=" + merge.info.getFieldInfos().hasVectors()); diff --git a/lucene/src/java/org/apache/lucene/index/MergePolicy.java b/lucene/src/java/org/apache/lucene/index/MergePolicy.java index a6c5bf83128..7298ecd3e1c 100644 --- a/lucene/src/java/org/apache/lucene/index/MergePolicy.java +++ b/lucene/src/java/org/apache/lucene/index/MergePolicy.java @@ -18,6 +18,7 @@ package org.apache.lucene.index; */ import org.apache.lucene.store.Directory; +import org.apache.lucene.store.MergeInfo; import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.SetOnce.AlreadySetException; diff --git a/lucene/src/java/org/apache/lucene/index/NormsWriter.java b/lucene/src/java/org/apache/lucene/index/NormsWriter.java index 41ed5c75afa..e4353829f01 100644 --- a/lucene/src/java/org/apache/lucene/index/NormsWriter.java +++ b/lucene/src/java/org/apache/lucene/index/NormsWriter.java @@ -21,8 +21,8 @@ import java.io.IOException; import java.util.Collection; import java.util.Map; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.store.IndexOutput; +import org.apache.lucene.store.IOContext.Context; import org.apache.lucene.util.IOUtils; // TODO FI: norms could actually be stored as doc store diff --git a/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java b/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java index 6e52d4f90da..78cf40a15c8 100644 --- a/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java +++ b/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java @@ -36,6 +36,7 @@ import org.apache.lucene.index.codecs.TermsConsumer; import org.apache.lucene.index.codecs.DocValuesConsumer; import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.util.IOUtils; /** diff --git a/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java b/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java index 68b81771fd2..e2437a97f61 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java @@ -24,6 +24,7 @@ import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.FieldsProducer; import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; /** Holds core readers that are shared (unchanged) when * SegmentReader is cloned or reopened */ diff --git a/lucene/src/java/org/apache/lucene/index/SegmentInfo.java b/lucene/src/java/org/apache/lucene/index/SegmentInfo.java index c5a572faca7..f924e6b3329 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentInfo.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentInfo.java @@ -31,6 +31,7 @@ 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.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; diff --git a/lucene/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/src/java/org/apache/lucene/index/SegmentInfos.java index 02f329724d3..26e71cf06f6 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentInfos.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentInfos.java @@ -32,12 +32,12 @@ import java.util.Map; import java.util.Set; import org.apache.lucene.index.FieldInfos.FieldNumberBiMap; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.index.codecs.DefaultSegmentInfosWriter; import org.apache.lucene.index.codecs.SegmentInfosReader; import org.apache.lucene.index.codecs.SegmentInfosWriter; 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.store.NoSuchDirectoryException; diff --git a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java index 7ae6094bc01..396e024026a 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java @@ -24,7 +24,6 @@ import java.util.Collection; import java.util.List; import org.apache.lucene.document.Document; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.index.IndexReader.FieldOption; import org.apache.lucene.index.MergePolicy.MergeAbortedException; import org.apache.lucene.index.codecs.Codec; @@ -33,6 +32,7 @@ import org.apache.lucene.index.codecs.MergeState; import org.apache.lucene.index.codecs.PerDocConsumer; import org.apache.lucene.index.codecs.PerDocValues; 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.Bits; @@ -68,8 +68,10 @@ final class SegmentMerger { private SegmentWriteState segmentWriteState; private PayloadProcessorProvider payloadProcessorProvider; + + private IOContext context; - SegmentMerger(Directory dir, int termIndexInterval, String name, MergePolicy.OneMerge merge, PayloadProcessorProvider payloadProcessorProvider, FieldInfos fieldInfos) { + SegmentMerger(Directory dir, int termIndexInterval, String name, MergePolicy.OneMerge merge, PayloadProcessorProvider payloadProcessorProvider, FieldInfos fieldInfos, IOContext context) { this.payloadProcessorProvider = payloadProcessorProvider; directory = dir; segment = name; @@ -85,6 +87,7 @@ final class SegmentMerger { }; } this.termIndexInterval = termIndexInterval; + this.context = context; } public FieldInfos fieldInfos() { @@ -234,8 +237,7 @@ final class SegmentMerger { setMatchingSegmentReaders(); // nocommit - should we rather use IOContext.MERGE here? - final FieldsWriter fieldsWriter = new FieldsWriter(directory, segment, IOContext.DEFAULT); - + final FieldsWriter fieldsWriter = new FieldsWriter(directory, segment, context); try { int idx = 0; for (IndexReader reader : readers) { @@ -269,8 +271,7 @@ final class SegmentMerger { // entering the index. See LUCENE-1282 for // details. throw new RuntimeException("mergeFields produced an invalid result: docCount is " + docCount + " but fdx file size is " + fdxFileLength + " file=" + fileName + " file exists?=" + directory.fileExists(fileName) + "; now aborting this merge to prevent index corruption"); - //nocommit if Merge then what to initialize OneMerge with ? - segmentWriteState = new SegmentWriteState(null, directory, segment, fieldInfos, docCount, termIndexInterval, codecInfo, null, IOContext.DEFAULT); + segmentWriteState = new SegmentWriteState(null, directory, segment, fieldInfos, docCount, termIndexInterval, codecInfo, null, context); return docCount; } @@ -355,9 +356,8 @@ final class SegmentMerger { * @throws IOException */ private final void mergeVectors() throws IOException { - //nocommit Putting MERGE context here would lead to assert error. What should MergeInfo be initialized with here? TermVectorsWriter termVectorsWriter = - new TermVectorsWriter(directory, segment, fieldInfos, new IOContext(Context.DEFAULT)); + new TermVectorsWriter(directory, segment, fieldInfos, context); try { int idx = 0; @@ -616,8 +616,7 @@ final class SegmentMerger { for (FieldInfo fi : fieldInfos) { if (fi.isIndexed && !fi.omitNorms) { if (output == null) { - //nocommit Putting MERGE context here would lead to assert error. What should MergeInfo be initialized with here? - output = directory.createOutput(IndexFileNames.segmentFileName(segment, "", IndexFileNames.NORMS_EXTENSION), new IOContext(Context.DEFAULT)); + output = directory.createOutput(IndexFileNames.segmentFileName(segment, "", IndexFileNames.NORMS_EXTENSION), context); output.writeBytes(SegmentNorms.NORMS_HEADER, SegmentNorms.NORMS_HEADER.length); } for (IndexReader reader : readers) { diff --git a/lucene/src/java/org/apache/lucene/index/SegmentNorms.java b/lucene/src/java/org/apache/lucene/index/SegmentNorms.java index 6c88ffaebe8..08e98072fce 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentNorms.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentNorms.java @@ -20,11 +20,10 @@ package org.apache.lucene.index; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.lucene.index.IOContext.Context; -import org.apache.lucene.index.MergePolicy.OneMerge; +import org.apache.lucene.store.FlushInfo; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexOutput; - /** * Byte[] referencing is used because a new norm object needs * to be created for each clone, and the byte array is all @@ -221,7 +220,8 @@ final class SegmentNorms implements Cloneable { // NOTE: norms are re-written in regular directory, not cfs si.advanceNormGen(this.number); final String normFileName = si.getNormFileName(this.number); - IndexOutput out = owner.directory().createOutput(normFileName, IOContext.DEFAULT); + //nocommit not sure if this is the correct information provided to FlushInfo + IndexOutput out = owner.directory().createOutput(normFileName, new IOContext(new FlushInfo(si.docCount, 0))); boolean success = false; try { try { diff --git a/lucene/src/java/org/apache/lucene/index/SegmentReadState.java b/lucene/src/java/org/apache/lucene/index/SegmentReadState.java index b72dc80b42c..e7e717f4450 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentReadState.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentReadState.java @@ -18,6 +18,7 @@ package org.apache.lucene.index; */ import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; /** * @lucene.experimental diff --git a/lucene/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/src/java/org/apache/lucene/index/SegmentReader.java index f5d36d97b00..967d4dff32a 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentReader.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentReader.java @@ -31,6 +31,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldSelector; import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.BitVector; import org.apache.lucene.util.Bits; diff --git a/lucene/src/java/org/apache/lucene/index/SegmentWriteState.java b/lucene/src/java/org/apache/lucene/index/SegmentWriteState.java index 25573c62c9e..f3b8ff67819 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentWriteState.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentWriteState.java @@ -20,6 +20,7 @@ package org.apache.lucene.index; import java.io.PrintStream; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.util.BitVector; /** diff --git a/lucene/src/java/org/apache/lucene/index/StoredFieldsWriter.java b/lucene/src/java/org/apache/lucene/index/StoredFieldsWriter.java index ee51d535886..de441d25d77 100644 --- a/lucene/src/java/org/apache/lucene/index/StoredFieldsWriter.java +++ b/lucene/src/java/org/apache/lucene/index/StoredFieldsWriter.java @@ -20,7 +20,7 @@ package org.apache.lucene.index; import java.io.IOException; import org.apache.lucene.document.Fieldable; -import org.apache.lucene.index.IOContext.Context; +import org.apache.lucene.store.IOContext; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.RamUsageEstimator; @@ -60,7 +60,7 @@ final class StoredFieldsWriter { // It's possible that all documents seen in this segment // hit non-aborting exceptions, in which case we will // not have yet init'd the FieldsWriter: - initFieldsWriter(); + initFieldsWriter(state.context); fill(state.numDocs); } @@ -76,10 +76,9 @@ final class StoredFieldsWriter { } } - private synchronized void initFieldsWriter() throws IOException { + private synchronized void initFieldsWriter(IOContext context) throws IOException { if (fieldsWriter == null) { - // nocommit - is this always a flush here or should we have a IOContext argument? - fieldsWriter = new FieldsWriter(docWriter.directory, docWriter.getSegment(), new IOContext(Context.FLUSH)); + fieldsWriter = new FieldsWriter(docWriter.directory, docWriter.getSegment(), context); lastDocID = 0; } } @@ -109,7 +108,7 @@ final class StoredFieldsWriter { void finishDocument() throws IOException { assert docWriter.writer.testPoint("StoredFieldsWriter.finishDocument start"); - initFieldsWriter(); + initFieldsWriter(IOContext.DEFAULT); fill(docState.docID); if (fieldsWriter != null && numStoredFields > 0) { diff --git a/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java b/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java index bd8e9128290..ca9b628cb0e 100644 --- a/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java +++ b/lucene/src/java/org/apache/lucene/index/TermVectorsReader.java @@ -17,11 +17,12 @@ package org.apache.lucene.index; * limitations under the License. */ -import org.apache.lucene.index.IOContext.Context; 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; diff --git a/lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java b/lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java index e6042910cd1..686c355a476 100644 --- a/lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java +++ b/lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java @@ -20,8 +20,10 @@ package org.apache.lucene.index; import java.io.IOException; import java.util.Map; -import org.apache.lucene.index.IOContext.Context; +import org.apache.lucene.store.FlushInfo; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; +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; @@ -90,7 +92,7 @@ final class TermVectorsTermsWriter extends TermsHashConsumer { if (tvx == null) { boolean success = false; try { - IOContext context = new IOContext(Context.FLUSH); + IOContext context = new IOContext(new FlushInfo(docWriter.getNumDocsInRAM(), docWriter.bytesUsed())); // If we hit an exception while init'ing the term // vector output files, we must abort this segment // because those files will be in an unknown diff --git a/lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java b/lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java index 1bc34b94521..f94365a7e83 100644 --- a/lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java +++ b/lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java @@ -18,6 +18,7 @@ package org.apache.lucene.index; */ import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsReader.java b/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsReader.java index 592539b4ec9..8eba4477476 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsReader.java @@ -29,7 +29,6 @@ import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.FieldsEnum; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.TermState; @@ -38,6 +37,7 @@ import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.codecs.standard.StandardPostingsReader; // javadocs import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.Bits; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesConsumer.java index 9edadc467df..f5c3a741dd2 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesConsumer.java @@ -29,6 +29,7 @@ import org.apache.lucene.index.PerDocWriteState; 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; public class DefaultDocValuesConsumer extends PerDocConsumer { @@ -55,7 +56,7 @@ public class DefaultDocValuesConsumer extends PerDocConsumer { docValuesId(segmentName, codecId, field.number), // TODO can we have a compound file per segment and codec for // docvalues? - directory, comparator, bytesUsed); + directory, comparator, bytesUsed, IOContext.DEFAULT); } @SuppressWarnings("fallthrough") diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java b/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java index 7c6091aacdc..8755bb6f364 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java @@ -22,7 +22,6 @@ import java.util.TreeMap; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.values.Bytes; import org.apache.lucene.index.values.IndexDocValues; @@ -30,6 +29,7 @@ import org.apache.lucene.index.values.Floats; 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; /** * Abstract base class for FieldsProducer implementations supporting @@ -57,9 +57,8 @@ public class DefaultDocValuesProducer extends PerDocValues { * if an {@link IOException} occurs */ public DefaultDocValuesProducer(SegmentInfo si, Directory dir, - FieldInfos fieldInfo, int codecId) throws IOException { - //nocommit this needs an IOContext - docValues = load(fieldInfo, si.name, si.docCount, dir, codecId); + FieldInfos fieldInfo, int codecId, IOContext context) throws IOException { + docValues = load(fieldInfo, si.name, si.docCount, dir, codecId, context); } /** @@ -73,7 +72,7 @@ public class DefaultDocValuesProducer extends PerDocValues { // Only opens files... doesn't actually load any values protected TreeMap load(FieldInfos fieldInfos, - String segment, int docCount, Directory dir, int codecId) + String segment, int docCount, Directory dir, int codecId, IOContext context) throws IOException { TreeMap values = new TreeMap(); boolean success = false; @@ -87,7 +86,7 @@ public class DefaultDocValuesProducer extends PerDocValues { final String id = DefaultDocValuesConsumer.docValuesId(segment, codecId, fieldInfo.number); values.put(field, - loadDocValues(docCount, dir, id, fieldInfo.getDocValues())); + loadDocValues(docCount, dir, id, fieldInfo.getDocValues(), context)); } } success = true; @@ -121,27 +120,26 @@ public class DefaultDocValuesProducer extends PerDocValues { * if the given {@link ValueType} is not supported */ protected IndexDocValues loadDocValues(int docCount, Directory dir, String id, - ValueType type) throws IOException { - // nocommit this needs an IOContext too + ValueType type, IOContext context) throws IOException { switch (type) { case INTS: - return Ints.getValues(dir, id, false); + return Ints.getValues(dir, id, false, 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); + return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, true, docCount, context); case BYTES_FIXED_DEREF: - return Bytes.getValues(dir, id, Bytes.Mode.DEREF, true, docCount); + return Bytes.getValues(dir, id, Bytes.Mode.DEREF, true, docCount, context); case BYTES_FIXED_SORTED: - return Bytes.getValues(dir, id, Bytes.Mode.SORTED, true, docCount); + return Bytes.getValues(dir, id, Bytes.Mode.SORTED, true, docCount, context); case BYTES_VAR_STRAIGHT: - return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, false, docCount); + return Bytes.getValues(dir, id, Bytes.Mode.STRAIGHT, false, docCount, context); case BYTES_VAR_DEREF: - return Bytes.getValues(dir, id, Bytes.Mode.DEREF, false, docCount); + return Bytes.getValues(dir, id, Bytes.Mode.DEREF, false, docCount, context); case BYTES_VAR_SORTED: - return Bytes.getValues(dir, id, Bytes.Mode.SORTED, false, docCount); + return Bytes.getValues(dir, id, Bytes.Mode.SORTED, false, docCount, context); default: throw new IllegalStateException("unrecognized index values mode " + type); } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java b/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java index 6a5eb120c9d..efa8e9a166a 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java @@ -22,15 +22,14 @@ import java.io.IOException; import org.apache.lucene.index.CompoundFileReader; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.FieldsReader; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.IndexFormatTooOldException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentInfos; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.store.ChecksumIndexInput; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; /** diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java b/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java index dca66bd94ec..8242d44594f 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java @@ -19,12 +19,11 @@ package org.apache.lucene.index.codecs; import java.io.IOException; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentInfos; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.store.ChecksumIndexOutput; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.util.IOUtils; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java b/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java index fa2fefacad7..fa2880c3db7 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java @@ -18,11 +18,11 @@ package org.apache.lucene.index.codecs; */ 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.index.FieldInfos; import org.apache.lucene.index.FieldInfo; -import org.apache.lucene.index.IOContext; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CodecUtil; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/SegmentInfosReader.java b/lucene/src/java/org/apache/lucene/index/codecs/SegmentInfosReader.java index 6abd7f6b4a1..69b680473d3 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/SegmentInfosReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/SegmentInfosReader.java @@ -19,9 +19,9 @@ package org.apache.lucene.index.codecs; import java.io.IOException; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.SegmentInfos; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; /** * Specifies an API for classes that can read {@link SegmentInfos} information. diff --git a/lucene/src/java/org/apache/lucene/index/codecs/SegmentInfosWriter.java b/lucene/src/java/org/apache/lucene/index/codecs/SegmentInfosWriter.java index 84b2248aaa4..42a3d8182b3 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/SegmentInfosWriter.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/SegmentInfosWriter.java @@ -19,9 +19,9 @@ package org.apache.lucene.index.codecs; import java.io.IOException; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.SegmentInfos; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; /** diff --git a/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexReader.java b/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexReader.java index 065fe4f7e8b..0befc752163 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexReader.java @@ -27,12 +27,12 @@ import java.util.Iterator; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; -import org.apache.lucene.index.IOContext; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentInfo; 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.BytesRef; import org.apache.lucene.util.CodecUtil; import org.apache.lucene.util.fst.Builder; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryCodec.java b/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryCodec.java index 48594ca1aa0..729529aaa9b 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryCodec.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryCodec.java @@ -48,6 +48,7 @@ import org.apache.lucene.index.codecs.TermStats; import org.apache.lucene.index.codecs.TermsConsumer; import org.apache.lucene.store.ByteArrayDataInput; 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.store.RAMOutputStream; @@ -697,9 +698,8 @@ public class MemoryCodec extends Codec { @Override public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException { - //nocommit its seems due to the nature of this codec that we should use IOContext.READONCE here where applicable. final String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.codecId, EXTENSION); - final IndexInput in = state.dir.openInput(fileName, state.context); + final IndexInput in = state.dir.openInput(fileName, IOContext.READONCE); final SortedMap fields = new TreeMap(); @@ -776,6 +776,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); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, IOContext.READONCE); } } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java b/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java index 7d5f0ee4db6..61f67bb110c 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/preflex/PreFlexFields.java @@ -31,7 +31,6 @@ import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.FieldsEnum; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.Term; @@ -39,6 +38,7 @@ import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.codecs.FieldsProducer; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java b/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java index 34f2f62e816..8dfd1de7da6 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java @@ -21,10 +21,10 @@ import java.io.IOException; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.FieldInfos; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.Term; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.util.CloseableThreadLocal; import org.apache.lucene.util.DoubleBarrelLRUCache; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java b/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java index 157e8c6c448..e5c5283992b 100644 --- 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 +173,6 @@ public class PulsingCodec extends Codec { @Override public PerDocValues docsProducer(SegmentReadState state) throws IOException { - return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context); } } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/IntStreamFactory.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/IntStreamFactory.java index 2bf3c5f4330..2d110591dbb 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/sep/IntStreamFactory.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/IntStreamFactory.java @@ -17,9 +17,8 @@ package org.apache.lucene.index.codecs.sep; * limitations under the License. */ -import org.apache.lucene.index.IOContext; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.BufferedIndexInput; +import org.apache.lucene.store.IOContext; import java.io.IOException; @@ -30,5 +29,5 @@ public abstract class IntStreamFactory { } // public abstract IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException; - public abstract IntIndexOutput createOutput(Directory dir, String fileName) throws IOException; + public abstract IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java index 82ec9467e0f..befe9dd1c40 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java @@ -23,7 +23,6 @@ import java.util.Collection; import org.apache.lucene.index.DocsAndPositionsEnum; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.FieldInfo; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.TermState; @@ -31,6 +30,7 @@ import org.apache.lucene.index.codecs.BlockTermState; import org.apache.lucene.index.codecs.PostingsReaderBase; import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.Bits; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java index 637b88f33c3..5ede6515c88 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java @@ -118,16 +118,16 @@ public final class SepPostingsWriterImpl extends PostingsWriterBase { this.skipInterval = skipInterval; this.skipMinimum = skipInterval; /* set to the same for now */ final String docFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, DOC_EXTENSION); - docOut = factory.createOutput(state.directory, docFileName); + docOut = factory.createOutput(state.directory, docFileName, state.context); docIndex = docOut.index(); if (state.fieldInfos.hasProx()) { final String frqFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, FREQ_EXTENSION); - freqOut = factory.createOutput(state.directory, frqFileName); + freqOut = factory.createOutput(state.directory, frqFileName, state.context); freqIndex = freqOut.index(); final String posFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, POS_EXTENSION); - posOut = factory.createOutput(state.directory, posFileName); + posOut = factory.createOutput(state.directory, posFileName, state.context); posIndex = posOut.index(); // TODO: -- only if at least one field stores payloads? diff --git a/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextCodec.java b/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextCodec.java index 612b70d1333..832b7e3bb20 100644 --- 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 @@ public class SimpleTextCodec extends Codec { @Override public PerDocValues docsProducer(SegmentReadState state) throws IOException { - return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context); } } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardCodec.java b/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardCodec.java index 10014389dd3..47def928931 100644 --- 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 +163,6 @@ public class StandardCodec extends Codec { @Override public PerDocValues docsProducer(SegmentReadState state) throws IOException { - return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context); } } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardPostingsReader.java b/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardPostingsReader.java index 5e1d5296677..b1c9449f85d 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardPostingsReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardPostingsReader.java @@ -23,7 +23,6 @@ import java.util.Collection; import org.apache.lucene.index.DocsAndPositionsEnum; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.FieldInfo; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.TermState; @@ -31,6 +30,7 @@ import org.apache.lucene.index.codecs.BlockTermState; import org.apache.lucene.index.codecs.PostingsReaderBase; import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.Bits; diff --git a/lucene/src/java/org/apache/lucene/index/values/Bytes.java b/lucene/src/java/org/apache/lucene/index/values/Bytes.java index 8742b0c6900..a7d80fcce26 100644 --- a/lucene/src/java/org/apache/lucene/index/values/Bytes.java +++ b/lucene/src/java/org/apache/lucene/index/values/Bytes.java @@ -23,12 +23,12 @@ import java.util.Collection; import java.util.Comparator; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.values.IndexDocValues.SortedSource; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.index.values.IndexDocValues.SourceEnum; 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.AttributeSource; @@ -107,9 +107,8 @@ public final class Bytes { * if the files for the writer can not be created. */ public static Writer getWriter(Directory dir, String id, Mode mode, - Comparator comp, boolean fixedSize, AtomicLong bytesUsed) + Comparator comp, boolean fixedSize, AtomicLong bytesUsed, IOContext context) throws IOException { - //nocommit this and all the blow need an IOContext too // TODO -- i shouldn't have to specify fixed? can // track itself & do the write thing at write time? @@ -119,19 +118,19 @@ public final class Bytes { if (fixedSize) { if (mode == Mode.STRAIGHT) { - return new FixedStraightBytesImpl.Writer(dir, id); + return new FixedStraightBytesImpl.Writer(dir, id, context); } else if (mode == Mode.DEREF) { - return new FixedDerefBytesImpl.Writer(dir, id, bytesUsed); + return new FixedDerefBytesImpl.Writer(dir, id, bytesUsed, context); } else if (mode == Mode.SORTED) { - return new FixedSortedBytesImpl.Writer(dir, id, comp, bytesUsed); + return new FixedSortedBytesImpl.Writer(dir, id, comp, bytesUsed, context); } } else { if (mode == Mode.STRAIGHT) { - return new VarStraightBytesImpl.Writer(dir, id, bytesUsed); + return new VarStraightBytesImpl.Writer(dir, id, bytesUsed, context); } else if (mode == Mode.DEREF) { - return new VarDerefBytesImpl.Writer(dir, id, bytesUsed); + return new VarDerefBytesImpl.Writer(dir, id, bytesUsed, context); } else if (mode == Mode.SORTED) { - return new VarSortedBytesImpl.Writer(dir, id, comp, bytesUsed); + return new VarSortedBytesImpl.Writer(dir, id, comp, bytesUsed, context); } } @@ -160,25 +159,24 @@ public final class Bytes { * if an {@link IOException} occurs */ public static IndexDocValues getValues(Directory dir, String id, Mode mode, - boolean fixedSize, int maxDoc) throws IOException { - //nocommit this and all the readers below need an IOContext too + boolean fixedSize, int maxDoc, IOContext context) throws IOException { // TODO -- I can peek @ header to determing fixed/mode? if (fixedSize) { if (mode == Mode.STRAIGHT) { - return new FixedStraightBytesImpl.Reader(dir, id, maxDoc); + return new FixedStraightBytesImpl.Reader(dir, id, maxDoc, context); } else if (mode == Mode.DEREF) { - return new FixedDerefBytesImpl.Reader(dir, id, maxDoc); + return new FixedDerefBytesImpl.Reader(dir, id, maxDoc, context); } else if (mode == Mode.SORTED) { - return new FixedSortedBytesImpl.Reader(dir, id, maxDoc); + return new FixedSortedBytesImpl.Reader(dir, id, maxDoc, context); } } 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); + return new VarSortedBytesImpl.Reader(dir, id, maxDoc, context); } } diff --git a/lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java index d6de9a053e6..fe7addc67a6 100644 --- a/lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java @@ -20,11 +20,11 @@ package org.apache.lucene.index.values; import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.values.Bytes.BytesBaseSource; import org.apache.lucene.index.values.Bytes.BytesReaderBase; import org.apache.lucene.index.values.Bytes.BytesWriterBase; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.AttributeSource; @@ -55,17 +55,16 @@ class FixedDerefBytesImpl { private final BytesRefHash hash = new BytesRefHash(pool, BytesRefHash.DEFAULT_CAPACITY, new TrackingDirectBytesStartArray( BytesRefHash.DEFAULT_CAPACITY, bytesUsed)); - public Writer(Directory dir, String id, AtomicLong bytesUsed) + public Writer(Directory dir, String id, AtomicLong bytesUsed, IOContext context) throws IOException { - //nocommit this needs an IOContext too this(dir, id, new DirectTrackingAllocator(ByteBlockPool.BYTE_BLOCK_SIZE, bytesUsed), - bytesUsed); + bytesUsed, context); } public Writer(Directory dir, String id, Allocator allocator, - AtomicLong bytesUsed) throws IOException { + AtomicLong bytesUsed, IOContext context) throws IOException { super(dir, id, CODEC_NAME, VERSION_CURRENT, true, - new ByteBlockPool(allocator), bytesUsed, IOContext.DEFAULT); + new ByteBlockPool(allocator), bytesUsed, context); docToID = new int[1]; bytesUsed.addAndGet(RamUsageEstimator.NUM_BYTES_INT); // TODO BytesRefHash // uses bytes too! @@ -135,8 +134,8 @@ class FixedDerefBytesImpl { public static class Reader extends BytesReaderBase { private final int size; - Reader(Directory dir, String id, int maxDoc) throws IOException { - super(dir, id, CODEC_NAME, VERSION_START, true, IOContext.DEFAULT); + Reader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { + super(dir, id, CODEC_NAME, VERSION_START, true, context); size = datIn.readInt(); } diff --git a/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java index e53536caf4e..294eb7ce224 100644 --- a/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java @@ -21,12 +21,12 @@ import java.io.IOException; import java.util.Comparator; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.values.Bytes.BytesBaseSortedSource; import org.apache.lucene.index.values.Bytes.BytesReaderBase; import org.apache.lucene.index.values.Bytes.BytesWriterBase; import org.apache.lucene.index.values.FixedDerefBytesImpl.Reader.DerefBytesEnum; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.AttributeSource; @@ -63,16 +63,15 @@ class FixedSortedBytesImpl { BytesRefHash.DEFAULT_CAPACITY, bytesUsed)); public Writer(Directory dir, String id, Comparator comp, - AtomicLong bytesUsed) throws IOException { - //nocommit this needs an IOContext too + AtomicLong bytesUsed, IOContext context) throws IOException { this(dir, id, comp, new DirectTrackingAllocator(ByteBlockPool.BYTE_BLOCK_SIZE, bytesUsed), - bytesUsed); + bytesUsed, context); } public Writer(Directory dir, String id, Comparator comp, - Allocator allocator, AtomicLong bytesUsed) throws IOException { + Allocator allocator, AtomicLong bytesUsed, IOContext context) throws IOException { super(dir, id, CODEC_NAME, VERSION_CURRENT, true, - new ByteBlockPool(allocator), bytesUsed, IOContext.DEFAULT); + new ByteBlockPool(allocator), bytesUsed, context); docToEntry = new int[1]; // docToEntry[0] = -1; bytesUsed.addAndGet(RamUsageEstimator.NUM_BYTES_INT); @@ -162,8 +161,8 @@ class FixedSortedBytesImpl { public static class Reader extends BytesReaderBase { private final int size; - public Reader(Directory dir, String id, int maxDoc) throws IOException { - super(dir, id, CODEC_NAME, VERSION_START, true, IOContext.DEFAULT); + public Reader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { + super(dir, id, CODEC_NAME, VERSION_START, true, context); size = datIn.readInt(); } diff --git a/lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java index be5b342f863..53e1d4d7726 100644 --- a/lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java @@ -19,11 +19,11 @@ package org.apache.lucene.index.values; import java.io.IOException; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.values.Bytes.BytesBaseSource; import org.apache.lucene.index.values.Bytes.BytesReaderBase; import org.apache.lucene.index.values.Bytes.BytesWriterBase; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.AttributeSource; import org.apache.lucene.util.BytesRef; @@ -47,9 +47,8 @@ class FixedStraightBytesImpl { private int lastDocID = -1; private byte[] oneRecord; - public Writer(Directory dir, String id) throws IOException { - //nocommit this needs an IOContext too - super(dir, id, CODEC_NAME, VERSION_CURRENT, false, null, null, IOContext.DEFAULT); + public Writer(Directory dir, String id, IOContext context) throws IOException { + super(dir, id, CODEC_NAME, VERSION_CURRENT, false, null, null, context); } @@ -127,8 +126,8 @@ class FixedStraightBytesImpl { private final int size; private final int maxDoc; - Reader(Directory dir, String id, int maxDoc) throws IOException { - super(dir, id, CODEC_NAME, VERSION_START, false, IOContext.DEFAULT); + Reader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { + super(dir, id, CODEC_NAME, VERSION_START, false, context); size = datIn.readInt(); this.maxDoc = maxDoc; } diff --git a/lucene/src/java/org/apache/lucene/index/values/Floats.java b/lucene/src/java/org/apache/lucene/index/values/Floats.java index 5f2f9743931..b55ea70011c 100644 --- a/lucene/src/java/org/apache/lucene/index/values/Floats.java +++ b/lucene/src/java/org/apache/lucene/index/values/Floats.java @@ -20,11 +20,10 @@ import java.io.IOException; import java.util.Collection; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.values.IndexDocValues.Source; 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.AttributeSource; @@ -53,22 +52,21 @@ public class Floats { public static Writer getWriter(Directory dir, String id, int precisionBytes, - AtomicLong bytesUsed) throws IOException { + AtomicLong bytesUsed, IOContext context) throws IOException { if (precisionBytes != 4 && precisionBytes != 8) { throw new IllegalArgumentException("precisionBytes must be 4 or 8; got " + precisionBytes); } if (precisionBytes == 4) { - return new Float4Writer(dir, id, bytesUsed); + return new Float4Writer(dir, id, bytesUsed, context); } else { - return new Float8Writer(dir, id, bytesUsed); + return new Float8Writer(dir, id, bytesUsed, context); } } - public static IndexDocValues getValues(Directory dir, String id, int maxDoc) + public static IndexDocValues getValues(Directory dir, String id, int maxDoc, IOContext context) throws IOException { - //nocommit this needs an IOContext too - return new FloatsReader(dir, id, maxDoc, IOContext.READ); + return new FloatsReader(dir, id, maxDoc, context); } abstract static class FloatsWriter extends Writer { @@ -147,9 +145,9 @@ public class Floats { // Writes 4 bytes (float) per value static class Float4Writer extends FloatsWriter { - protected Float4Writer(Directory dir, String id, AtomicLong bytesUsed) + protected Float4Writer(Directory dir, String id, AtomicLong bytesUsed, IOContext context) throws IOException { - super(dir, id, 4, bytesUsed, new IOContext(Context.FLUSH)); + super(dir, id, 4, bytesUsed, context); } @Override @@ -190,9 +188,9 @@ public class Floats { // Writes 8 bytes (double) per value static class Float8Writer extends FloatsWriter { - protected Float8Writer(Directory dir, String id, AtomicLong bytesUsed) + protected Float8Writer(Directory dir, String id, AtomicLong bytesUsed, IOContext context) throws IOException { - super(dir, id, 8, bytesUsed, new IOContext(Context.FLUSH)); + super(dir, id, 8, bytesUsed, context); } @Override diff --git a/lucene/src/java/org/apache/lucene/index/values/Ints.java b/lucene/src/java/org/apache/lucene/index/values/Ints.java index 7f81fc7d301..ec802f265d7 100644 --- a/lucene/src/java/org/apache/lucene/index/values/Ints.java +++ b/lucene/src/java/org/apache/lucene/index/values/Ints.java @@ -20,10 +20,10 @@ package org.apache.lucene.index.values; import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.values.IntsImpl.IntsReader; import org.apache.lucene.index.values.IntsImpl.IntsWriter; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; /** * @lucene.experimental @@ -35,14 +35,13 @@ public class Ints { } public static Writer getWriter(Directory dir, String id, - boolean useFixedArray, AtomicLong bytesUsed) throws IOException { + boolean useFixedArray, AtomicLong bytesUsed, IOContext context) throws IOException { // TODO - implement fixed?! - return new IntsWriter(dir, id, bytesUsed, IOContext.DEFAULT); + return new IntsWriter(dir, id, bytesUsed, context); } public static IndexDocValues getValues(Directory dir, String id, - boolean useFixedArray) throws IOException { - //nocommit this needs an IOContext too - return new IntsReader(dir, id, IOContext.DEFAULT); + boolean useFixedArray, IOContext context) throws IOException { + return new IntsReader(dir, id, context); } } diff --git a/lucene/src/java/org/apache/lucene/index/values/IntsImpl.java b/lucene/src/java/org/apache/lucene/index/values/IntsImpl.java index 9660a62c704..5a67c22873f 100644 --- a/lucene/src/java/org/apache/lucene/index/values/IntsImpl.java +++ b/lucene/src/java/org/apache/lucene/index/values/IntsImpl.java @@ -20,9 +20,9 @@ import java.io.IOException; import java.util.Collection; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; 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.ArrayUtil; diff --git a/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java index 696ca01367a..76ca1146620 100644 --- a/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java @@ -20,13 +20,13 @@ package org.apache.lucene.index.values; import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.values.Bytes.BytesBaseSource; import org.apache.lucene.index.values.Bytes.BytesReaderBase; import org.apache.lucene.index.values.Bytes.BytesWriterBase; import org.apache.lucene.index.values.FixedDerefBytesImpl.Reader.DerefBytesEnum; import org.apache.lucene.store.DataOutput; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.AttributeSource; @@ -116,17 +116,16 @@ class VarDerefBytesImpl { bytesUsed); private final BytesRefHash hash = new BytesRefHash(pool, 16, array); - public Writer(Directory dir, String id, AtomicLong bytesUsed) + public Writer(Directory dir, String id, AtomicLong bytesUsed, IOContext context) throws IOException { - //nocommit this needs an IOContext too this(dir, id, new DirectTrackingAllocator(ByteBlockPool.BYTE_BLOCK_SIZE, bytesUsed), - bytesUsed); + bytesUsed, context); } public Writer(Directory dir, String id, Allocator allocator, - AtomicLong bytesUsed) throws IOException { + AtomicLong bytesUsed, IOContext context) throws IOException { super(dir, id, CODEC_NAME, VERSION_CURRENT, true, - new ByteBlockPool(allocator), bytesUsed, IOContext.DEFAULT); + new ByteBlockPool(allocator), bytesUsed, context); docToAddress = new int[1]; bytesUsed.addAndGet(RamUsageEstimator.NUM_BYTES_INT); } @@ -203,8 +202,8 @@ class VarDerefBytesImpl { public static class Reader extends BytesReaderBase { - Reader(Directory dir, String id, int maxDoc) throws IOException { - super(dir, id, CODEC_NAME, VERSION_START, true, IOContext.DEFAULT); + Reader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { + super(dir, id, CODEC_NAME, VERSION_START, true, context); } @Override diff --git a/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java index e0cfd26b504..cbbbb0d3781 100644 --- a/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java @@ -22,11 +22,11 @@ import java.util.Arrays; import java.util.Comparator; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.values.Bytes.BytesBaseSortedSource; import org.apache.lucene.index.values.Bytes.BytesReaderBase; import org.apache.lucene.index.values.Bytes.BytesWriterBase; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.AttributeSource; @@ -62,16 +62,15 @@ class VarSortedBytesImpl { BytesRefHash.DEFAULT_CAPACITY, bytesUsed)); public Writer(Directory dir, String id, Comparator comp, - AtomicLong bytesUsed) throws IOException { - //nocommit this needs an IOContext too + AtomicLong bytesUsed, IOContext context) throws IOException { this(dir, id, comp, new DirectTrackingAllocator(ByteBlockPool.BYTE_BLOCK_SIZE, bytesUsed), - bytesUsed); + bytesUsed, context); } public Writer(Directory dir, String id, Comparator comp, - Allocator allocator, AtomicLong bytesUsed) throws IOException { + Allocator allocator, AtomicLong bytesUsed, IOContext context) throws IOException { super(dir, id, CODEC_NAME, VERSION_CURRENT, true, - new ByteBlockPool(allocator), bytesUsed, IOContext.DEFAULT); + new ByteBlockPool(allocator), bytesUsed, context); this.comp = comp; docToEntry = new int[1]; docToEntry[0] = -1; @@ -158,8 +157,8 @@ class VarSortedBytesImpl { public static class Reader extends BytesReaderBase { - Reader(Directory dir, String id, int maxDoc) throws IOException { - super(dir, id, CODEC_NAME, VERSION_START, true, IOContext.DEFAULT); + Reader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { + super(dir, id, CODEC_NAME, VERSION_START, true, context); } @Override diff --git a/lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java b/lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java index 82def807ede..3cd8f3576cf 100644 --- a/lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java @@ -20,11 +20,11 @@ package org.apache.lucene.index.values; import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.values.Bytes.BytesBaseSource; import org.apache.lucene.index.values.Bytes.BytesReaderBase; import org.apache.lucene.index.values.Bytes.BytesWriterBase; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.AttributeSource; @@ -50,16 +50,15 @@ class VarStraightBytesImpl { private int lastDocID = -1; private long[] docToAddress; - public Writer(Directory dir, String id, AtomicLong bytesUsed) + public Writer(Directory dir, String id, AtomicLong bytesUsed, IOContext context) throws IOException { - //nocommit this needs an IOContext too - super(dir, id, CODEC_NAME, VERSION_CURRENT, true, null, bytesUsed, IOContext.DEFAULT); + super(dir, id, CODEC_NAME, VERSION_CURRENT, true, null, bytesUsed, context); docToAddress = new long[1]; bytesUsed.addAndGet(RamUsageEstimator.NUM_BYTES_INT); } - public Writer(Directory dir, String id) throws IOException { - this(dir, id, new AtomicLong()); + public Writer(Directory dir, String id, IOContext context) throws IOException { + this(dir, id, new AtomicLong(), context); } // Fills up to but not including this docID @@ -123,8 +122,8 @@ class VarStraightBytesImpl { public static class Reader extends BytesReaderBase { private final int maxDoc; - Reader(Directory dir, String id, int maxDoc) throws IOException { - super(dir, id, CODEC_NAME, VERSION_START, true, IOContext.DEFAULT); + Reader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { + super(dir, id, CODEC_NAME, VERSION_START, true, context); this.maxDoc = maxDoc; } diff --git a/lucene/src/java/org/apache/lucene/index/values/Writer.java b/lucene/src/java/org/apache/lucene/index/values/Writer.java index e3444545773..ab5dbab603d 100644 --- a/lucene/src/java/org/apache/lucene/index/values/Writer.java +++ b/lucene/src/java/org/apache/lucene/index/values/Writer.java @@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicLong; import org.apache.lucene.index.codecs.DocValuesConsumer; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; @@ -192,35 +193,35 @@ public abstract class Writer extends DocValuesConsumer { * @throws IOException */ public static Writer create(ValueType type, String id, Directory directory, - Comparator comp, AtomicLong bytesUsed) throws IOException { + Comparator comp, AtomicLong bytesUsed, IOContext context) throws IOException { if (comp == null) { comp = BytesRef.getUTF8SortedAsUnicodeComparator(); } switch (type) { case INTS: - return Ints.getWriter(directory, id, true, bytesUsed); + return Ints.getWriter(directory, id, true, bytesUsed, context); case FLOAT_32: - return Floats.getWriter(directory, id, 4, bytesUsed); + return Floats.getWriter(directory, id, 4, bytesUsed, context); case FLOAT_64: - return Floats.getWriter(directory, id, 8, bytesUsed); + return Floats.getWriter(directory, id, 8, bytesUsed, context); case BYTES_FIXED_STRAIGHT: return Bytes.getWriter(directory, id, Bytes.Mode.STRAIGHT, comp, true, - bytesUsed); + bytesUsed, context); case BYTES_FIXED_DEREF: return Bytes.getWriter(directory, id, Bytes.Mode.DEREF, comp, true, - bytesUsed); + bytesUsed, context); case BYTES_FIXED_SORTED: return Bytes.getWriter(directory, id, Bytes.Mode.SORTED, comp, true, - bytesUsed); + bytesUsed, context); case BYTES_VAR_STRAIGHT: return Bytes.getWriter(directory, id, Bytes.Mode.STRAIGHT, comp, false, - bytesUsed); + bytesUsed, context); case BYTES_VAR_DEREF: return Bytes.getWriter(directory, id, Bytes.Mode.DEREF, comp, false, - bytesUsed); + bytesUsed, context); case BYTES_VAR_SORTED: return Bytes.getWriter(directory, id, Bytes.Mode.SORTED, comp, false, - bytesUsed); + bytesUsed, context); default: throw new IllegalArgumentException("Unknown Values: " + type); } diff --git a/lucene/src/java/org/apache/lucene/store/Directory.java b/lucene/src/java/org/apache/lucene/store/Directory.java index c30aa26286d..51862e91659 100644 --- a/lucene/src/java/org/apache/lucene/store/Directory.java +++ b/lucene/src/java/org/apache/lucene/store/Directory.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.Closeable; import java.util.Collection; // for javadocs -import org.apache.lucene.index.IOContext; import org.apache.lucene.util.IOUtils; /** A Directory is a flat list of files. Files may be written once, when they diff --git a/lucene/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/src/java/org/apache/lucene/store/FSDirectory.java index 2b1178c8965..e3a36b57708 100644 --- a/lucene/src/java/org/apache/lucene/store/FSDirectory.java +++ b/lucene/src/java/org/apache/lucene/store/FSDirectory.java @@ -29,7 +29,6 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.Future; -import org.apache.lucene.index.IOContext; import org.apache.lucene.util.ThreadInterruptedException; import org.apache.lucene.util.Constants; diff --git a/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java b/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java index dcd9162c4a2..51676a77aa0 100644 --- a/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java +++ b/lucene/src/java/org/apache/lucene/store/FileSwitchDirectory.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Set; import java.util.HashSet; -import org.apache.lucene.index.IOContext; /** * Expert: A Directory instance that switches files between diff --git a/lucene/src/java/org/apache/lucene/store/FlushInfo.java b/lucene/src/java/org/apache/lucene/store/FlushInfo.java new file mode 100644 index 00000000000..e40a68cfdf2 --- /dev/null +++ b/lucene/src/java/org/apache/lucene/store/FlushInfo.java @@ -0,0 +1,45 @@ +package org.apache.lucene.store; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + *

A FlushInfo provides information required for a FLUSH context and other optimization operations. + * It is used as part of an {@link IOContext} in case of FLUSH context.

+ */ + + +public class FlushInfo { + + public final int numDocs; + + public final long estimatedSegmentSize; + + /** + *

Creates a new {@link FlushInfo} instance from + * the values required for a FLUSH {@link IOContext} context. + * + * These values are only estimates and are not the actual values. + * + */ + + public FlushInfo(int numDocs, long estimatedSegmentSize) { + this.numDocs = numDocs; + this.estimatedSegmentSize = estimatedSegmentSize; + } + +} diff --git a/lucene/src/java/org/apache/lucene/index/IOContext.java b/lucene/src/java/org/apache/lucene/store/IOContext.java similarity index 80% rename from lucene/src/java/org/apache/lucene/index/IOContext.java rename to lucene/src/java/org/apache/lucene/store/IOContext.java index 5e5127d8517..bfff4483576 100644 --- a/lucene/src/java/org/apache/lucene/index/IOContext.java +++ b/lucene/src/java/org/apache/lucene/store/IOContext.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index; +package org.apache.lucene.store; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -37,6 +37,8 @@ public class IOContext { public final MergeInfo mergeInfo; + public final FlushInfo flushInfo; + public final boolean readOnce; public static final IOContext DEFAULT = new IOContext(Context.DEFAULT); @@ -49,14 +51,23 @@ public class IOContext { this(false); } - public IOContext(Context context) { + public IOContext (FlushInfo flushInfo) { + assert flushInfo != null; + this.context = Context.FLUSH; + this.mergeInfo = null; + this.readOnce = false; + this.flushInfo = flushInfo; + } + + public IOContext (Context context) { this(context, null); } - private IOContext(boolean readOnce) { + private IOContext (boolean readOnce) { this.context = Context.READ; this.mergeInfo = null; this.readOnce = readOnce; + this.flushInfo = null; } public IOContext (MergeInfo mergeInfo) { @@ -64,10 +75,11 @@ public class IOContext { } private IOContext (Context context, MergeInfo mergeInfo ) { - assert context != Context.MERGE || mergeInfo != null; + assert context != Context.MERGE || context != Context.FLUSH || mergeInfo != null; this.context = context; this.readOnce = false; this.mergeInfo = mergeInfo; + this.flushInfo = null; } } \ No newline at end of file diff --git a/lucene/src/java/org/apache/lucene/store/MMapDirectory.java b/lucene/src/java/org/apache/lucene/store/MMapDirectory.java index 3c18d44e3a5..6439b22fa01 100644 --- a/lucene/src/java/org/apache/lucene/store/MMapDirectory.java +++ b/lucene/src/java/org/apache/lucene/store/MMapDirectory.java @@ -31,7 +31,6 @@ import java.security.PrivilegedExceptionAction; import java.security.PrivilegedActionException; import java.lang.reflect.Method; -import org.apache.lucene.index.IOContext; import org.apache.lucene.util.Constants; /** File-based {@link Directory} implementation that uses diff --git a/lucene/src/java/org/apache/lucene/index/MergeInfo.java b/lucene/src/java/org/apache/lucene/store/MergeInfo.java similarity index 75% rename from lucene/src/java/org/apache/lucene/index/MergeInfo.java rename to lucene/src/java/org/apache/lucene/store/MergeInfo.java index 208eeb41f94..b4137ce95a9 100644 --- a/lucene/src/java/org/apache/lucene/index/MergeInfo.java +++ b/lucene/src/java/org/apache/lucene/store/MergeInfo.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index; +package org.apache.lucene.store; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -15,7 +15,12 @@ package org.apache.lucene.index; * See the License for the specific language governing permissions and * limitations under the License. */ -//nocommit javadoc + +/** + *

A MergeInfo provides information required for a MERGE context and other optimization operations. + * It is used as part of an {@link IOContext} in case of MERGE context.

+ */ + public class MergeInfo { public int totalDocCount; @@ -25,6 +30,15 @@ public class MergeInfo { boolean isExternal; // used by IndexWriter boolean optimize; // used by IndexWriter + + + /** + *

Creates a new {@link MergeInfo} instance from + * the values required for a MERGE {@link IOContext} context. + * + * These values are only estimates and are not the actual values. + * + */ public MergeInfo(int totalDocCount, long estimatedMergeBytes, boolean isExternal, boolean optimize) { this.totalDocCount = totalDocCount; diff --git a/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java b/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java index d128f27e4e3..6a2ff16c645 100644 --- a/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java +++ b/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java @@ -23,7 +23,6 @@ import java.nio.ByteBuffer; import java.nio.channels.ClosedChannelException; // javadoc @link import java.nio.channels.FileChannel; import java.util.concurrent.Future; // javadoc -import org.apache.lucene.index.IOContext; /** * An {@link FSDirectory} implementation that uses java.nio's FileChannel's diff --git a/lucene/src/java/org/apache/lucene/store/RAMDirectory.java b/lucene/src/java/org/apache/lucene/store/RAMDirectory.java index ae6b85a891b..0e0cc184a0c 100644 --- a/lucene/src/java/org/apache/lucene/store/RAMDirectory.java +++ b/lucene/src/java/org/apache/lucene/store/RAMDirectory.java @@ -27,7 +27,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; -import org.apache.lucene.index.IOContext; /** * A memory-resident {@link Directory} implementation. Locking diff --git a/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java b/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java index d466ec38d0f..3afa7138db9 100644 --- a/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java +++ b/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; -import org.apache.lucene.index.IOContext; /** A straightforward implementation of {@link FSDirectory} * using java.io.RandomAccessFile. However, this class has diff --git a/lucene/src/java/org/apache/lucene/util/BitVector.java b/lucene/src/java/org/apache/lucene/util/BitVector.java index f182c9fc4c2..b24a64962ff 100644 --- a/lucene/src/java/org/apache/lucene/util/BitVector.java +++ b/lucene/src/java/org/apache/lucene/util/BitVector.java @@ -19,12 +19,12 @@ package org.apache.lucene.util; import java.io.IOException; -import org.apache.lucene.index.IOContext; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.index.MergePolicy.OneMerge; 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.store.IOContext.Context; /** Optimized implementation of a vector of bits. This is more-or-less like java.util.BitSet, but also includes the following: diff --git 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 index c8c9db24e42..aa3c799c705 100644 --- 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 @@ -20,7 +20,6 @@ package org.apache.lucene.index.codecs.mockintblock; import java.io.IOException; import java.util.Set; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentWriteState; @@ -103,8 +102,8 @@ public class MockFixedIntBlockCodec extends Codec { } @Override - public IntIndexOutput createOutput(Directory dir, String fileName) throws IOException { - IndexOutput out = dir.createOutput(fileName, IOContext.DEFAULT); + public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException { + IndexOutput out = dir.createOutput(fileName, context); boolean success = false; try { FixedIntBlockIndexOutput ret = new FixedIntBlockIndexOutput(out, blockSize) { @@ -226,6 +225,6 @@ public class MockFixedIntBlockCodec extends Codec { @Override public PerDocValues docsProducer(SegmentReadState state) throws IOException { - return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context); } } diff --git 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 index f4ba2f2b341..3ba849ce75a 100644 --- 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 @@ -20,7 +20,6 @@ package org.apache.lucene.index.codecs.mockintblock; import java.io.IOException; import java.util.Set; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentWriteState; @@ -49,6 +48,7 @@ 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; @@ -107,8 +107,8 @@ public class MockVariableIntBlockCodec extends Codec { } @Override - public IntIndexOutput createOutput(Directory dir, String fileName) throws IOException { - final IndexOutput out = dir.createOutput(fileName, IOContext.DEFAULT); + public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException { + final IndexOutput out = dir.createOutput(fileName, context); boolean success = false; try { out.writeInt(baseBlockSize); @@ -248,6 +248,6 @@ public class MockVariableIntBlockCodec extends Codec { @Override public PerDocValues docsProducer(SegmentReadState state) throws IOException { - return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context); } } diff --git 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 index 76a06827a57..d147694d60a 100644 --- 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 @@ -25,7 +25,6 @@ import java.util.Random; import java.util.Set; import org.apache.lucene.index.FieldInfo; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; @@ -62,6 +61,7 @@ import org.apache.lucene.index.codecs.sep.SepPostingsWriterImpl; import org.apache.lucene.index.codecs.standard.StandardPostingsReader; import org.apache.lucene.index.codecs.standard.StandardPostingsWriter; 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; @@ -115,12 +115,12 @@ public class MockRandomCodec extends Codec { } @Override - public IntIndexOutput createOutput(Directory dir, String fileName) throws IOException { + public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException { final IntStreamFactory f = delegates.get((Math.abs(salt ^ getExtension(fileName).hashCode())) % delegates.size()); if (LuceneTestCase.VERBOSE) { System.out.println("MockRandomCodec: write using int factory " + f + " to fileName=" + fileName); } - return f.createOutput(dir, fileName); + return f.createOutput(dir, fileName, context); } } @@ -386,6 +386,6 @@ public class MockRandomCodec extends Codec { @Override public PerDocValues docsProducer(SegmentReadState state) throws IOException { - return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context); } } diff --git 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 index d2f4b413a2c..7454cab7b5c 100644 --- 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 @@ public class MockSepCodec extends Codec { @Override public PerDocValues docsProducer(SegmentReadState state) throws IOException { - return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context); } } diff --git a/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntFactory.java b/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntFactory.java index debc21741ff..6dce24af773 100644 --- a/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntFactory.java +++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntFactory.java @@ -18,7 +18,7 @@ package org.apache.lucene.index.codecs.mocksep; */ import org.apache.lucene.store.Directory; -import org.apache.lucene.index.IOContext; +import org.apache.lucene.store.IOContext; import org.apache.lucene.index.codecs.sep.IntStreamFactory; import org.apache.lucene.index.codecs.sep.IntIndexInput; import org.apache.lucene.index.codecs.sep.IntIndexOutput; @@ -32,7 +32,7 @@ public class MockSingleIntFactory extends IntStreamFactory { return new MockSingleIntIndexInput(dir, fileName, context); } @Override - public IntIndexOutput createOutput(Directory dir, String fileName) throws IOException { - return new MockSingleIntIndexOutput(dir, fileName); + public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException { + return new MockSingleIntIndexOutput(dir, fileName, context); } } diff --git a/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexInput.java b/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexInput.java index 933da1861cc..df34e468280 100644 --- a/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexInput.java +++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexInput.java @@ -19,10 +19,10 @@ package org.apache.lucene.index.codecs.mocksep; import java.io.IOException; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.codecs.sep.IntIndexInput; import org.apache.lucene.store.DataInput; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.CodecUtil; diff --git a/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.java b/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.java index a40fa5fde6c..7830b786a57 100644 --- a/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.java +++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.java @@ -17,11 +17,11 @@ package org.apache.lucene.index.codecs.mocksep; * limitations under the License. */ +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.Directory; import org.apache.lucene.util.CodecUtil; import org.apache.lucene.util.IOUtils; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.codecs.sep.IntIndexOutput; import java.io.IOException; @@ -36,9 +36,8 @@ public class MockSingleIntIndexOutput extends IntIndexOutput { final static int VERSION_START = 0; final static int VERSION_CURRENT = VERSION_START; - public MockSingleIntIndexOutput(Directory dir, String fileName) throws IOException { - //nocommit pass IOContext in via ctor! - out = dir.createOutput(fileName, IOContext.DEFAULT); + public MockSingleIntIndexOutput(Directory dir, String fileName, IOContext context) throws IOException { + out = dir.createOutput(fileName, context); boolean success = false; try { CodecUtil.writeHeader(out, CODEC, VERSION_CURRENT); diff --git a/lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/TermInfosWriter.java b/lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/TermInfosWriter.java index de60280bed9..e2a535aaaab 100644 --- a/lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/TermInfosWriter.java +++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/TermInfosWriter.java @@ -22,11 +22,11 @@ import java.io.Closeable; import java.io.IOException; import org.apache.lucene.index.FieldInfos; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.codecs.preflex.PreFlexCodec; import org.apache.lucene.index.codecs.preflex.TermInfo; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRef; diff --git a/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java index d4a503355d1..afc95a1e73e 100644 --- a/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java +++ b/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java @@ -31,7 +31,6 @@ import java.util.Map; import java.util.Random; import java.util.Set; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.util.LuceneTestCase; @@ -198,7 +197,7 @@ public class MockDirectoryWrapper extends Directory { byte[] zeroes = new byte[256]; long upto = 0; //nocommit - randomize the IOContext here? - IndexOutput out = delegate.createOutput(name, IOContext.DEFAULT); + IndexOutput out = delegate.createOutput(name, LuceneTestCase.newIOContext(randomState)); while(upto < length) { final int limit = (int) Math.min(length-upto, zeroes.length); out.writeBytes(zeroes, 0, limit); @@ -208,7 +207,7 @@ public class MockDirectoryWrapper extends Directory { } else if (count % 3 == 2) { // Truncate the file: //nocommit - randomize the IOContext here? - IndexOutput out = delegate.createOutput(name, IOContext.DEFAULT); + IndexOutput out = delegate.createOutput(name, LuceneTestCase.newIOContext(randomState)); out.setLength(fileLength(name)/2); out.close(); } @@ -376,7 +375,7 @@ public class MockDirectoryWrapper extends Directory { //System.out.println(Thread.currentThread().getName() + ": MDW: create " + name); // nocommit - randomize the IOContext here? - IndexOutput io = new MockIndexOutputWrapper(this, delegate.createOutput(name, context), name); + IndexOutput io = new MockIndexOutputWrapper(this, delegate.createOutput(name, LuceneTestCase.newIOContext(randomState)), name); addFileHandle(io, name, false); openFilesForWrite.add(name); @@ -417,7 +416,7 @@ public class MockDirectoryWrapper extends Directory { } // nocommit - randomize IOContext here? - IndexInput ii = new MockIndexInputWrapper(this, name, delegate.openInput(name, context)); + IndexInput ii = new MockIndexInputWrapper(this, name, delegate.openInput(name, LuceneTestCase.newIOContext(randomState))); addFileHandle(ii, name, true); return ii; } diff --git a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java index a109f8f7f58..0c2d54bc696 100644 --- a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java +++ b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java @@ -60,7 +60,10 @@ import org.apache.lucene.search.AssertingIndexSearcher; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.store.FlushInfo; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.LockFactory; +import org.apache.lucene.store.MergeInfo; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.MockDirectoryWrapper.Throttling; import org.apache.lucene.util.FieldCacheSanityChecker.Insanity; @@ -1312,6 +1315,38 @@ public abstract class LuceneTestCase extends Assert { return sb.toString(); } + public static IOContext newIOContext(Random random) { + int randomNumDocs=4192, size=2048; + int type = random.nextInt(5); + IOContext context = IOContext.DEFAULT; + switch(type) { + case 0: + context = IOContext.DEFAULT; + break; + + case 1: + context = IOContext.READ; + break; + + case 2: + context = IOContext.READONCE; + break; + + case 3: + randomNumDocs = random.nextInt(4192); + size = random.nextInt(2048); + context = new IOContext(new MergeInfo(randomNumDocs, size, true, false)); + break; + + case 4: + randomNumDocs = random.nextInt(4192); + size = random.nextInt(2048); + context = new IOContext(new FlushInfo(randomNumDocs, size)); + break; + } + return context; + } + // recorded seed: for beforeClass private static long staticSeed; // seed for individual test methods, changed in @before diff --git a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java index aa9d2e88706..6bf3506d59b 100755 --- a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java +++ b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java @@ -38,6 +38,7 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; @@ -395,7 +396,7 @@ public class TestAddIndexes extends LuceneTestCase { setMergePolicy(newLogMergePolicy(4)) ); - writer.addIndexes(aux, new MockDirectoryWrapper(random, new RAMDirectory(aux, IOContext.DEFAULT))); + writer.addIndexes(aux, new MockDirectoryWrapper(random, new RAMDirectory(aux, newIOContext(random)))); assertEquals(1060, writer.maxDoc()); assertEquals(1000, writer.getDocCount(0)); writer.close(); @@ -430,7 +431,7 @@ public class TestAddIndexes extends LuceneTestCase { setMergePolicy(newLogMergePolicy(4)) ); - writer.addIndexes(aux, new MockDirectoryWrapper(random, new RAMDirectory(aux, IOContext.DEFAULT))); + writer.addIndexes(aux, new MockDirectoryWrapper(random, new RAMDirectory(aux, newIOContext(random)))); assertEquals(1020, writer.maxDoc()); assertEquals(1000, writer.getDocCount(0)); writer.close(); @@ -665,7 +666,7 @@ public class TestAddIndexes extends LuceneTestCase { final Directory[] dirs = new Directory[NUM_COPY]; for(int k=0;k filesToDelete = merger.createCompoundFile(merged + ".cfs", info, IOContext.DEFAULT); + Collection filesToDelete = merger.createCompoundFile(merged + ".cfs", info, newIOContext(random)); info.setUseCompoundFile(true); for (final String fileToDelete : filesToDelete) si1.dir.deleteFile(fileToDelete); @@ -223,7 +222,7 @@ public class TestDoc extends LuceneTestCase { private void printSegment(PrintWriter out, SegmentInfo si) throws Exception { - SegmentReader reader = SegmentReader.get(true, si, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, IOContext.READ); + SegmentReader reader = SegmentReader.get(true, si, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, newIOContext(random)); for (int i = 0; i < reader.numDocs(); i++) out.println(reader.document(i)); diff --git a/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java b/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java index 93ba1510731..c229ffa8ae6 100644 --- a/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java +++ b/lucene/src/test/org/apache/lucene/index/TestDocTermOrds.java @@ -223,7 +223,7 @@ public class TestDocTermOrds extends LuceneTestCase { @Override public PerDocValues docsProducer(SegmentReadState state) throws IOException { - return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId); + return new DefaultDocValuesProducer(state.segmentInfo, state.dir, state.fieldInfos, state.codecId, state.context); } } diff --git a/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java b/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java index 2c4651ba636..bd6adfbef97 100644 --- a/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java +++ b/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java @@ -34,8 +34,9 @@ import org.apache.lucene.document.Field.Index; import org.apache.lucene.document.Field.Store; import org.apache.lucene.document.Field.TermVector; import org.apache.lucene.document.Fieldable; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; +import org.apache.lucene.store.IOContext.Context; import org.apache.lucene.util.AttributeSource; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; @@ -69,7 +70,7 @@ public class TestDocumentWriter extends LuceneTestCase { SegmentInfo info = writer.newestSegment(); writer.close(); //After adding the document, we should be able to read it back in - SegmentReader reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, IOContext.READ); + SegmentReader reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, newIOContext(random)); assertTrue(reader != null); Document doc = reader.document(0); assertTrue(doc != null); @@ -130,7 +131,7 @@ public class TestDocumentWriter extends LuceneTestCase { writer.commit(); SegmentInfo info = writer.newestSegment(); writer.close(); - SegmentReader reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, IOContext.READ); + SegmentReader reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, newIOContext(random)); DocsAndPositionsEnum termPositions = MultiFields.getTermPositionsEnum(reader, MultiFields.getDeletedDocs(reader), "repeated", new BytesRef("repeated")); @@ -194,7 +195,7 @@ public class TestDocumentWriter extends LuceneTestCase { writer.commit(); SegmentInfo info = writer.newestSegment(); writer.close(); - SegmentReader reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, IOContext.READ); + SegmentReader reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, newIOContext(random)); DocsAndPositionsEnum termPositions = reader.fields().terms("f1").docsAndPositions(reader.getDeletedDocs(), new BytesRef("a"), null); assertTrue(termPositions.nextDoc() != termPositions.NO_MORE_DOCS); @@ -238,7 +239,7 @@ public class TestDocumentWriter extends LuceneTestCase { writer.commit(); SegmentInfo info = writer.newestSegment(); writer.close(); - SegmentReader reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, IOContext.READ); + SegmentReader reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR, newIOContext(random)); DocsAndPositionsEnum termPositions = reader.fields().terms("preanalyzed").docsAndPositions(reader.getDeletedDocs(), new BytesRef("term1"), null); assertTrue(termPositions.nextDoc() != termPositions.NO_MORE_DOCS); diff --git a/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java b/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java index ea9cc600835..ad6113a2129 100644 --- a/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java +++ b/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java @@ -20,7 +20,6 @@ package org.apache.lucene.index; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; import org.apache.lucene.document.Document; -import org.apache.lucene.index.IOContext.Context; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IndexOutput; @@ -48,7 +47,7 @@ public class TestFieldInfos extends LuceneTestCase { assertTrue(fieldInfos.size() == DocHelper.all.size()); //this is all b/c we are using the no-arg constructor - IndexOutput output = dir.createOutput(filename, IOContext.DEFAULT); + IndexOutput output = dir.createOutput(filename, newIOContext(random)); assertTrue(output != null); //Use a RAMOutputStream diff --git a/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java b/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java index a1874a150ca..caacaa3770a 100644 --- a/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java +++ b/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java @@ -35,6 +35,7 @@ import org.apache.lucene.search.FieldCache; 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.store.IndexOutput; import org.apache.lucene.util.LuceneTestCase; diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java b/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java index 7430423416c..fa4e1e6dee7 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java @@ -21,6 +21,7 @@ import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.search.DefaultSimilarity; import org.apache.lucene.search.Similarity; 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.store.MockDirectoryWrapper; @@ -91,7 +92,7 @@ public class TestIndexFileDeleter extends LuceneTestCase { // figure out which field number corresponds to // "content", and then set our expected file names below // accordingly: - CompoundFileReader cfsReader = new CompoundFileReader(dir, "_2.cfs", IOContext.DEFAULT); + CompoundFileReader cfsReader = new CompoundFileReader(dir, "_2.cfs", newIOContext(random)); FieldInfos fieldInfos = new FieldInfos(cfsReader, "_2.fnm"); int contentFieldIndex = -1; for (FieldInfo fi : fieldInfos) { @@ -212,8 +213,8 @@ public class TestIndexFileDeleter extends LuceneTestCase { } public void copyFile(Directory dir, String src, String dest) throws IOException { - IndexInput in = dir.openInput(src, IOContext.DEFAULT); - IndexOutput out = dir.createOutput(dest, IOContext.DEFAULT); + IndexInput in = dir.openInput(src, newIOContext(random)); + IndexOutput out = dir.createOutput(dest, newIOContext(random)); byte[] b = new byte[1024]; long remainder = in.length(); while(remainder > 0) { diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexInput.java b/lucene/src/test/org/apache/lucene/index/TestIndexInput.java index e593760ce76..4c6b881fbfa 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexInput.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexInput.java @@ -99,10 +99,10 @@ public class TestIndexInput extends LuceneTestCase { // this test checks the raw IndexInput methods as it uses RAMIndexInput which extends IndexInput directly public void testRawIndexInputRead() throws IOException { final RAMDirectory dir = new RAMDirectory(); - final IndexOutput os = dir.createOutput("foo", IOContext.DEFAULT); + final IndexOutput os = dir.createOutput("foo", newIOContext(random)); os.writeBytes(READ_TEST_BYTES, READ_TEST_BYTES.length); os.close(); - final IndexInput is = dir.openInput("foo", IOContext.DEFAULT); + final IndexInput is = dir.openInput("foo", newIOContext(random)); checkReads(is); is.close(); dir.close(); diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReaderOnDiskFull.java b/lucene/src/test/org/apache/lucene/index/TestIndexReaderOnDiskFull.java index dfcad0301cb..86ea0f7514c 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexReaderOnDiskFull.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexReaderOnDiskFull.java @@ -84,7 +84,7 @@ public class TestIndexReaderOnDiskFull extends LuceneTestCase { // Iterate w/ ever increasing free disk space: while(!done) { - MockDirectoryWrapper dir = new MockDirectoryWrapper(random, new RAMDirectory(startDir, IOContext.DEFAULT)); + MockDirectoryWrapper dir = new MockDirectoryWrapper(random, new RAMDirectory(startDir, newIOContext(random))); // If IndexReader hits disk full, it can write to // the same files again. diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java index 050da2b5ae0..3a54bf4ed49 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -60,6 +60,7 @@ import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.spans.SpanTermQuery; import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.Lock; import org.apache.lucene.store.LockFactory; @@ -1029,7 +1030,7 @@ public class TestIndexWriter extends LuceneTestCase { Directory dir = newDirectory(); try { // Create my own random file: - IndexOutput out = dir.createOutput("myrandomfile", IOContext.DEFAULT); + IndexOutput out = dir.createOutput("myrandomfile", newIOContext(random)); out.writeByte((byte) 42); out.close(); diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java index 4cb2d5fefbd..0d9b6db6f52 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java @@ -456,7 +456,7 @@ public class TestIndexWriterDelete extends LuceneTestCase { if (VERBOSE) { System.out.println("TEST: cycle"); } - MockDirectoryWrapper dir = new MockDirectoryWrapper(random, new RAMDirectory(startDir, IOContext.DEFAULT)); + MockDirectoryWrapper dir = new MockDirectoryWrapper(random, new RAMDirectory(startDir, newIOContext(random))); dir.setPreventDoubleWrite(false); IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig( diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java index 67e25c34804..ccd2bd78554 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java @@ -39,6 +39,7 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.PhraseQuery; 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.store.MockDirectoryWrapper; @@ -935,7 +936,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase { if (VERBOSE) { System.out.println("TEST: iter " + i); } - MockDirectoryWrapper dir = new MockDirectoryWrapper(random, new RAMDirectory(startDir, IOContext.DEFAULT)); + MockDirectoryWrapper dir = new MockDirectoryWrapper(random, new RAMDirectory(startDir, newIOContext(random))); conf = newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)).setMergeScheduler(new ConcurrentMergeScheduler()); ((ConcurrentMergeScheduler) conf.getMergeScheduler()).setSuppressExceptions(); w = new IndexWriter(dir, conf); @@ -1039,8 +1040,8 @@ public class TestIndexWriterExceptions extends LuceneTestCase { assertTrue("segment generation should be > 0 but got " + gen, gen > 0); final String segmentsFileName = SegmentInfos.getCurrentSegmentFileName(dir); - IndexInput in = dir.openInput(segmentsFileName, IOContext.DEFAULT); - IndexOutput out = dir.createOutput(IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1+gen), IOContext.DEFAULT); + IndexInput in = dir.openInput(segmentsFileName, newIOContext(random)); + IndexOutput out = dir.createOutput(IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1+gen), newIOContext(random)); out.copyBytes(in, in.length()-1); byte b = in.readByte(); out.writeByte((byte) (1+b)); @@ -1084,8 +1085,8 @@ public class TestIndexWriterExceptions extends LuceneTestCase { String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1+gen); - IndexInput in = dir.openInput(fileNameIn, IOContext.DEFAULT); - IndexOutput out = dir.createOutput(fileNameOut, IOContext.DEFAULT); + IndexInput in = dir.openInput(fileNameIn, newIOContext(random)); + IndexOutput out = dir.createOutput(fileNameOut, newIOContext(random)); long length = in.length(); for(int i=0;i set = mapper.getTermVectorEntrySet(); @@ -385,7 +386,7 @@ public class TestTermVectorsReader extends LuceneTestCase { public void testBadParams() throws IOException { TermVectorsReader reader = null; try { - reader = new TermVectorsReader(dir, seg, fieldInfos, IOContext.READ); + reader = new TermVectorsReader(dir, seg, fieldInfos, newIOContext(random)); //Bad document number, good field number reader.get(50, testFields[0]); fail(); @@ -395,7 +396,7 @@ public class TestTermVectorsReader extends LuceneTestCase { reader.close(); } try { - reader = new TermVectorsReader(dir, seg, fieldInfos, IOContext.READ); + reader = new TermVectorsReader(dir, seg, fieldInfos, newIOContext(random)); //Bad document number, no field reader.get(50); fail(); @@ -405,7 +406,7 @@ public class TestTermVectorsReader extends LuceneTestCase { reader.close(); } try { - reader = new TermVectorsReader(dir, seg, fieldInfos, IOContext.READ); + reader = new TermVectorsReader(dir, seg, fieldInfos, newIOContext(random)); //good document number, bad field number TermFreqVector vector = reader.get(0, "f50"); assertTrue(vector == null); diff --git a/lucene/src/test/org/apache/lucene/index/TestTermVectorsWriter.java b/lucene/src/test/org/apache/lucene/index/TestTermVectorsWriter.java index b6675c6ff92..7cb139e6a04 100644 --- a/lucene/src/test/org/apache/lucene/index/TestTermVectorsWriter.java +++ b/lucene/src/test/org/apache/lucene/index/TestTermVectorsWriter.java @@ -299,7 +299,7 @@ public class TestTermVectorsWriter extends LuceneTestCase { .setMergeScheduler(new SerialMergeScheduler()).setMergePolicy( new LogDocMergePolicy())); - Directory[] indexDirs = {new MockDirectoryWrapper(random, new RAMDirectory(dir, IOContext.DEFAULT))}; + Directory[] indexDirs = {new MockDirectoryWrapper(random, new RAMDirectory(dir, newIOContext(random)))}; writer.addIndexes(indexDirs); writer.optimize(); writer.close(); diff --git a/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java b/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java index c97e33c13c9..dbd01a05293 100644 --- a/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java +++ b/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java @@ -19,7 +19,6 @@ package org.apache.lucene.index.codecs.intblock; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.store.*; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.codecs.sep.*; import org.apache.lucene.index.codecs.mockintblock.*; @@ -30,13 +29,13 @@ public class TestIntBlockCodec extends LuceneTestCase { IntStreamFactory f = new MockFixedIntBlockCodec(128).getIntFactory(); - IntIndexOutput out = f.createOutput(dir, "test"); + IntIndexOutput out = f.createOutput(dir, "test", newIOContext(random)); for(int i=0;i<11777;i++) { out.write(i); } out.close(); - IntIndexInput in = f.openInput(dir, "test", IOContext.DEFAULT); + IntIndexInput in = f.openInput(dir, "test", newIOContext(random)); IntIndexInput.Reader r = in.reader(); for(int i=0;i<11777;i++) { @@ -51,12 +50,12 @@ public class TestIntBlockCodec extends LuceneTestCase { Directory dir = newDirectory(); IntStreamFactory f = new MockFixedIntBlockCodec(128).getIntFactory(); - IntIndexOutput out = f.createOutput(dir, "test"); + IntIndexOutput out = f.createOutput(dir, "test", newIOContext(random)); // write no ints out.close(); - IntIndexInput in = f.openInput(dir, "test", IOContext.DEFAULT); + IntIndexInput in = f.openInput(dir, "test", newIOContext(random)); in.reader(); // read no ints in.close(); diff --git a/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java b/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java index c1365d824ac..ce400bdc865 100644 --- a/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java +++ b/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicLong; import org.apache.lucene.index.values.IndexDocValues.SortedSource; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FloatsRef; import org.apache.lucene.util.LongsRef; @@ -61,7 +62,7 @@ public class TestDocValues extends LuceneTestCase { Directory dir = newDirectory(); final AtomicLong trackBytes = new AtomicLong(0); - Writer w = Bytes.getWriter(dir, "test", mode, comp, fixedSize, trackBytes); + Writer w = Bytes.getWriter(dir, "test", mode, comp, fixedSize, trackBytes, newIOContext(random)); int maxDoc = 220; final String[] values = new String[maxDoc]; final int fixedLength = 3 + random.nextInt(7); @@ -81,7 +82,7 @@ public class TestDocValues extends LuceneTestCase { w.finish(maxDoc); assertEquals(0, trackBytes.get()); - IndexDocValues r = Bytes.getValues(dir, "test", mode, fixedSize, maxDoc); + IndexDocValues r = Bytes.getValues(dir, "test", mode, fixedSize, maxDoc, newIOContext(random)); for (int iter = 0; iter < 2; iter++) { ValuesEnum bytesEnum = getEnum(r); assertNotNull("enum is null", bytesEnum); @@ -185,7 +186,7 @@ public class TestDocValues extends LuceneTestCase { for (int rx = 1; rx < 63; rx++, maxV *= 2) { Directory dir = newDirectory(); final AtomicLong trackBytes = new AtomicLong(0); - Writer w = Ints.getWriter(dir, "test", false, trackBytes); + Writer w = Ints.getWriter(dir, "test", false, trackBytes, newIOContext(random)); values[0] = maxMin[j]; w.add(0, values[0]); values[1] = maxMin[j+1]; @@ -199,7 +200,7 @@ public class TestDocValues extends LuceneTestCase { w.finish(NUM_VALUES + additionalDocs); assertEquals(0, trackBytes.get()); - IndexDocValues r = Ints.getValues(dir, "test", false); + IndexDocValues r = Ints.getValues(dir, "test", false, newIOContext(random)); for (int iter = 0; iter < 2; iter++) { Source s = getSource(r); for (int i = 0; i < NUM_VALUES; i++) { @@ -250,7 +251,7 @@ public class TestDocValues extends LuceneTestCase { private void runTestFloats(int precision, double delta) throws IOException { Directory dir = newDirectory(); final AtomicLong trackBytes = new AtomicLong(0); - Writer w = Floats.getWriter(dir, "test", precision, trackBytes); + Writer w = Floats.getWriter(dir, "test", precision, trackBytes, newIOContext(random)); final int NUM_VALUES = 777 + random.nextInt(777);; final double[] values = new double[NUM_VALUES]; for (int i = 0; i < NUM_VALUES; i++) { @@ -263,7 +264,7 @@ public class TestDocValues extends LuceneTestCase { w.finish(NUM_VALUES + additionalValues); assertEquals(0, trackBytes.get()); - IndexDocValues r = Floats.getValues(dir, "test", NUM_VALUES + additionalValues); + IndexDocValues r = Floats.getValues(dir, "test", NUM_VALUES + additionalValues, newIOContext(random)); for (int iter = 0; iter < 2; iter++) { Source s = getSource(r); for (int i = 0; i < NUM_VALUES; i++) { diff --git a/lucene/src/test/org/apache/lucene/search/TestBoolean2.java b/lucene/src/test/org/apache/lucene/search/TestBoolean2.java index 396e216ab9e..f42fceabce3 100644 --- a/lucene/src/test/org/apache/lucene/search/TestBoolean2.java +++ b/lucene/src/test/org/apache/lucene/search/TestBoolean2.java @@ -23,13 +23,13 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.index.IndexReader; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; diff --git a/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java b/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java index b421fea941d..9d9957ec7a8 100755 --- a/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java +++ b/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java @@ -29,7 +29,6 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.index.IOContext; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; @@ -94,11 +93,11 @@ public class TestBufferedIndexInput extends LuceneTestCase { // run test with chunk size of 10 bytes runReadBytesAndClose(new SimpleFSIndexInput(tmpInputFile, - IOContext.DEFAULT, 10), inputBufferSize, random); + newIOContext(random), 10), inputBufferSize, random); // run test with chunk size of 10 bytes runReadBytesAndClose(new NIOFSIndexInput(tmpInputFile, - IOContext.DEFAULT, 10), inputBufferSize, random); + newIOContext(random), 10), inputBufferSize, random); } private void runReadBytesAndClose(IndexInput input, int bufferSize, Random r) diff --git a/lucene/src/test/org/apache/lucene/store/TestCopyBytes.java b/lucene/src/test/org/apache/lucene/store/TestCopyBytes.java index 94630a0e027..156a58f1fb6 100644 --- a/lucene/src/test/org/apache/lucene/store/TestCopyBytes.java +++ b/lucene/src/test/org/apache/lucene/store/TestCopyBytes.java @@ -17,36 +17,33 @@ package org.apache.lucene.store; * limitations under the License. */ - -import org.apache.lucene.index.IOContext; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; import org.junit.Test; public class TestCopyBytes extends LuceneTestCase { - + private byte value(int idx) { - return (byte) ((idx%256) * (1+(idx/256))); + return (byte) ((idx % 256) * (1 + (idx / 256))); } - - + @Test public void testCopyBytes() throws Exception { int num = atLeast(10); - for(int iter=0;iter test2 - final IndexInput in = dir.openInput("test", IOContext.DEFAULT); - - out = dir.createOutput("test2", IOContext.DEFAULT); - + final IndexInput in = dir.openInput("test", newIOContext(random)); + + out = dir.createOutput("test2", newIOContext(random)); + upto = 0; - while(upto < size) { + while (upto < size) { if (random.nextBoolean()) { out.writeByte(in.readByte()); upto++; } else { - final int chunk = Math.min(_TestUtil.nextInt(random, 1, bytes.length), size-upto); + final int chunk = Math.min( + _TestUtil.nextInt(random, 1, bytes.length), size - upto); out.copyBytes(in, chunk); upto += chunk; } @@ -79,26 +77,27 @@ public class TestCopyBytes extends LuceneTestCase { assertEquals(size, upto); out.close(); in.close(); - + // verify - IndexInput in2 = dir.openInput("test2", IOContext.DEFAULT); + IndexInput in2 = dir.openInput("test2", newIOContext(random)); upto = 0; - while(upto < size) { + while (upto < size) { if (random.nextBoolean()) { final byte v = in2.readByte(); assertEquals(value(upto), v); upto++; } else { - final int limit = Math.min(_TestUtil.nextInt(random, 1, bytes.length), size-upto); + final int limit = Math.min( + _TestUtil.nextInt(random, 1, bytes.length), size - upto); in2.readBytes(bytes, 0, limit); - for(int byteIdx=0;byteIdx=count1; i--) { - BitVector bv2 = new BitVector(d, "TESTBV", IOContext.DEFAULT); + BitVector bv2 = new BitVector(d, "TESTBV", newIOContext(random)); assertTrue(doCompare(bv,bv2)); bv = bv2; bv.clear(i); assertEquals(i,bv.count()); - bv.write(d, "TESTBV", IOContext.DEFAULT); + bv.write(d, "TESTBV", newIOContext(random)); } } /** diff --git a/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java b/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java index ccee2e662cd..fe21d7bb96f 100644 --- a/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java +++ b/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java @@ -29,7 +29,7 @@ import java.util.*; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; -import org.apache.lucene.index.IOContext; +import org.apache.lucene.store.IOContext; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; @@ -468,11 +468,13 @@ public class TestFSTs extends LuceneTestCase { } FST fst = builder.finish(); - if (random.nextBoolean() && fst != null) { - IndexOutput out = dir.createOutput("fst.bin", IOContext.DEFAULT); + if (random.nextBoolean() && fst != null) { + TestFSTs t = new TestFSTs(); + IOContext context = t.newIOContext(random); + IndexOutput out = dir.createOutput("fst.bin", context); fst.save(out); out.close(); - IndexInput in = dir.openInput("fst.bin", IOContext.DEFAULT); + IndexInput in = dir.openInput("fst.bin", context); try { fst = new FST(in, outputs); } finally { diff --git a/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java b/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java index 6072e636247..107bf02aeb2 100644 --- a/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java +++ b/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java @@ -17,7 +17,6 @@ package org.apache.lucene.util.packed; * limitations under the License. */ -import org.apache.lucene.index.IOContext; import org.apache.lucene.store.*; import org.apache.lucene.util.LuceneTestCase; @@ -55,7 +54,7 @@ public class TestPackedInts extends LuceneTestCase { final int valueCount = 100+random.nextInt(500); final Directory d = newDirectory(); - IndexOutput out = d.createOutput("out.bin", IOContext.DEFAULT); + IndexOutput out = d.createOutput("out.bin", newIOContext(random)); PackedInts.Writer w = PackedInts.getWriter( out, valueCount, nbits); @@ -72,7 +71,7 @@ public class TestPackedInts extends LuceneTestCase { final long fp = out.getFilePointer(); out.close(); {// test reader - IndexInput in = d.openInput("out.bin", IOContext.DEFAULT); + IndexInput in = d.openInput("out.bin", newIOContext(random)); PackedInts.Reader r = PackedInts.getReader(in); assertEquals(fp, in.getFilePointer()); for(int i=0;i