From 365ec15d2ba37a1546bc2892b86be7a3dfcb6863 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 15 Jan 2015 21:47:53 -0500 Subject: [PATCH] Backcompat: Fix backcompat for 0.90.0.Beta1 indexes --- src/main/java/org/elasticsearch/Version.java | 2 +- .../postingsformat/BloomFilterPostingsFormat.java | 13 +++---------- .../org.apache.lucene.codecs.PostingsFormat | 1 + .../OldIndexBackwardsCompatibilityTests.java | 4 ++-- .../Elasticsearch090RWPostingsFormat.java | 11 ++++++++++- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/elasticsearch/Version.java b/src/main/java/org/elasticsearch/Version.java index a191eb8bee2..1f47417e7d6 100644 --- a/src/main/java/org/elasticsearch/Version.java +++ b/src/main/java/org/elasticsearch/Version.java @@ -219,7 +219,7 @@ public class Version { public static final int V_1_4_2_ID = 1040299; public static final Version V_1_4_2 = new Version(V_1_4_2_ID, false, org.apache.lucene.util.Version.LUCENE_4_10_2); public static final int V_1_4_3_ID = 1040399; - public static final Version V_1_4_3 = new Version(V_1_4_3_ID, false, org.apache.lucene.util.Version.LUCENE_4_10_2); + public static final Version V_1_4_3 = new Version(V_1_4_3_ID, true, org.apache.lucene.util.Version.LUCENE_4_10_2); public static final int V_1_5_0_ID = 1050099; public static final Version V_1_5_0 = new Version(V_1_5_0_ID, true, org.apache.lucene.util.Version.LUCENE_4_10_3); public static final int V_2_0_0_ID = 2000099; diff --git a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java index 863d1763b7a..e0b2da64297 100644 --- a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java +++ b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java @@ -43,7 +43,7 @@ import java.util.Map.Entry; * @deprecated only for reading old segments */ @Deprecated -public final class BloomFilterPostingsFormat extends PostingsFormat { +public class BloomFilterPostingsFormat extends PostingsFormat { public static final String BLOOM_CODEC_NAME = "XBloomFilter"; // the Lucene one is named BloomFilter public static final int BLOOM_CODEC_VERSION = 1; @@ -83,15 +83,8 @@ public final class BloomFilterPostingsFormat extends PostingsFormat { } @Override - public BloomFilteredFieldsConsumer fieldsConsumer(SegmentWriteState state) - throws IOException { - if (delegatePostingsFormat == null) { - throw new UnsupportedOperationException("Error - " + getClass().getName() - + " has been constructed without a choice of PostingsFormat"); - } - return new BloomFilteredFieldsConsumer( - delegatePostingsFormat.fieldsConsumer(state), state, - delegatePostingsFormat); + public BloomFilteredFieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException { + throw new UnsupportedOperationException("this codec can only be used for reading"); } @Override diff --git a/src/main/resources/META-INF/services/org.apache.lucene.codecs.PostingsFormat b/src/main/resources/META-INF/services/org.apache.lucene.codecs.PostingsFormat index 20debad9cac..52134e4fc82 100644 --- a/src/main/resources/META-INF/services/org.apache.lucene.codecs.PostingsFormat +++ b/src/main/resources/META-INF/services/org.apache.lucene.codecs.PostingsFormat @@ -1,2 +1,3 @@ org.elasticsearch.index.codec.postingsformat.Elasticsearch090PostingsFormat org.elasticsearch.search.suggest.completion.Completion090PostingsFormat +org.elasticsearch.index.codec.postingsformat.BloomFilterPostingsFormat diff --git a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java index 0156f7559d2..381c83ab460 100644 --- a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java @@ -55,6 +55,7 @@ public class OldIndexBackwardsCompatibilityTests extends StaticIndexBackwardComp List indexes = Arrays.asList( /* skipping 0.90.0.Beta1...fails to load with "java.lang.IllegalArgumentException: An SPI class of type org.apache.lucene.codecs.PostingsFormat with name 'XBloomFilter' does not exist" */ + "index-0.90.0.Beta1.zip", "index-0.90.0.RC1.zip", "index-0.90.0.RC2.zip", "index-0.90.0.zip", @@ -110,8 +111,7 @@ public class OldIndexBackwardsCompatibilityTests extends StaticIndexBackwardComp if (v.onOrBefore(Version.V_0_20_6)) continue; // problematic indexes...see notes above - if (v.equals(Version.V_0_90_0_Beta1) || - v.equals(Version.V_1_2_0)) continue; + if (v.equals(Version.V_1_2_0)) continue; expectedVersions.add("index-" + v.toString() + ".zip"); } diff --git a/src/test/java/org/elasticsearch/index/codec/postingformat/Elasticsearch090RWPostingsFormat.java b/src/test/java/org/elasticsearch/index/codec/postingformat/Elasticsearch090RWPostingsFormat.java index 39ba13f363c..444dfbd28b4 100644 --- a/src/test/java/org/elasticsearch/index/codec/postingformat/Elasticsearch090RWPostingsFormat.java +++ b/src/test/java/org/elasticsearch/index/codec/postingformat/Elasticsearch090RWPostingsFormat.java @@ -23,10 +23,13 @@ import com.google.common.base.Predicates; import com.google.common.collect.Iterators; import org.apache.lucene.codecs.FieldsConsumer; +import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.index.Fields; import org.apache.lucene.index.FilterLeafReader; import org.apache.lucene.index.SegmentWriteState; +import org.elasticsearch.common.util.BloomFilter; import org.elasticsearch.index.codec.postingsformat.BloomFilterPostingsFormat.BloomFilteredFieldsConsumer; +import org.elasticsearch.index.codec.postingsformat.BloomFilterPostingsFormat; import org.elasticsearch.index.codec.postingsformat.Elasticsearch090PostingsFormat; import org.elasticsearch.index.mapper.internal.UidFieldMapper; @@ -37,7 +40,13 @@ import java.util.Iterator; public class Elasticsearch090RWPostingsFormat extends Elasticsearch090PostingsFormat { @Override public FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException { - final BloomFilteredFieldsConsumer fieldsConsumer = bloomPostings.fieldsConsumer(state); + final PostingsFormat delegate = getDefaultWrapped(); + final BloomFilteredFieldsConsumer fieldsConsumer = new BloomFilterPostingsFormat(delegate, BloomFilter.Factory.DEFAULT) { + @Override + public BloomFilteredFieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException { + return new BloomFilteredFieldsConsumer(delegate.fieldsConsumer(state), state,delegate); + } + }.fieldsConsumer(state); return new FieldsConsumer() { @Override