-
Notifications
You must be signed in to change notification settings - Fork 18
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
Custom Codecs Upgrade to Lucene99 Codec #95
Closed
sarthakaggarwal97
wants to merge
2
commits into
opensearch-project:main
from
sarthakaggarwal97:lucene-99-upgrade-test
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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
94 changes: 94 additions & 0 deletions
94
...ain/java/org/opensearch/index/codec/customcodecs/backward_codecs/Lucene95CustomCodec.java
This file contains 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,94 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.codec.customcodecs.backward_codecs; | ||
|
||
import org.apache.lucene.codecs.FilterCodec; | ||
import org.apache.lucene.codecs.StoredFieldsFormat; | ||
import org.apache.lucene.backward_codecs.lucene95.Lucene95Codec; | ||
import org.opensearch.index.codec.customcodecs.Lucene99CustomStoredFieldsFormat; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
/** | ||
* | ||
* Extends {@link FilterCodec} to reuse the functionality of Lucene Codec. | ||
* Supports two modes zstd and zstd_no_dict. | ||
* Uses Lucene95 as the delegate codec | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public abstract class Lucene95CustomCodec extends FilterCodec { | ||
|
||
/** Default compression level used for compression */ | ||
public static final int DEFAULT_COMPRESSION_LEVEL = 3; | ||
|
||
/** Each mode represents a compression algorithm. */ | ||
public enum Mode { | ||
/** | ||
* ZStandard mode with dictionary | ||
*/ | ||
ZSTD("ZSTD", Set.of("zstd")), | ||
/** | ||
* ZStandard mode without dictionary | ||
*/ | ||
ZSTD_NO_DICT("ZSTDNODICT", Set.of("zstd_no_dict")), | ||
/** | ||
* Deprecated ZStandard mode, added for backward compatibility to support indices created in 2.9.0 where | ||
* both ZSTD and ZSTD_NO_DICT used Lucene95CustomCodec underneath. This should not be used to | ||
* create new indices. | ||
*/ | ||
ZSTD_DEPRECATED("Lucene95CustomCodec", Collections.emptySet()); | ||
|
||
private final String codec; | ||
private final Set<String> aliases; | ||
|
||
Mode(String codec, Set<String> aliases) { | ||
this.codec = codec; | ||
this.aliases = aliases; | ||
} | ||
|
||
/** | ||
* Returns the Codec that is registered with Lucene | ||
*/ | ||
public String getCodec() { | ||
return codec; | ||
} | ||
|
||
/** | ||
* Returns the aliases of the Codec | ||
*/ | ||
public Set<String> getAliases() { | ||
return aliases; | ||
} | ||
} | ||
|
||
private final StoredFieldsFormat storedFieldsFormat; | ||
|
||
/** | ||
* Creates a new compression codec. | ||
* | ||
* @param mode The compression codec (ZSTD or ZSTDNODICT). | ||
*/ | ||
|
||
public Lucene95CustomCodec(Mode mode) { | ||
super(mode.getCodec(), new Lucene95Codec()); | ||
this.storedFieldsFormat = new Lucene99CustomStoredFieldsFormat(); | ||
} | ||
|
||
@Override | ||
public StoredFieldsFormat storedFieldsFormat() { | ||
return storedFieldsFormat; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName(); | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarthakaggarwal97 I don't think we should approach codec backward compatibility this way - it will cause an explosion of compression codecs. Ideally, we should be able:
The codec name stays the same
zstd
/zstdnodict
. @msfroh does it make sense (from Apache Lucene perspective)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reta I was initially not planning to introduce new codecs. I was looking to extend the current ZSTD and ZSTD_NO_DICT codecs from Lucene99 instead of Lucene95, and finally read the stored fields using the same Lucene95CustomStoredFieldsFormat, but I started to run into problems.
This initial approach worked well to ensure that we are now indexing and reading the newly created segments with Lucene99 codec in the background, but upon reading the older segments (created with zstandard in <OSv2.12), things started to fail.
We would see the shards are getting unassigned upon recovery with the exception
Even though the codecs name were same, we would still see the recovery to fail. The only difference was that instead of Lucene95 as the delegate codec, we were using Lucene99 as the delegate codec. It should have worked since even with Lucene99, lucene is still relying on the Lucene90StoredFieldsFormat.
So what changed?
There was a slight change in the way we parse the segments in Lucene95 and Lucene99.
This comparison can be viewed over here: https://editor.mergely.com/Mb1lKm8z
There is an additional call to readbyte in the Lucene99SegmentInfoFormat, post which we see EOF exception if we try to read the old segments with Lucene99SegmentInfoFormat.
It was in this commit where this change in format and how we parse the segments was introduced: apache/lucene@6677109
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, it definitely makes sense, I was confused a bit why we have to duplicate
Mode
for each codec, but looking into code it is clear - we use it as codec name, so what you've implemented makes perfect sense. Thanks @sarthakaggarwal97 !