Skip to content

Commit 2ca8a9f

Browse files
committed
Update after review
1 parent 3ebc9f4 commit 2ca8a9f

File tree

9 files changed

+101
-20
lines changed

9 files changed

+101
-20
lines changed

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/BWCCodec.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@
4343
*/
4444
public abstract class BWCCodec extends Codec {
4545

46+
protected FieldInfosFormat fieldInfosFormat;
47+
protected SegmentInfoFormat segmentInfosFormat;
48+
4649
protected BWCCodec(String name) {
4750
super(name);
51+
this.fieldInfosFormat = wrappedFieldInfosFormat();
52+
this.segmentInfosFormat = wrappedSegmentInfoFormat();
4853
}
4954

5055
protected final PostingsFormat postingsFormat = new PerFieldPostingsFormat() {
@@ -69,32 +74,40 @@ public final KnnVectorsFormat knnVectorsFormat() {
6974
throw new UnsupportedOperationException();
7075
}
7176

72-
protected static SegmentInfoFormat wrap(SegmentInfoFormat wrapped) {
77+
protected abstract SegmentInfoFormat setSegmentInfoFormat();
78+
79+
protected final SegmentInfoFormat wrappedSegmentInfoFormat() {
7380
return new SegmentInfoFormat() {
81+
final SegmentInfoFormat wrappedFormat = setSegmentInfoFormat();
82+
7483
@Override
7584
public SegmentInfo read(Directory directory, String segmentName, byte[] segmentID, IOContext context) throws IOException {
76-
return wrap(wrapped.read(directory, segmentName, segmentID, context));
85+
return wrap(wrappedFormat.read(directory, segmentName, segmentID, context));
7786
}
7887

7988
@Override
8089
public void write(Directory dir, SegmentInfo info, IOContext ioContext) throws IOException {
81-
wrapped.write(dir, info, ioContext);
90+
wrappedFormat.write(dir, info, ioContext);
8291
}
8392
};
8493
}
8594

86-
protected static FieldInfosFormat wrap(FieldInfosFormat wrapped) {
95+
protected abstract FieldInfosFormat setFieldInfosFormat();
96+
97+
protected final FieldInfosFormat wrappedFieldInfosFormat() {
8798
return new FieldInfosFormat() {
99+
final FieldInfosFormat wrappedFormat = setFieldInfosFormat();
100+
88101
@Override
89102
public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext)
90103
throws IOException {
91-
return filterFields(wrapped.read(directory, segmentInfo, segmentSuffix, iocontext));
104+
return filterFields(wrappedFormat.read(directory, segmentInfo, segmentSuffix, iocontext));
92105
}
93106

94107
@Override
95108
public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context)
96109
throws IOException {
97-
wrapped.write(directory, segmentInfo, segmentSuffix, infos, context);
110+
wrappedFormat.write(directory, segmentInfo, segmentSuffix, infos, context);
98111
}
99112
};
100113
}

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene60/Lucene60Codec.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,17 @@
4747
*/
4848
@Deprecated
4949
public class Lucene60Codec extends BWCCodec {
50-
private final FieldInfosFormat fieldInfosFormat = wrap(new Lucene60FieldInfosFormat());
51-
private final SegmentInfoFormat segmentInfosFormat = wrap(new Lucene50SegmentInfoFormat());
50+
51+
@Override
52+
protected FieldInfosFormat setFieldInfosFormat() {
53+
return new Lucene60FieldInfosFormat();
54+
}
55+
56+
@Override
57+
protected SegmentInfoFormat setSegmentInfoFormat() {
58+
return new Lucene50SegmentInfoFormat();
59+
}
60+
5261
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
5362
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
5463
private final StoredFieldsFormat storedFieldsFormat;

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene62/Lucene62Codec.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,17 @@
4747
*/
4848
@Deprecated
4949
public class Lucene62Codec extends BWCCodec {
50-
private final FieldInfosFormat fieldInfosFormat = wrap(new Lucene60FieldInfosFormat());
51-
private final SegmentInfoFormat segmentInfosFormat = wrap(new Lucene62SegmentInfoFormat());
50+
51+
@Override
52+
protected FieldInfosFormat setFieldInfosFormat() {
53+
return new Lucene60FieldInfosFormat();
54+
}
55+
56+
@Override
57+
protected SegmentInfoFormat setSegmentInfoFormat() {
58+
return new Lucene62SegmentInfoFormat();
59+
}
60+
5261
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
5362
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
5463
private final StoredFieldsFormat storedFieldsFormat;

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene70/BWCLucene70Codec.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@
3232
*/
3333
public class BWCLucene70Codec extends BWCCodec {
3434

35-
private final FieldInfosFormat fieldInfosFormat = wrap(new Lucene60FieldInfosFormat());
36-
private final SegmentInfoFormat segmentInfosFormat = wrap(new Lucene70SegmentInfoFormat());
35+
@Override
36+
protected FieldInfosFormat setFieldInfosFormat() {
37+
return new Lucene60FieldInfosFormat();
38+
}
39+
40+
@Override
41+
protected SegmentInfoFormat setSegmentInfoFormat() {
42+
return new Lucene70SegmentInfoFormat();
43+
}
44+
3745
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
3846
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
3947
private final StoredFieldsFormat storedFieldsFormat;

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene80/BWCLucene80Codec.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@
3131
*/
3232
public class BWCLucene80Codec extends BWCCodec {
3333

34-
private final FieldInfosFormat fieldInfosFormat = wrap(new Lucene60FieldInfosFormat());
35-
private final SegmentInfoFormat segmentInfosFormat = wrap(new Lucene70SegmentInfoFormat());
34+
@Override
35+
protected FieldInfosFormat setFieldInfosFormat() {
36+
return new Lucene60FieldInfosFormat();
37+
}
38+
39+
@Override
40+
protected SegmentInfoFormat setSegmentInfoFormat() {
41+
return new Lucene70SegmentInfoFormat();
42+
}
43+
3644
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
3745
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
3846

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene84/BWCLucene84Codec.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,16 @@
3333
*/
3434
public class BWCLucene84Codec extends BWCCodec {
3535

36-
private final FieldInfosFormat fieldInfosFormat = wrap(new Lucene60FieldInfosFormat());
37-
private final SegmentInfoFormat segmentInfosFormat = wrap(new Lucene70SegmentInfoFormat());
36+
@Override
37+
protected FieldInfosFormat setFieldInfosFormat() {
38+
return new Lucene60FieldInfosFormat();
39+
}
40+
41+
@Override
42+
protected SegmentInfoFormat setSegmentInfoFormat() {
43+
return new Lucene70SegmentInfoFormat();
44+
}
45+
3846
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
3947
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
4048
private final PostingsFormat defaultFormat;

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene86/BWCLucene86Codec.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@
3232
*/
3333
public class BWCLucene86Codec extends BWCCodec {
3434

35-
private final FieldInfosFormat fieldInfosFormat = wrap(new Lucene60FieldInfosFormat());
36-
private final SegmentInfoFormat segmentInfosFormat = wrap(new Lucene86SegmentInfoFormat());
35+
@Override
36+
protected FieldInfosFormat setFieldInfosFormat() {
37+
return new Lucene60FieldInfosFormat();
38+
}
39+
40+
@Override
41+
protected SegmentInfoFormat setSegmentInfoFormat() {
42+
return new Lucene86SegmentInfoFormat();
43+
}
44+
3745
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
3846
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
3947
private final PointsFormat pointsFormat = new Lucene86MetadataOnlyPointsFormat();

x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/codecs/lucene87/BWCLucene87Codec.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,16 @@ private enum Mode {
5353
}
5454
}
5555

56-
private final FieldInfosFormat fieldInfosFormat = wrap(new Lucene60FieldInfosFormat());
57-
private final SegmentInfoFormat segmentInfosFormat = wrap(new Lucene86SegmentInfoFormat());
56+
@Override
57+
protected FieldInfosFormat setFieldInfosFormat() {
58+
return new Lucene60FieldInfosFormat();
59+
}
60+
61+
@Override
62+
protected SegmentInfoFormat setSegmentInfoFormat() {
63+
return new Lucene86SegmentInfoFormat();
64+
}
65+
5866
private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();
5967
private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();
6068
private final PointsFormat pointsFormat = new Lucene86MetadataOnlyPointsFormat();

x-pack/plugin/old-lucene-versions/src/test/java/org/elasticsearch/xpack/lucene/bwc/codecs/BWCCodecTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ public class BWCCodecTests extends ESTestCase {
2424

2525
public BWCCodecTests() {
2626
this.codec = new BWCCodec("WrapperCodec") {
27+
@Override
28+
protected SegmentInfoFormat setSegmentInfoFormat() {
29+
return null;
30+
}
31+
32+
@Override
33+
protected FieldInfosFormat setFieldInfosFormat() {
34+
return null;
35+
}
36+
2737
@Override
2838
public PostingsFormat postingsFormat() {
2939
return null;

0 commit comments

Comments
 (0)