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

Make index.codec setting case-insensitive. #7171

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.opensearch.index.mapper.MapperService;

import java.util.Map;
import java.util.TreeMap;

/**
* Since Lucene 4.0 low level index segments are read and written through a
Expand Down Expand Up @@ -72,7 +73,8 @@ public CodecService(@Nullable MapperService mapperService, Logger logger) {
for (String codec : Codec.availableCodecs()) {
codecs.put(codec, Codec.forName(codec));
}
this.codecs = codecs.immutableMap();
this.codecs = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
this.codecs.putAll(codecs.map());
}

public Codec codec(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.opensearch.threadpool.ThreadPool;

import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.function.BooleanSupplier;
import java.util.function.LongSupplier;
Expand Down Expand Up @@ -123,15 +124,19 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() {
* allocated on both `kind` of nodes.
*/
public static final Setting<String> INDEX_CODEC_SETTING = new Setting<>("index.codec", "default", s -> {
switch (s) {
switch (s.toLowerCase(Locale.ROOT)) {
case "default":
case "best_compression":
case "lucene_default":
return s;
default:
if (Codec.availableCodecs().contains(s) == false) { // we don't error message the not officially supported ones
if (!Codec.availableCodecs().stream().anyMatch(c -> c.equalsIgnoreCase(s))) { // we don't error message the not
mulugetam marked this conversation as resolved.
Show resolved Hide resolved
// officially supported ones
throw new IllegalArgumentException(
"unknown value for [index.codec] must be one of [default, best_compression] but was: " + s
"unknown value for [index.codec] must be one of [default, best_compression, lucene_default] or "
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're allowing for users to set it to lucene_default and/or one of the listed available codecs (Lucene80, Lucene70, etc), this needs to be documented on the static settings for index creation for index.codec setting.

Ref: https://opensearch.org/docs/2.4/api-reference/index-apis/create-index/#static-index-settings

+ Codec.availableCodecs()
+ " but was: "
+ s
);
}
return s;
Expand Down