Skip to content

Commit

Permalink
reinstating default and best_compression
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Jul 20, 2023
1 parent a6922b6 commit e8703c5
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public class MultiCodecReindexIT extends ReindexTestCase {
public void testReindexingMultipleCodecs() throws InterruptedException, ExecutionException {
internalCluster().ensureAtLeastNumDataNodes(1);
Map<String, String> codecMap = Map.of(
CodecService.ZLIB_CODEC,
CodecType.BEST_COMPRESSION.getName(),
"BEST_COMPRESSION",
CodecService.ZSTD_NO_DICT_CODEC,
CodecType.ZSTD_NO_DICT.getName(),
"ZSTD_NO_DICT",
CodecService.ZSTD_CODEC,
CodecType.ZSTD.getName(),
"ZSTD",
CodecService.LZ4_CODEC,
CodecType.DEFAULT.getName(),
"BEST_SPEED"
);

Expand All @@ -71,7 +71,7 @@ private void assertReindexingWithMultipleCodecs(String destCodec, String destCod
Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.codec", CodecService.LZ4_CODEC)
.put("index.codec", CodecType.DEFAULT.getName())
.put("index.merge.policy.max_merged_segment", "1b")
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public class MultiCodecMergeIT extends OpenSearchIntegTestCase {
public void testForceMergeMultipleCodecs() throws ExecutionException, InterruptedException {

Map<String, String> codecMap = Map.of(
CodecService.ZLIB_CODEC,
CodecType.BEST_COMPRESSION.getName(),
"BEST_COMPRESSION",
CodecService.ZSTD_NO_DICT_CODEC,
CodecType.ZSTD_NO_DICT.getName(),
"ZSTD_NO_DICT",
CodecService.ZSTD_CODEC,
CodecType.ZSTD.getName(),
"ZSTD",
CodecService.LZ4_CODEC,
CodecType.DEFAULT.getName(),
"BEST_SPEED"
);

Expand All @@ -71,7 +71,7 @@ private void forceMergeMultipleCodecs(String finalCodec, String finalCodecMode,
Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.codec", CodecService.LZ4_CODEC)
.put("index.codec", CodecType.DEFAULT.getName())
.put("index.merge.policy.max_merged_segment", "1b")
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ public CodecService(@Nullable MapperService mapperService, IndexSettings indexSe
}
if (mapperService == null) {
codecs.put(CodecType.DEFAULT.getName(), new Lucene95Codec());
codecs.put(CodecType.LZ4.getName(), new Lucene95Codec());
codecs.put(CodecType.BEST_COMPRESSION.getName(), new Lucene95Codec(Mode.BEST_COMPRESSION));
codecs.put(CodecType.ZLIB.getName(), new Lucene95Codec(Mode.BEST_COMPRESSION));
codecs.put(CodecType.ZSTD.getName(), new ZstdCodec(compressionLevel));
codecs.put(CodecType.ZSTD_NO_DICT.getName(), new ZstdNoDictCodec(compressionLevel));
} else {
codecs.put(CodecType.DEFAULT.getName(), new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
codecs.put(CodecType.LZ4.getName(), new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
codecs.put(
CodecType.BEST_COMPRESSION.getName(),
new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger)
);
codecs.put(CodecType.ZLIB.getName(), new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
codecs.put(CodecType.ZSTD.getName(), new ZstdCodec(mapperService, logger, compressionLevel));
codecs.put(CodecType.ZSTD_NO_DICT.getName(), new ZstdNoDictCodec(mapperService, logger, compressionLevel));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
public enum CodecType {

DEFAULT("default", Set.of()),
LZ4("lz4", Set.of()),
BEST_COMPRESSION("best_compression", Set.of()),
ZLIB("zlib", Set.of()),
ZSTD("zstd", Set.of(EngineConfig.INDEX_CODEC_COMPRESSION_LEVEL_SETTING)),
ZSTD_NO_DICT("zstd_no_dict", Set.of(EngineConfig.INDEX_CODEC_COMPRESSION_LEVEL_SETTING)),
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() {
public static final Setting<String> INDEX_CODEC_SETTING = new Setting<>("index.codec", "lz4", s -> {
switch (s) {
case "lz4":
case "default":
case "best_compression":
case "zlib":
case "zstd":
case "zstd_no_dict":
Expand All @@ -139,7 +141,8 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() {
default:
if (Codec.availableCodecs().contains(s) == false) { // we don't error message the not officially supported ones
throw new IllegalArgumentException(
"unknown value for [index.codec] must be one of [lz4, zlib, zstd, zstd_no_dict] but was: " + s
"unknown value for [index.codec] must be one of [default, best_compression, lz4, zlib, zstd, zstd_no_dict] but was: "
+ s
);
}
return s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.hamcrest.Matchers;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.codec.CodecService;
import org.opensearch.index.codec.CodecType;
import org.opensearch.search.SearchService;
import org.opensearch.test.FeatureFlagSetter;

Expand Down Expand Up @@ -74,13 +74,13 @@ public void testValidate() {
}

{
Settings settings = Settings.builder().put("index.codec", CodecService.LZ4_CODEC).put("index.foo.bar", 1).build();
Settings settings = Settings.builder().put("index.codec", CodecType.DEFAULT.getName()).put("index.foo.bar", 1).build();
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> new SettingsModule(settings));
assertEquals("node settings must not contain any index level settings", ex.getMessage());
}

{
Settings settings = Settings.builder().put("index.codec", CodecService.LZ4_CODEC).build();
Settings settings = Settings.builder().put("index.codec", CodecType.DEFAULT.getName()).build();
SettingsModule module = new SettingsModule(settings);
assertInstanceBinding(module, Settings.class, (s) -> s == settings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.opensearch.index.IndexSettings;
import org.opensearch.index.codec.CodecService;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.index.codec.CodecType;
import org.opensearch.indices.replication.checkpoint.ReplicationCheckpoint;
import org.opensearch.repositories.IndexId;
import org.opensearch.snapshots.Snapshot;
Expand Down Expand Up @@ -812,7 +813,10 @@ public TestAllocator addData(DiscoveryNode node, String allocationId, boolean pr
node,
allocationId,
primary,
ReplicationCheckpoint.empty(shardId, new CodecService(null, indexSettings, null).codec(CodecService.LZ4_CODEC).getName()),
ReplicationCheckpoint.empty(
shardId,
new CodecService(null, indexSettings, null).codec(CodecType.DEFAULT.getName()).getName()
),
null
);
}
Expand All @@ -824,7 +828,10 @@ public TestAllocator addData(DiscoveryNode node, String allocationId, boolean pr
node,
allocationId,
primary,
ReplicationCheckpoint.empty(shardId, new CodecService(null, indexSettings, null).codec(CodecService.LZ4_CODEC).getName()),
ReplicationCheckpoint.empty(
shardId,
new CodecService(null, indexSettings, null).codec(CodecType.DEFAULT.getName()).getName()
),
storeException
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.env.Environment;
import org.opensearch.index.codec.CodecService;
import org.opensearch.index.codec.CodecType;
import org.opensearch.index.shard.IndexShard;
import org.opensearch.index.shard.IndexShardTestCase;
import org.opensearch.core.index.shard.ShardId;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void testCopyStateCreation() throws IOException {
CopyState copyState = new CopyState(
ReplicationCheckpoint.empty(
mockIndexShard.shardId(),
new CodecService(null, mockIndexShard.indexSettings(), null).codec(CodecService.LZ4_CODEC).getName()
new CodecService(null, mockIndexShard.indexSettings(), null).codec(CodecType.DEFAULT.getName()).getName()
),
mockIndexShard
);
Expand Down

0 comments on commit e8703c5

Please sign in to comment.