You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2012/01/19 15:06:10 UTC
svn commit: r1233380 - in /lucene/dev/trunk/lucene/src:
java/org/apache/lucene/codecs/lucene3x/
java/org/apache/lucene/codecs/lucene40/
test-framework/java/org/apache/lucene/codecs/preflexrw/
Author: simonw
Date: Thu Jan 19 14:06:10 2012
New Revision: 1233380
URL: http://svn.apache.org/viewvc?rev=1233380&view=rev
Log:
LUCENE-3707: Add a Lucene3x private SegmentInfosFormat implementation
Added:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosFormat.java
- copied, changed from r1233248, lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosFormat.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosReader.java
- copied, changed from r1233248, lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosReader.java
lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosFormat.java
- copied, changed from r1233248, lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosFormat.java
lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosWriter.java
- copied, changed from r1233248, lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosWriter.java
Modified:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosFormat.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xNormsFormat.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xPostingsFormat.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsFormat.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosReader.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosWriter.java
lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWCodec.java
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java?rev=1233380&r1=1233379&r2=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java Thu Jan 19 14:06:10 2012
@@ -30,9 +30,7 @@ import org.apache.lucene.codecs.Postings
import org.apache.lucene.codecs.SegmentInfosFormat;
import org.apache.lucene.codecs.StoredFieldsFormat;
import org.apache.lucene.codecs.TermVectorsFormat;
-import org.apache.lucene.codecs.lucene40.Lucene40SegmentInfosFormat;
import org.apache.lucene.codecs.lucene40.Lucene40StoredFieldsFormat;
-import org.apache.lucene.codecs.lucene40.Lucene40TermVectorsFormat;
import org.apache.lucene.index.PerDocWriteState;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.index.SegmentReadState;
@@ -55,12 +53,8 @@ public class Lucene3xCodec extends Codec
private final FieldInfosFormat fieldInfosFormat = new Lucene3xFieldInfosFormat();
- // TODO: this should really be a different impl
- // also if we want preflex to *really* be read-only it should throw exception for the writer?
- // this way IR.commit fails on delete/undelete/setNorm/etc ?
- private final SegmentInfosFormat infosFormat = new Lucene40SegmentInfosFormat();
+ private final SegmentInfosFormat infosFormat = new Lucene3xSegmentInfosFormat();
- // TODO: this should really be a different impl
private final NormsFormat normsFormat = new Lucene3xNormsFormat();
// 3.x doesn't support docvalues
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosFormat.java?rev=1233380&r1=1233379&r2=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosFormat.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosFormat.java Thu Jan 19 14:06:10 2012
@@ -27,8 +27,12 @@ import org.apache.lucene.index.SegmentIn
import org.apache.lucene.store.Directory;
/**
+ * Lucene3x ReadOnly FieldInfosFromat implementation
+ * @deprecated (4.0) This is only used to read indexes created
+ * before 4.0.
* @lucene.experimental
*/
+@Deprecated
public class Lucene3xFieldInfosFormat extends FieldInfosFormat {
private final FieldInfosReader reader = new Lucene3xFieldInfosReader();
@@ -39,7 +43,7 @@ public class Lucene3xFieldInfosFormat ex
@Override
public FieldInfosWriter getFieldInfosWriter() throws IOException {
- throw new IllegalArgumentException("this codec can only be used for reading");
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
@Override
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xNormsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xNormsFormat.java?rev=1233380&r1=1233379&r2=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xNormsFormat.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xNormsFormat.java Thu Jan 19 14:06:10 2012
@@ -29,10 +29,12 @@ import org.apache.lucene.index.SegmentRe
import org.apache.lucene.store.Directory;
/**
- * Read-Only Lucene 3.x Norms Format
- *
+ * Lucene3x ReadOnly NormsFormat implementation
+ * @deprecated (4.0) This is only used to read indexes created
+ * before 4.0.
* @lucene.experimental
*/
+@Deprecated
public class Lucene3xNormsFormat extends NormsFormat {
@@ -49,7 +51,7 @@ public class Lucene3xNormsFormat extends
@Override
public PerDocConsumer docsConsumer(PerDocWriteState state) throws IOException {
- throw new IllegalArgumentException("this codec can only be used for reading");
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
@Override
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xPostingsFormat.java?rev=1233380&r1=1233379&r2=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xPostingsFormat.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xPostingsFormat.java Thu Jan 19 14:06:10 2012
@@ -57,7 +57,7 @@ public class Lucene3xPostingsFormat exte
@Override
public FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException {
- throw new IllegalArgumentException("this codec can only be used for reading");
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
@Override
Copied: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosFormat.java (from r1233248, lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosFormat.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosFormat.java?p2=lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosFormat.java&p1=lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosFormat.java&r1=1233248&r2=1233380&rev=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosFormat.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosFormat.java Thu Jan 19 14:06:10 2012
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.lucene40;
+package org.apache.lucene.codecs.lucene3x;
import org.apache.lucene.codecs.SegmentInfosFormat;
import org.apache.lucene.codecs.SegmentInfosReader;
@@ -22,11 +22,14 @@ import org.apache.lucene.codecs.SegmentI
*/
/**
+ * Lucene3x ReadOnly SegmentInfosFormat implementation
+ * @deprecated (4.0) This is only used to read indexes created
+ * before 4.0.
* @lucene.experimental
*/
-public class Lucene40SegmentInfosFormat extends SegmentInfosFormat {
- private final SegmentInfosReader reader = new Lucene40SegmentInfosReader();
- private final SegmentInfosWriter writer = new Lucene40SegmentInfosWriter();
+@Deprecated
+public class Lucene3xSegmentInfosFormat extends SegmentInfosFormat {
+ private final SegmentInfosReader reader = new Lucene3xSegmentInfosReader();
@Override
public SegmentInfosReader getSegmentInfosReader() {
@@ -35,6 +38,6 @@ public class Lucene40SegmentInfosFormat
@Override
public SegmentInfosWriter getSegmentInfosWriter() {
- return writer;
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
}
Copied: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosReader.java (from r1233248, lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosReader.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosReader.java?p2=lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosReader.java&p1=lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosReader.java&r1=1233248&r2=1233380&rev=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfosReader.java Thu Jan 19 14:06:10 2012
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.lucene40;
+package org.apache.lucene.codecs.lucene3x;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,7 +23,8 @@ import java.util.Map;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.SegmentInfosReader;
-import org.apache.lucene.codecs.lucene40.Lucene40TermVectorsReader;
+// TODO we need a 3x version of stored fields reader
+import org.apache.lucene.codecs.lucene40.Lucene40StoredFieldsReader;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.IndexFormatTooOldException;
import org.apache.lucene.index.SegmentInfo;
@@ -34,19 +35,11 @@ import org.apache.lucene.store.Directory
import org.apache.lucene.store.IOContext;
/**
- * Default implementation of {@link SegmentInfosReader}.
+ * Lucene 3x implementation of {@link SegmentInfosReader}.
* @lucene.experimental
*/
-public class Lucene40SegmentInfosReader extends SegmentInfosReader {
+public class Lucene3xSegmentInfosReader extends SegmentInfosReader {
- // TODO: shove all backwards code to preflex!
- // this is a little tricky, because of IR.commit(), two options:
- // 1. PreFlex writes 4.x SIS format, but reads both 3.x and 4.x
- // (and maybe RW always only writes the 3.x one? for that to work well,
- // we have to move .fnx file to codec too, not too bad but more work).
- // or we just have crappier RW testing like today.
- // 2. PreFlex writes 3.x SIS format, and only reads 3.x
- // (in this case we have to move .fnx file to codec as well)
@Override
public void read(Directory directory, String segmentsFileName, ChecksumIndexInput input, SegmentInfos infos, IOContext context) throws IOException {
infos.version = input.readLong(); // read version
@@ -115,11 +108,9 @@ public class Lucene40SegmentInfosReader
docStoreIsCompoundFile = false;
}
- if (format > SegmentInfos.FORMAT_4_0) {
- // pre-4.0 indexes write a byte if there is a single norms file
- byte b = input.readByte();
- assert 1 == b;
- }
+ // pre-4.0 indexes write a byte if there is a single norms file
+ byte b = input.readByte();
+ assert 1 == b : "expected 1 but was: "+ b + " format: " + format;
final int numNormGen = input.readInt();
final Map<Integer,Long> normGen;
@@ -128,12 +119,7 @@ public class Lucene40SegmentInfosReader
} else {
normGen = new HashMap<Integer, Long>();
for(int j=0;j<numNormGen;j++) {
- int fieldNumber = j;
- if (format <= SegmentInfos.FORMAT_4_0) {
- fieldNumber = input.readInt();
- }
-
- normGen.put(fieldNumber, input.readLong());
+ normGen.put(j, input.readLong());
}
}
final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;
@@ -143,13 +129,7 @@ public class Lucene40SegmentInfosReader
final int hasProx = input.readByte();
- final Codec codec;
- // note: if the codec is not available: Codec.forName will throw an exception.
- if (format <= SegmentInfos.FORMAT_4_0) {
- codec = Codec.forName(input.readString());
- } else {
- codec = Codec.forName("Lucene3x");
- }
+ final Codec codec = Codec.forName("Lucene3x");
final Map<String,String> diagnostics = input.readStringStringMap();
final int hasVectors;
@@ -175,8 +155,7 @@ public class Lucene40SegmentInfosReader
dirToTest = dir;
}
try {
- // TODO: remove this manual file check or push to preflex codec
- hasVectors = dirToTest.fileExists(IndexFileNames.segmentFileName(storesSegment, "", Lucene40TermVectorsReader.VECTORS_INDEX_EXTENSION)) ? SegmentInfo.YES : SegmentInfo.NO;
+ hasVectors = dirToTest.fileExists(IndexFileNames.segmentFileName(storesSegment, "", Lucene3xTermVectorsReader.VECTORS_INDEX_EXTENSION)) ? SegmentInfo.YES : SegmentInfo.NO;
} finally {
if (isCompoundFile) {
dirToTest.close();
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsFormat.java?rev=1233380&r1=1233379&r2=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsFormat.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsFormat.java Thu Jan 19 14:06:10 2012
@@ -28,6 +28,13 @@ import org.apache.lucene.index.SegmentIn
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
+/**
+ * Lucene3x ReadOnly TermVectorsFormat implementation
+ * @deprecated (4.0) This is only used to read indexes created
+ * before 4.0.
+ * @lucene.experimental
+ */
+@Deprecated
public class Lucene3xTermVectorsFormat extends TermVectorsFormat {
@Override
@@ -37,8 +44,7 @@ public class Lucene3xTermVectorsFormat e
@Override
public TermVectorsWriter vectorsWriter(Directory directory, String segment, IOContext context) throws IOException {
- // TODO all these IAEs in preflex should be UOEs?
- throw new IllegalArgumentException("this codec can only be used for reading");
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
@Override
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosReader.java?rev=1233380&r1=1233379&r2=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosReader.java Thu Jan 19 14:06:10 2012
@@ -23,13 +23,10 @@ import java.util.Map;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.SegmentInfosReader;
-import org.apache.lucene.codecs.lucene40.Lucene40TermVectorsReader;
-import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.IndexFormatTooOldException;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.CompoundFileDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
@@ -39,88 +36,37 @@ import org.apache.lucene.store.IOContext
*/
public class Lucene40SegmentInfosReader extends SegmentInfosReader {
- // TODO: shove all backwards code to preflex!
- // this is a little tricky, because of IR.commit(), two options:
- // 1. PreFlex writes 4.x SIS format, but reads both 3.x and 4.x
- // (and maybe RW always only writes the 3.x one? for that to work well,
- // we have to move .fnx file to codec too, not too bad but more work).
- // or we just have crappier RW testing like today.
- // 2. PreFlex writes 3.x SIS format, and only reads 3.x
- // (in this case we have to move .fnx file to codec as well)
@Override
public void read(Directory directory, String segmentsFileName, ChecksumIndexInput input, SegmentInfos infos, IOContext context) throws IOException {
infos.version = input.readLong(); // read version
infos.counter = input.readInt(); // read counter
final int format = infos.getFormat();
+ assert format <= SegmentInfos.FORMAT_4_0;
for (int i = input.readInt(); i > 0; i--) { // read segmentInfos
SegmentInfo si = readSegmentInfo(directory, format, input);
- if (si.getVersion() == null) {
- // Could be a 3.0 - try to open the doc stores - if it fails, it's a
- // 2.x segment, and an IndexFormatTooOldException will be thrown,
- // which is what we want.
- Directory dir = directory;
- if (si.getDocStoreOffset() != -1) {
- if (si.getDocStoreIsCompoundFile()) {
- dir = new CompoundFileDirectory(dir, IndexFileNames.segmentFileName(
- si.getDocStoreSegment(), "",
- IndexFileNames.COMPOUND_FILE_STORE_EXTENSION), context, false);
- }
- } else if (si.getUseCompoundFile()) {
- dir = new CompoundFileDirectory(dir, IndexFileNames.segmentFileName(
- si.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION), context, false);
- }
-
- try {
- Lucene40StoredFieldsReader.checkCodeVersion(dir, si.getDocStoreSegment());
- } finally {
- // If we opened the directory, close it
- if (dir != directory) dir.close();
- }
-
- // Above call succeeded, so it's a 3.0 segment. Upgrade it so the next
- // time the segment is read, its version won't be null and we won't
- // need to open FieldsReader every time for each such segment.
- si.setVersion("3.0");
- } else if (si.getVersion().equals("2.x")) {
- // If it's a 3x index touched by 3.1+ code, then segments record their
- // version, whether they are 2.x ones or not. We detect that and throw
- // appropriate exception.
- throw new IndexFormatTooOldException("segment " + si.name + " in resource " + input, si.getVersion());
- }
+ assert si.getVersion() != null;
infos.add(si);
}
infos.userData = input.readStringStringMap();
}
- // if we make a preflex impl we can remove a lot of this hair...
public SegmentInfo readSegmentInfo(Directory dir, int format, ChecksumIndexInput input) throws IOException {
- final String version;
- if (format <= SegmentInfos.FORMAT_3_1) {
- version = input.readString();
- } else {
- version = null;
- }
+ final String version = input.readString();
final String name = input.readString();
final int docCount = input.readInt();
final long delGen = input.readLong();
+ // this is still written in 4.0 if we open a 3.x and upgrade the SI
final int docStoreOffset = input.readInt();
final String docStoreSegment;
final boolean docStoreIsCompoundFile;
- if (docStoreOffset != -1) {
+ if (docStoreOffset != -1) {
docStoreSegment = input.readString();
docStoreIsCompoundFile = input.readByte() == SegmentInfo.YES;
} else {
docStoreSegment = name;
docStoreIsCompoundFile = false;
}
-
- if (format > SegmentInfos.FORMAT_4_0) {
- // pre-4.0 indexes write a byte if there is a single norms file
- byte b = input.readByte();
- assert 1 == b;
- }
-
final int numNormGen = input.readInt();
final Map<Integer,Long> normGen;
if (numNormGen == SegmentInfo.NO) {
@@ -128,61 +74,17 @@ public class Lucene40SegmentInfosReader
} else {
normGen = new HashMap<Integer, Long>();
for(int j=0;j<numNormGen;j++) {
- int fieldNumber = j;
- if (format <= SegmentInfos.FORMAT_4_0) {
- fieldNumber = input.readInt();
- }
-
- normGen.put(fieldNumber, input.readLong());
+ normGen.put(input.readInt(), input.readLong());
}
}
final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;
final int delCount = input.readInt();
assert delCount <= docCount;
-
final int hasProx = input.readByte();
-
- final Codec codec;
- // note: if the codec is not available: Codec.forName will throw an exception.
- if (format <= SegmentInfos.FORMAT_4_0) {
- codec = Codec.forName(input.readString());
- } else {
- codec = Codec.forName("Lucene3x");
- }
+ final Codec codec = Codec.forName(input.readString());
final Map<String,String> diagnostics = input.readStringStringMap();
-
- final int hasVectors;
- if (format <= SegmentInfos.FORMAT_HAS_VECTORS) {
- hasVectors = input.readByte();
- } else {
- final String storesSegment;
- final String ext;
- final boolean storeIsCompoundFile;
- if (docStoreOffset != -1) {
- storesSegment = docStoreSegment;
- storeIsCompoundFile = docStoreIsCompoundFile;
- ext = IndexFileNames.COMPOUND_FILE_STORE_EXTENSION;
- } else {
- storesSegment = name;
- storeIsCompoundFile = isCompoundFile;
- ext = IndexFileNames.COMPOUND_FILE_EXTENSION;
- }
- final Directory dirToTest;
- if (storeIsCompoundFile) {
- dirToTest = new CompoundFileDirectory(dir, IndexFileNames.segmentFileName(storesSegment, "", ext), IOContext.READONCE, false);
- } else {
- dirToTest = dir;
- }
- try {
- // TODO: remove this manual file check or push to preflex codec
- hasVectors = dirToTest.fileExists(IndexFileNames.segmentFileName(storesSegment, "", Lucene40TermVectorsReader.VECTORS_INDEX_EXTENSION)) ? SegmentInfo.YES : SegmentInfo.NO;
- } finally {
- if (isCompoundFile) {
- dirToTest.close();
- }
- }
- }
+ final int hasVectors = input.readByte();
return new SegmentInfo(dir, version, name, docCount, delGen, docStoreOffset,
docStoreSegment, docStoreIsCompoundFile, normGen, isCompoundFile,
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosWriter.java?rev=1233380&r1=1233379&r2=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosWriter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosWriter.java Thu Jan 19 14:06:10 2012
@@ -43,6 +43,10 @@ public class Lucene40SegmentInfosWriter
IndexOutput out = createOutput(dir, segmentFileName, new IOContext(new FlushInfo(infos.size(), infos.totalDocCount())));
boolean success = false;
try {
+ /*
+ * TODO its not ideal that we write the format and the codecID inside the
+ * codec private classes but we read it in SegmentInfos.
+ */
out.writeInt(SegmentInfos.FORMAT_CURRENT); // write FORMAT
out.writeString(codecID); // write codecID
out.writeLong(infos.version);
@@ -69,7 +73,7 @@ public class Lucene40SegmentInfosWriter
output.writeString(si.name);
output.writeInt(si.docCount);
output.writeLong(si.getDelGen());
-
+ // we still need to write this in 4.0 since we can open a 3.x with shared docStores
output.writeInt(si.getDocStoreOffset());
if (si.getDocStoreOffset() != -1) {
output.writeString(si.getDocStoreSegment());
Modified: lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWCodec.java?rev=1233380&r1=1233379&r2=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWCodec.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWCodec.java Thu Jan 19 14:06:10 2012
@@ -20,6 +20,7 @@ package org.apache.lucene.codecs.preflex
import org.apache.lucene.codecs.FieldInfosFormat;
import org.apache.lucene.codecs.NormsFormat;
import org.apache.lucene.codecs.PostingsFormat;
+import org.apache.lucene.codecs.SegmentInfosFormat;
import org.apache.lucene.codecs.TermVectorsFormat;
import org.apache.lucene.codecs.lucene3x.Lucene3xCodec;
import org.apache.lucene.util.LuceneTestCase;
@@ -33,6 +34,7 @@ public class PreFlexRWCodec extends Luce
private final NormsFormat norms = new PreFlexRWNormsFormat();
private final FieldInfosFormat fieldInfos = new PreFlexRWFieldInfosFormat();
private final TermVectorsFormat termVectors = new PreFlexRWTermVectorsFormat();
+ private final SegmentInfosFormat segmentInfos = new PreFlexRWSegmentInfosFormat();
@Override
public PostingsFormat postingsFormat() {
@@ -53,6 +55,15 @@ public class PreFlexRWCodec extends Luce
}
@Override
+ public SegmentInfosFormat segmentInfosFormat() {
+ if (LuceneTestCase.PREFLEX_IMPERSONATION_IS_ACTIVE) {
+ return segmentInfos ;
+ } else {
+ return super.segmentInfosFormat();
+ }
+ }
+
+ @Override
public FieldInfosFormat fieldInfosFormat() {
if (LuceneTestCase.PREFLEX_IMPERSONATION_IS_ACTIVE) {
return fieldInfos;
Copied: lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosFormat.java (from r1233248, lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosFormat.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosFormat.java?p2=lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosFormat.java&p1=lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosFormat.java&r1=1233248&r2=1233380&rev=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosFormat.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosFormat.java Thu Jan 19 14:06:10 2012
@@ -1,8 +1,7 @@
-package org.apache.lucene.codecs.lucene40;
+package org.apache.lucene.codecs.preflexrw;
-import org.apache.lucene.codecs.SegmentInfosFormat;
-import org.apache.lucene.codecs.SegmentInfosReader;
import org.apache.lucene.codecs.SegmentInfosWriter;
+import org.apache.lucene.codecs.lucene3x.Lucene3xSegmentInfosFormat;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -24,16 +23,10 @@ import org.apache.lucene.codecs.SegmentI
/**
* @lucene.experimental
*/
-public class Lucene40SegmentInfosFormat extends SegmentInfosFormat {
- private final SegmentInfosReader reader = new Lucene40SegmentInfosReader();
- private final SegmentInfosWriter writer = new Lucene40SegmentInfosWriter();
+public class PreFlexRWSegmentInfosFormat extends Lucene3xSegmentInfosFormat {
+ private final SegmentInfosWriter writer = new PreFlexRWSegmentInfosWriter();
@Override
- public SegmentInfosReader getSegmentInfosReader() {
- return reader;
- }
-
- @Override
public SegmentInfosWriter getSegmentInfosWriter() {
return writer;
}
Copied: lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosWriter.java (from r1233248, lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosWriter.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosWriter.java?p2=lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosWriter.java&p1=lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosWriter.java&r1=1233248&r2=1233380&rev=1233380&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfosWriter.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWSegmentInfosWriter.java Thu Jan 19 14:06:10 2012
@@ -1,4 +1,4 @@
-package org.apache.lucene.codecs.lucene40;
+package org.apache.lucene.codecs.preflexrw;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -32,10 +32,10 @@ import org.apache.lucene.store.IndexOutp
import org.apache.lucene.util.IOUtils;
/**
- * Default implementation of {@link SegmentInfosWriter}.
+ * PreFlex implementation of {@link SegmentInfosWriter}.
* @lucene.experimental
*/
-public class Lucene40SegmentInfosWriter extends SegmentInfosWriter {
+public class PreFlexRWSegmentInfosWriter extends SegmentInfosWriter {
@Override
public IndexOutput writeInfos(Directory dir, String segmentFileName, String codecID, SegmentInfos infos, IOContext context)
@@ -43,8 +43,8 @@ public class Lucene40SegmentInfosWriter
IndexOutput out = createOutput(dir, segmentFileName, new IOContext(new FlushInfo(infos.size(), infos.totalDocCount())));
boolean success = false;
try {
- out.writeInt(SegmentInfos.FORMAT_CURRENT); // write FORMAT
- out.writeString(codecID); // write codecID
+ out.writeInt(SegmentInfos.FORMAT_3_1); // write FORMAT
+ // we don't write a codec - this is 3.x
out.writeLong(infos.version);
out.writeInt(infos.counter); // write counter
out.writeInt(infos.size()); // write infos
@@ -75,6 +75,8 @@ public class Lucene40SegmentInfosWriter
output.writeString(si.getDocStoreSegment());
output.writeByte((byte) (si.getDocStoreIsCompoundFile() ? 1:0));
}
+ // pre-4.0 indexes write a byte if there is a single norms file
+ output.writeByte((byte) 1);
Map<Integer,Long> normGen = si.getNormGen();
if (normGen == null) {
@@ -82,7 +84,6 @@ public class Lucene40SegmentInfosWriter
} else {
output.writeInt(normGen.size());
for (Entry<Integer,Long> entry : normGen.entrySet()) {
- output.writeInt(entry.getKey());
output.writeLong(entry.getValue());
}
}
@@ -90,7 +91,6 @@ public class Lucene40SegmentInfosWriter
output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
output.writeInt(si.getDelCount());
output.writeByte((byte) (si.getHasProxInternal()));
- output.writeString(si.getCodec().getName());
output.writeStringStringMap(si.getDiagnostics());
output.writeByte((byte) (si.getHasVectorsInternal()));
}