Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-16442: upgrade to Lucene 9.4 (do and document) #1056

Merged
merged 13 commits into from
Oct 19, 2022
93 changes: 93 additions & 0 deletions dev-docs/lucene-upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

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
limitations under the License.
-->

# Lucene upgrade steps

## Read

https://lucene.apache.org/core/9_4_0/MIGRATE.html

## Start

Create a new branch locally e.g. `git checkout -b lucene940 -t origin/main` for upgrading to Lucene 9.4.0 version.

## Build

### `versions.props` update

```
- org.apache.lucene:*=9.3.0
+ org.apache.lucene:*=9.4.0
```

### `versions.lock` update

```
gradlew --write-locks
```

### `solr/licenses` update

```
git rm lucene-*-9.3.0.jar.sha1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./gradlew updateLicenses will handle this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! #1087 to simplify the docs (and I'll leave that PR open for a few days in case of additional documentation feedback)


# ???manually get new .sha1 files???

git add lucene-*-9.4.0.jar.sha1
```

## Code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets read upgrading notes provided by Lucene first; ehh?
https://lucene.apache.org/core/9_4_0/MIGRATE.html

```
gradlew compileJava
```

* adjust for signature changes e.g.
* `int` to `long` type change
* additional or removed constructor arguments
* additional abstract base class or interface methods
* inner classes becoming outer classes
* codec changes (if any)
* conceptually `s/org.apache.lucene.codecs.lucene9x.Lucene9x/org.apache.lucene.codecs.lucene94.Lucene94`

## Test

```
gradlew compileTestJava
```

```
gradlew precommit
```

```
gradlew test
```

## Documentation

### `solr/solr-ref-guide/antora.yml` update

```
- lucene-javadocs: 'https://lucene.apache.org/core/9_3_0'
+ lucene-javadocs: 'https://lucene.apache.org/core/9_4_0'
```

## Finish

Push the local branch to github (fork) and open a pull request.

Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@
* <li>unmap -- See {@link MMapDirectory#setUseUnmap(boolean)}
* <li>preload -- See {@link MMapDirectory#setPreload(boolean)}
* <li>maxChunkSize -- The Max chunk size. See {@link MMapDirectory#MMapDirectory(Path,
* LockFactory, int)}
* LockFactory, long)}
* </ul>
*/
public class MMapDirectoryFactory extends StandardDirectoryFactory {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
boolean unmapHack;
boolean preload;
private int maxChunk;
private long maxChunk;

@Override
public void init(NamedList<?> args) {
super.init(args);
SolrParams params = args.toSolrParams();
maxChunk = params.getInt("maxChunkSize", MMapDirectory.DEFAULT_MAX_CHUNK_SIZE);
maxChunk = params.getLong("maxChunkSize", MMapDirectory.DEFAULT_MAX_CHUNK_SIZE);
Comment on lines -40 to +53
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (maxChunk <= 0) {
throw new IllegalArgumentException("maxChunk must be greater than 0");
}
Expand Down
10 changes: 5 additions & 5 deletions solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.KnnVectorsFormat;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.lucene92.Lucene92Codec;
import org.apache.lucene.codecs.lucene92.Lucene92Codec.Mode;
import org.apache.lucene.codecs.lucene92.Lucene92HnswVectorsFormat;
cpoerschke marked this conversation as resolved.
Show resolved Hide resolved
import org.apache.lucene.codecs.lucene94.Lucene94Codec;
import org.apache.lucene.codecs.lucene94.Lucene94Codec.Mode;
import org.apache.lucene.codecs.lucene94.Lucene94HnswVectorsFormat;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.util.NamedList;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void init(NamedList<?> args) {
log.debug("Using default compressionMode: {}", compressionMode);
}
codec =
new Lucene92Codec(compressionMode) {
new Lucene94Codec(compressionMode) {
@Override
public PostingsFormat getPostingsFormatForField(String field) {
final SchemaField schemaField = core.getLatestSchema().getFieldOrNull(field);
Expand Down Expand Up @@ -128,7 +128,7 @@ public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
if (knnAlgorithm.equals(DenseVectorField.HNSW_ALGORITHM)) {
int maxConn = vectorType.getHnswMaxConn();
int beamWidth = vectorType.getHnswBeamWidth();
return new Lucene92HnswVectorsFormat(maxConn, beamWidth);
return new Lucene94HnswVectorsFormat(maxConn, beamWidth);
}
} else {
throw new SolrException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.apache.solr.schema;

import static java.util.Optional.ofNullable;
import static org.apache.lucene.codecs.lucene92.Lucene92HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
import static org.apache.lucene.codecs.lucene92.Lucene92HnswVectorsFormat.DEFAULT_MAX_CONN;
import static org.apache.lucene.codecs.lucene94.Lucene94HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
import static org.apache.lucene.codecs.lucene94.Lucene94HnswVectorsFormat.DEFAULT_MAX_CONN;

import java.util.ArrayList;
import java.util.List;
Expand Down
6 changes: 6 additions & 0 deletions solr/core/src/java/org/apache/solr/schema/SchemaField.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.IndexableFieldType;
import org.apache.lucene.index.VectorEncoding;
import org.apache.lucene.index.VectorSimilarityFunction;
import org.apache.lucene.search.SortField;
import org.apache.solr.common.SolrException;
Expand Down Expand Up @@ -548,6 +549,11 @@ public int vectorDimension() {
return 0;
}

@Override
public VectorEncoding vectorEncoding() {
return VectorEncoding.BYTE;
}

Comment on lines +552 to +556
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Override
public VectorSimilarityFunction vectorSimilarityFunction() {
return VectorSimilarityFunction.EUCLIDEAN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ private static class ReaderWrapper extends FilterLeafReader {
fieldInfo.getPointIndexDimensionCount(),
fieldInfo.getPointNumBytes(),
fieldInfo.getVectorDimension(),
fieldInfo.getVectorEncoding(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fieldInfo.getVectorSimilarityFunction(),
fieldInfo.isSoftDeletesField());
newInfos.add(f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private NumericHidingLeafReader(LeafReader in, String field) {
fi.getPointIndexDimensionCount(),
fi.getPointNumBytes(),
fi.getVectorDimension(),
fi.getVectorEncoding(),
fi.getVectorSimilarityFunction(),
fi.isSoftDeletesField()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public static LeafReader wrap(LeafReader in, Function<String, Type> mapping) {
fi.getPointIndexDimensionCount(),
fi.getPointNumBytes(),
fi.getVectorDimension(),
fi.getVectorEncoding(),
fi.getVectorSimilarityFunction(),
fi.isSoftDeletesField()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.io.IOException;
import java.util.Map;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.lucene92.Lucene92Codec.Mode;
import org.apache.lucene.codecs.lucene94.Lucene94Codec.Mode;
import org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat;
import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;
import org.apache.lucene.index.SegmentInfo;
Expand Down
1 change: 0 additions & 1 deletion solr/licenses/lucene-analysis-common-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-analysis-common-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
02fbd4e87241411fcf5d34e92a50bee46ab164dc
1 change: 0 additions & 1 deletion solr/licenses/lucene-analysis-icu-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-analysis-icu-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aa0f250558375922f3091820361156e514fe1842
1 change: 0 additions & 1 deletion solr/licenses/lucene-analysis-kuromoji-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-analysis-kuromoji-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
32eb1ad367ab1289804aeed95ea7216711a7764d
1 change: 0 additions & 1 deletion solr/licenses/lucene-analysis-morfologik-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-analysis-morfologik-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
13e1ae2c760d8c0d7990ffe3296e46d9d8e6f842
1 change: 0 additions & 1 deletion solr/licenses/lucene-analysis-nori-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-analysis-nori-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
63661714be65f882a921d281965b0779fd487b90
1 change: 0 additions & 1 deletion solr/licenses/lucene-analysis-opennlp-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-analysis-opennlp-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c0ca97d8f89e674084b44240d587453cf5df8670
1 change: 0 additions & 1 deletion solr/licenses/lucene-analysis-phonetic-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-analysis-phonetic-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1034d876551fc21f7835b456dab01db21b9a4af6
1 change: 0 additions & 1 deletion solr/licenses/lucene-analysis-smartcn-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-analysis-smartcn-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f704ee4b14e2fe2622bb983f04b36a32df8fd4a7
1 change: 0 additions & 1 deletion solr/licenses/lucene-analysis-stempel-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-analysis-stempel-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a95ff17b51da6b3da641fa4053e5ee9ea2ff5daf
1 change: 0 additions & 1 deletion solr/licenses/lucene-backward-codecs-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-backward-codecs-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
259863dfd107645de6146b3c87b4ecee66a4d43d
1 change: 0 additions & 1 deletion solr/licenses/lucene-classification-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-classification-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
35fb746cbfc8a36264a2e6352294d8a45c9006fe
1 change: 0 additions & 1 deletion solr/licenses/lucene-codecs-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-codecs-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5c9d00dbe95e88980938f20be1e130070dd03b3a
1 change: 0 additions & 1 deletion solr/licenses/lucene-core-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-core-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cca1116f813c0f0c63acfac4c952baf29d46d76b
1 change: 0 additions & 1 deletion solr/licenses/lucene-expressions-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-expressions-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
19749e264805171009836cbedecc5494b13cd920
1 change: 0 additions & 1 deletion solr/licenses/lucene-grouping-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-grouping-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
51bec1d5acc8ecaf9f50e047d3f86d60c7a958f4
1 change: 0 additions & 1 deletion solr/licenses/lucene-highlighter-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-highlighter-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c8cf8c9308d8fb18a927c7ed267a14ace3990a5f
1 change: 0 additions & 1 deletion solr/licenses/lucene-join-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-join-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
99b2d3c8e137a6853a2503456897d47d4f18974b
1 change: 0 additions & 1 deletion solr/licenses/lucene-memory-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-memory-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
881cb214e79da14de35cb0e8e6779d2722828a96
1 change: 0 additions & 1 deletion solr/licenses/lucene-misc-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-misc-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a126123e482e6bf2e7aea670d221a2a39d3277dc
1 change: 0 additions & 1 deletion solr/licenses/lucene-queries-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-queries-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe74dbfe9dba9ee9ee2cb80f151fde97fb4efd12
1 change: 0 additions & 1 deletion solr/licenses/lucene-queryparser-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-queryparser-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
13f108a8572fcf0670c7df3ba8dbe1076d0e0dbe
1 change: 0 additions & 1 deletion solr/licenses/lucene-sandbox-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-sandbox-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e7a676a12ea50dcbf64564f4e4022f939f0a627d
1 change: 0 additions & 1 deletion solr/licenses/lucene-spatial-extras-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-spatial-extras-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
84d956d1cb1458c51967af1c4acadd2a1f92634d
1 change: 0 additions & 1 deletion solr/licenses/lucene-spatial3d-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-spatial3d-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
76887ca708f23b13613e45fb9e307c548b22c6da
1 change: 0 additions & 1 deletion solr/licenses/lucene-suggest-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-suggest-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
406c9c539f262449d3b1e57e7bc4302efeecaf6c
1 change: 0 additions & 1 deletion solr/licenses/lucene-test-framework-9.3.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions solr/licenses/lucene-test-framework-9.4.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5f13400741a511fd4ba48e64d5637fb0a8b1bd7a
2 changes: 1 addition & 1 deletion solr/server/solr/configsets/_default/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
that you fully re-index after changing this setting as it can
affect both how text is indexed and queried.
-->
<luceneMatchVersion>9.3</luceneMatchVersion>
<luceneMatchVersion>9.4</luceneMatchVersion>

<!-- <lib/> directives can be used to instruct Solr to load any Jars
identified and use them to resolve any "plugins" specified in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
that you fully re-index after changing this setting as it can
affect both how text is indexed and queried.
-->
<luceneMatchVersion>9.3</luceneMatchVersion>
<luceneMatchVersion>9.4</luceneMatchVersion>

<!-- <lib/> directives can be used to instruct Solr to load any Jars
identified and use them to resolve any "plugins" specified in
Expand Down
2 changes: 1 addition & 1 deletion solr/solr-ref-guide/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ asciidoc:
# 'patch-version' is the 'z' part of x.y.z semantic version
page-solr-javadocs: 'https://solr.apache.org/docs/10_0_0'
solr-javadocs: 'https://solr.apache.org/docs/10_0_0'
lucene-javadocs: 'https://lucene.apache.org/core/9_3_0'
lucene-javadocs: 'https://lucene.apache.org/core/9_4_0'
java-javadocs: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/
# Some constructed links may be 404 TODO to check
solr-docs-version: '10.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.FieldComparatorSource;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.comparators.TermOrdValComparator;
Comment on lines -26 to +28
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import org.apache.lucene.util.BytesRef;

/** Custom field representing a {@link BinaryField} that's sortable. */
Expand Down Expand Up @@ -70,12 +70,14 @@ public BinarySortField(final String field, final boolean reverse) {
field,
new FieldComparatorSource() {
@Override
public FieldComparator.TermOrdValComparator newComparator(
public TermOrdValComparator newComparator(
final String fieldname,
final int numHits,
final boolean enableSkipping,
final boolean reversed) {
return new FieldComparator.TermOrdValComparator(numHits, fieldname);
final boolean sortMissingLast = false;
return new TermOrdValComparator(
numHits, fieldname, sortMissingLast, reversed, enableSkipping);
}
},
reverse);
Expand Down