-
Notifications
You must be signed in to change notification settings - Fork 25.2k
lucene_snapshot: Update to new Lucene 10.3 postings format #128240
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
Merged
ChrisHegarty
merged 15 commits into
elastic:lucene_snapshot
from
ChrisHegarty:new_103_postings_format
May 23, 2025
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
60b9f59
lucene_snapshot: Update to new Lucene 10.3 postings format
ChrisHegarty 4e691db
itr
ChrisHegarty efffda5
fix hints
ChrisHegarty 288f4f6
Merge branch 'lucene_snapshot' into new_103_postings_format
ChrisHegarty 1478c8a
fix direct io hints - again
ChrisHegarty 351ba80
rename codec
ChrisHegarty 737d802
Always keep DirectIOHint in the hints
thecoop 12d25c9
remove compression and constant copied code
ChrisHegarty 4c2c3d9
Use the new Elasticsearch92Lucene103Codec
ChrisHegarty 467de1b
fix default postings format - aligned with changes in main
ChrisHegarty e5a37db
fix test
ChrisHegarty f1c4a51
fix test
ChrisHegarty afa5b34
comment
ChrisHegarty c363959
another test fix
ChrisHegarty 34e94cc
DEFAULT_POSTINGS_FORMAT
ChrisHegarty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
server/src/main/java/org/elasticsearch/index/codec/Elasticsearch902Lucene103Codec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.codec; | ||
|
||
import org.apache.lucene.codecs.DocValuesFormat; | ||
import org.apache.lucene.codecs.KnnVectorsFormat; | ||
import org.apache.lucene.codecs.PostingsFormat; | ||
import org.apache.lucene.codecs.StoredFieldsFormat; | ||
import org.apache.lucene.codecs.lucene103.Lucene103Codec; | ||
import org.apache.lucene.codecs.lucene103.Lucene103PostingsFormat; | ||
import org.apache.lucene.codecs.lucene90.Lucene90DocValuesFormat; | ||
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat; | ||
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat; | ||
import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat; | ||
import org.elasticsearch.index.codec.perfield.XPerFieldDocValuesFormat; | ||
import org.elasticsearch.index.codec.zstd.Zstd814StoredFieldsFormat; | ||
|
||
/** | ||
* Elasticsearch codec as of 9.2 relying on Lucene 10.3. This extends the Lucene 10.3 codec to compressed | ||
* stored fields with ZSTD instead of LZ4/DEFLATE. See {@link Zstd814StoredFieldsFormat}. | ||
*/ | ||
public class Elasticsearch902Lucene103Codec extends CodecService.DeduplicateFieldInfosCodec { | ||
|
||
private final StoredFieldsFormat storedFieldsFormat; | ||
|
||
private final PostingsFormat defaultPostingsFormat; | ||
private final PostingsFormat postingsFormat = new PerFieldPostingsFormat() { | ||
@Override | ||
public PostingsFormat getPostingsFormatForField(String field) { | ||
return Elasticsearch902Lucene103Codec.this.getPostingsFormatForField(field); | ||
} | ||
}; | ||
|
||
private final DocValuesFormat defaultDVFormat; | ||
private final DocValuesFormat docValuesFormat = new XPerFieldDocValuesFormat() { | ||
@Override | ||
public DocValuesFormat getDocValuesFormatForField(String field) { | ||
return Elasticsearch902Lucene103Codec.this.getDocValuesFormatForField(field); | ||
} | ||
}; | ||
|
||
private final KnnVectorsFormat defaultKnnVectorsFormat; | ||
private final KnnVectorsFormat knnVectorsFormat = new PerFieldKnnVectorsFormat() { | ||
@Override | ||
public KnnVectorsFormat getKnnVectorsFormatForField(String field) { | ||
return Elasticsearch902Lucene103Codec.this.getKnnVectorsFormatForField(field); | ||
} | ||
}; | ||
|
||
/** Public no-arg constructor, needed for SPI loading at read-time. */ | ||
public Elasticsearch902Lucene103Codec() { | ||
this(Zstd814StoredFieldsFormat.Mode.BEST_SPEED); | ||
} | ||
|
||
/** | ||
* Constructor. Takes a {@link Zstd814StoredFieldsFormat.Mode} that describes whether to optimize for retrieval speed at the expense of | ||
* worse space-efficiency or vice-versa. | ||
*/ | ||
public Elasticsearch902Lucene103Codec(Zstd814StoredFieldsFormat.Mode mode) { | ||
super("Elasticsearch902Lucene103", new Lucene103Codec()); | ||
this.storedFieldsFormat = mode.getFormat(); | ||
this.defaultPostingsFormat = new Lucene103PostingsFormat(); | ||
this.defaultDVFormat = new Lucene90DocValuesFormat(); | ||
this.defaultKnnVectorsFormat = new Lucene99HnswVectorsFormat(); | ||
} | ||
|
||
@Override | ||
public StoredFieldsFormat storedFieldsFormat() { | ||
return storedFieldsFormat; | ||
} | ||
|
||
@Override | ||
public final PostingsFormat postingsFormat() { | ||
return postingsFormat; | ||
} | ||
|
||
@Override | ||
public final DocValuesFormat docValuesFormat() { | ||
return docValuesFormat; | ||
} | ||
|
||
@Override | ||
public final KnnVectorsFormat knnVectorsFormat() { | ||
return knnVectorsFormat; | ||
} | ||
|
||
/** | ||
* Returns the postings format that should be used for writing new segments of <code>field</code>. | ||
* | ||
* <p>The default implementation always returns "Lucene912". | ||
* | ||
* <p><b>WARNING:</b> if you subclass, you are responsible for index backwards compatibility: | ||
* future version of Lucene are only guaranteed to be able to read the default implementation, | ||
*/ | ||
public PostingsFormat getPostingsFormatForField(String field) { | ||
return defaultPostingsFormat; | ||
} | ||
|
||
/** | ||
* Returns the docvalues format that should be used for writing new segments of <code>field</code> | ||
* . | ||
* | ||
* <p>The default implementation always returns "Lucene912". | ||
* | ||
* <p><b>WARNING:</b> if you subclass, you are responsible for index backwards compatibility: | ||
* future version of Lucene are only guaranteed to be able to read the default implementation. | ||
*/ | ||
public DocValuesFormat getDocValuesFormatForField(String field) { | ||
return defaultDVFormat; | ||
} | ||
|
||
/** | ||
* Returns the vectors format that should be used for writing new segments of <code>field</code> | ||
* | ||
* <p>The default implementation always returns "Lucene912". | ||
* | ||
* <p><b>WARNING:</b> if you subclass, you are responsible for index backwards compatibility: | ||
* future version of Lucene are only guaranteed to be able to read the default implementation. | ||
*/ | ||
public KnnVectorsFormat getKnnVectorsFormatForField(String field) { | ||
return defaultKnnVectorsFormat; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
server/src/main/java/org/elasticsearch/index/codec/postings/CompressionAlgorithm.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* @notice | ||
* 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. | ||
* | ||
* Modifications copyright (C) 2025 Elasticsearch B.V. | ||
*/ | ||
package org.elasticsearch.index.codec.postings; | ||
|
||
import org.apache.lucene.store.DataInput; | ||
import org.apache.lucene.util.compress.LowercaseAsciiCompression; | ||
|
||
import java.io.IOException; | ||
|
||
/** Compression algorithm used for suffixes of a block of terms. */ | ||
public enum CompressionAlgorithm { | ||
ChrisHegarty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NO_COMPRESSION(0x00) { | ||
|
||
@Override | ||
void read(DataInput in, byte[] out, int len) throws IOException { | ||
in.readBytes(out, 0, len); | ||
} | ||
}, | ||
|
||
LOWERCASE_ASCII(0x01) { | ||
|
||
@Override | ||
void read(DataInput in, byte[] out, int len) throws IOException { | ||
LowercaseAsciiCompression.decompress(in, out, len); | ||
} | ||
}, | ||
|
||
LZ4(0x02) { | ||
|
||
@Override | ||
void read(DataInput in, byte[] out, int len) throws IOException { | ||
org.apache.lucene.util.compress.LZ4.decompress(in, len, out, 0); | ||
} | ||
}; | ||
|
||
private static final CompressionAlgorithm[] BY_CODE = new CompressionAlgorithm[3]; | ||
|
||
static { | ||
for (CompressionAlgorithm alg : CompressionAlgorithm.values()) { | ||
BY_CODE[alg.code] = alg; | ||
} | ||
} | ||
|
||
/** Look up a {@link CompressionAlgorithm} by its {@link CompressionAlgorithm#code}. */ | ||
static CompressionAlgorithm byCode(int code) { | ||
if (code < 0 || code >= BY_CODE.length) { | ||
throw new IllegalArgumentException("Illegal code for a compression algorithm: " + code); | ||
} | ||
return BY_CODE[code]; | ||
} | ||
|
||
public final int code; | ||
|
||
CompressionAlgorithm(int code) { | ||
this.code = code; | ||
} | ||
|
||
abstract void read(DataInput in, byte[] out, int len) throws IOException; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.