Skip to content

Commit 2544a22

Browse files
authored
Remove write logic from Lucene70NormsFormat. (#2287)
Our policy is to not maintain write logic for old formats that can't be written to. The write logic is moved to the test folder to support unit testing.
1 parent 902ce08 commit 2544a22

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70Codec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public final DocValuesFormat docValuesFormat() {
134134
private final NormsFormat normsFormat = new Lucene70NormsFormat();
135135

136136
@Override
137-
public final NormsFormat normsFormat() {
137+
public NormsFormat normsFormat() {
138138
return normsFormat;
139139
}
140140
}

lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70NormsFormat.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ public Lucene70NormsFormat() {}
8787

8888
@Override
8989
public NormsConsumer normsConsumer(SegmentWriteState state) throws IOException {
90-
return new Lucene70NormsConsumer(
91-
state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION);
90+
throw new UnsupportedOperationException("Old codecs may only be used for reading");
9291
}
9392

9493
@Override
@@ -97,10 +96,10 @@ public NormsProducer normsProducer(SegmentReadState state) throws IOException {
9796
state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION);
9897
}
9998

100-
private static final String DATA_CODEC = "Lucene70NormsData";
101-
private static final String DATA_EXTENSION = "nvd";
102-
private static final String METADATA_CODEC = "Lucene70NormsMetadata";
103-
private static final String METADATA_EXTENSION = "nvm";
99+
static final String DATA_CODEC = "Lucene70NormsData";
100+
static final String DATA_EXTENSION = "nvd";
101+
static final String METADATA_CODEC = "Lucene70NormsMetadata";
102+
static final String METADATA_EXTENSION = "nvm";
104103
static final int VERSION_START = 0;
105104
static final int VERSION_CURRENT = VERSION_START;
106105
}
File renamed without changes.

lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/Lucene70RWCodec.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.lucene.backward_codecs.lucene50.Lucene50RWPostingsFormat;
2020
import org.apache.lucene.backward_codecs.lucene50.Lucene50RWStoredFieldsFormat;
21+
import org.apache.lucene.codecs.NormsFormat;
2122
import org.apache.lucene.codecs.PostingsFormat;
2223
import org.apache.lucene.codecs.SegmentInfoFormat;
2324
import org.apache.lucene.codecs.StoredFieldsFormat;
@@ -43,6 +44,11 @@ public SegmentInfoFormat segmentInfoFormat() {
4344
return new Lucene70RWSegmentInfoFormat();
4445
}
4546

47+
@Override
48+
public NormsFormat normsFormat() {
49+
return new Lucene70RWNormsFormat();
50+
}
51+
4652
@Override
4753
public StoredFieldsFormat storedFieldsFormat() {
4854
return new Lucene50RWStoredFieldsFormat();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.lucene.backward_codecs.lucene70;
18+
19+
import java.io.IOException;
20+
import org.apache.lucene.codecs.NormsConsumer;
21+
import org.apache.lucene.index.SegmentWriteState;
22+
23+
public class Lucene70RWNormsFormat extends Lucene70NormsFormat {
24+
25+
@Override
26+
public NormsConsumer normsConsumer(SegmentWriteState state) throws IOException {
27+
return new Lucene70NormsConsumer(
28+
state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION);
29+
}
30+
}

0 commit comments

Comments
 (0)