Skip to content

Commit

Permalink
experimental codec support
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Jun 5, 2024
1 parent 39ae32a commit 14ee1c0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
*/
public interface CodecSettings {
boolean supports(Setting<?> setting);

boolean experimental();
}
23 changes: 21 additions & 2 deletions server/src/main/java/org/opensearch/index/engine/EngineConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,19 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() {
return s;
default:
if (Codec.availableCodecs().contains(s)) {
return s;
if (!isExperimentalCodec(Codec.forName(s))) {
return s;
}
}

for (String codecName : Codec.availableCodecs()) {
Codec codec = Codec.forName(codecName);
if (codec instanceof CodecAliases) {
CodecAliases codecWithAlias = (CodecAliases) codec;
if (codecWithAlias.aliases().contains(s)) {
return s;
if (!isExperimentalCodec(codec)) {
return s;
}
}
}
}
Expand All @@ -159,6 +163,21 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() {
}
}, Property.IndexScope, Property.NodeScope);

static boolean isExperimentalCodec(Codec codec) {
if (codec instanceof CodecSettings) {
CodecSettings codecWithSettings = (CodecSettings) codec;
if (!codecWithSettings.experimental()) {
return false;
} else {
throw new IllegalArgumentException(
"experimental codecs are not enabled. value for [index.codec] must be one of [default, lz4, best_compression, zlib] but was: "
+ codec.getName()
);
}
}
return false;
}

/**
* Index setting to change the compression level of zstd and zstd_no_dict lucene codecs.
* Compression Level gives a trade-off between compression ratio and speed. The higher compression level results in higher compression ratio but slower compression and decompression speeds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

package org.opensearch.index.engine;

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.lucene99.Lucene99Codec;
import org.opensearch.Version;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.codec.CodecSettings;
import org.opensearch.index.seqno.RetentionLeases;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.test.IndexSettingsModule;
Expand Down Expand Up @@ -68,4 +73,33 @@ private EngineConfig createReadOnlyEngine(IndexSettings indexSettings) {
.readOnlyReplica(true)
.build();
}

public void testExperimentalCodecs() throws Exception {
class ExperimentalCodec extends FilterCodec implements CodecSettings {

final boolean isExperimental;

protected ExperimentalCodec(String name, Codec delegate, boolean isExperimental) {
super(name, delegate);
this.isExperimental = isExperimental;
}

@Override
public boolean supports(Setting<?> setting) {
return false;
}

@Override
public boolean experimental() {
return isExperimental;
}
}
final IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> EngineConfig.isExperimentalCodec(new ExperimentalCodec("experimentalcodec", new Lucene99Codec(), true))
);
assertTrue(e.getMessage().startsWith("experimental codecs are not enabled."));
assertFalse(EngineConfig.isExperimentalCodec(new ExperimentalCodec("nonexperimentalcodec", new Lucene99Codec(), false)));
}

}

0 comments on commit 14ee1c0

Please sign in to comment.