Apache Lucene open-source search software
removed invalid nocommits & some minor cleanups
Simon Willnauera3af18cdeae6
diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.javaindex 4d235830d50..570041bf0fa 100644--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java@@ -2470,7 +2470,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {for (IndexReader reader : readers) // add new indexesmerger.add(reader);- // nocommit - we should pass a MergeInfo here into merge to create corresponding IOContext instances?int docCount = merger.merge(); // merge 'emfinal FieldInfos fieldInfos = merger.fieldInfos();diff --git a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/src/java/org/apache/lucene/index/SegmentMerger.javaindex 396e024026a..f388f156e7f 100644--- a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java+++ b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java@@ -236,7 +236,6 @@ final class SegmentMerger {int docCount = 0;setMatchingSegmentReaders();- // nocommit - should we rather use IOContext.MERGE here?final FieldsWriter fieldsWriter = new FieldsWriter(directory, segment, context);try {int idx = 0;diff --git a/lucene/src/java/org/apache/lucene/store/IOContext.java b/lucene/src/java/org/apache/lucene/store/IOContext.javaindex bfff4483576..294453e18ce 100644--- a/lucene/src/java/org/apache/lucene/store/IOContext.java+++ b/lucene/src/java/org/apache/lucene/store/IOContext.java@@ -10,7 +10,7 @@ package org.apache.lucene.store;** http://www.apache.org/licenses/LICENSE-2.0*-* Unless required by applicable law or agreed to in writing, software+ * 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@@ -26,60 +26,64 @@ package org.apache.lucene.store;public class IOContext {/**- * Context is a enumerator which specifies the context in which the Directory is being used for.+ * Context is a enumerator which specifies the context in which the Directory+ * is being used for.*/- public enum Context {MERGE,READ,FLUSH,DEFAULT};-+ public enum Context {+ MERGE, READ, FLUSH, DEFAULT+ };+/*** An object of a enumerator Context type*/public final Context context;-+public final MergeInfo mergeInfo;-+public final FlushInfo flushInfo;-+public final boolean readOnce;-+public static final IOContext DEFAULT = new IOContext(Context.DEFAULT);-+public static final IOContext READONCE = new IOContext(true);-+public static final IOContext READ = new IOContext(false);-- public IOContext () {++ public IOContext() {this(false);}-- public IOContext (FlushInfo flushInfo) {++ public IOContext(FlushInfo flushInfo) {assert flushInfo != null;this.context = Context.FLUSH;this.mergeInfo = null;this.readOnce = false;- this.flushInfo = flushInfo;+ this.flushInfo = flushInfo;}-- public IOContext (Context context) {- this(context, null);++ public IOContext(Context context) {+ this(context, null);}-- private IOContext (boolean readOnce) {++ private IOContext(boolean readOnce) {this.context = Context.READ;- this.mergeInfo = null;+ this.mergeInfo = null;this.readOnce = readOnce;this.flushInfo = null;}-- public IOContext (MergeInfo mergeInfo) {++ public IOContext(MergeInfo mergeInfo) {this(Context.MERGE, mergeInfo);}- private IOContext (Context context, MergeInfo mergeInfo ) {- assert context != Context.MERGE || context != Context.FLUSH || mergeInfo != null;+ private IOContext(Context context, MergeInfo mergeInfo) {+ assert context != Context.MERGE || mergeInfo != null : "MergeInfo must not be null if context is MERGE";+ assert context != Context.FLUSH : "Use IOContext(FlushInfo) to create a FLUSH IOContext";this.context = context;this.readOnce = false;this.mergeInfo = mergeInfo;this.flushInfo = null;}-+}\ No newline at end of filediff --git a/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.javaindex afc95a1e73e..073e448ac43 100644--- a/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java+++ b/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java@@ -196,7 +196,6 @@ public class MockDirectoryWrapper extends Directory {long length = fileLength(name);byte[] zeroes = new byte[256];long upto = 0;- //nocommit - randomize the IOContext here?IndexOutput out = delegate.createOutput(name, LuceneTestCase.newIOContext(randomState));while(upto < length) {final int limit = (int) Math.min(length-upto, zeroes.length);@@ -206,7 +205,6 @@ public class MockDirectoryWrapper extends Directory {out.close();} else if (count % 3 == 2) {// Truncate the file:- //nocommit - randomize the IOContext here?IndexOutput out = delegate.createOutput(name, LuceneTestCase.newIOContext(randomState));out.setLength(fileLength(name)/2);out.close();@@ -374,7 +372,6 @@ 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, LuceneTestCase.newIOContext(randomState)), name);addFileHandle(io, name, false);openFilesForWrite.add(name);@@ -415,7 +412,6 @@ public class MockDirectoryWrapper extends Directory {throw fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open for writing"), name, false);}- // nocommit - randomize IOContext here?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.javaindex 0c2d54bc696..dc89072c4d2 100644--- a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java@@ -1059,8 +1059,7 @@ public abstract class LuceneTestCase extends Assert {public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);for (String file : d.listAll()) {- //nocommit randomiz the IOContext here?- d.copy(impl, file, file, IOContext.DEFAULT);+ d.copy(impl, file, file, newIOContext(r));}MockDirectoryWrapper dir = new MockDirectoryWrapper(r, impl);stores.put(dir, Thread.currentThread().getStackTrace());@@ -1316,33 +1315,27 @@ public abstract class LuceneTestCase extends Assert {}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;+ final int randomNumDocs = random.nextInt(4192);+ final int size = random.nextInt(512) * randomNumDocs;+ final IOContext context;+ switch (random.nextInt(5)) {+ case 0:+ context = IOContext.DEFAULT;+ break;+ case 1:+ context = IOContext.READ;+ break;+ case 2:+ context = IOContext.READONCE;+ break;+ case 3:+ context = new IOContext(new MergeInfo(randomNumDocs, size, true, false));+ break;+ case 4:+ context = new IOContext(new FlushInfo(randomNumDocs, size));+ break;+ default:+ context = IOContext.DEFAULT;}return context;}