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 27, 2023
1 parent 912d9dd commit d94d2f1
Show file tree
Hide file tree
Showing 7 changed files with 27 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,
"best_compression",
"BEST_COMPRESSION",
CodecService.ZSTD_NO_DICT_CODEC,
"zstd_no_dict",
"ZSTD_NO_DICT",
CodecService.ZSTD_CODEC,
"zstd",
"ZSTD",
CodecService.LZ4_CODEC,
"default",
"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", "default")
.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,
"best_compression",
"BEST_COMPRESSION",
CodecService.ZSTD_NO_DICT_CODEC,
"zstd_no_dict",
"ZSTD_NO_DICT",
CodecService.ZSTD_CODEC,
"zstd",
"ZSTD",
CodecService.LZ4_CODEC,
"default",
"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", "default")
.put("index.merge.policy.max_merged_segment", "1b")
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public class CodecService {
private final Map<String, Codec> codecs;

public static final String DEFAULT_CODEC = "default";
public static final String LZ4 = "lz4";
public static final String BEST_COMPRESSION_CODEC = "best_compression";
public static final String ZLIB = "zlib";
/**
* the raw unfiltered lucene default. useful for testing
*/
Expand All @@ -74,12 +76,16 @@ public CodecService(@Nullable MapperService mapperService, IndexSettings indexSe
int compressionLevel = indexSettings.getValue(INDEX_CODEC_COMPRESSION_LEVEL_SETTING);
if (mapperService == null) {
codecs.put(DEFAULT_CODEC, new Lucene95Codec());
codecs.put(LZ4, new Lucene95Codec());
codecs.put(BEST_COMPRESSION_CODEC, new Lucene95Codec(Mode.BEST_COMPRESSION));
codecs.put(ZLIB, new Lucene95Codec(Mode.BEST_COMPRESSION));
codecs.put(ZSTD_CODEC, new ZstdCodec(compressionLevel));
codecs.put(ZSTD_NO_DICT_CODEC, new ZstdNoDictCodec(compressionLevel));
} else {
codecs.put(DEFAULT_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
codecs.put(LZ4, new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
codecs.put(BEST_COMPRESSION_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
codecs.put(ZLIB, new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
codecs.put(ZSTD_CODEC, new ZstdCodec(mapperService, logger, compressionLevel));
codecs.put(ZSTD_NO_DICT_CODEC, new ZstdNoDictCodec(mapperService, logger, compressionLevel));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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 @@ -138,7 +140,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 Expand Up @@ -184,6 +187,8 @@ private static void doValidateCodecSettings(final String codec) {
case "best_compression":
case "lucene_default":
case "default":
case "lz4":
case "zlib":
break;
default:
if (Codec.availableCodecs().contains(codec)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.hamcrest.Matchers;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.codec.CodecService;
import org.opensearch.search.SearchService;
import org.opensearch.test.FeatureFlagSetter;

Expand Down Expand Up @@ -74,13 +73,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", "default").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", "default").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 @@ -812,7 +812,7 @@ 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("default").getName()),
null
);
}
Expand All @@ -824,7 +824,7 @@ 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("default").getName()),
storeException
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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("default").getName()
),
mockIndexShard
);
Expand Down

0 comments on commit d94d2f1

Please sign in to comment.