-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallowing compression level for lz4 and best_compression codec
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
- Loading branch information
1 parent
ca74aac
commit 87d4990
Showing
5 changed files
with
269 additions
and
10 deletions.
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
185 changes: 185 additions & 0 deletions
185
server/src/internalClusterTest/java/org/opensearch/index/codec/CodecCompressionLevelIT.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,185 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.logging.log4j.core.util.Throwables; | ||
import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.common.Randomness; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST) | ||
public class CodecCompressionLevelIT extends OpenSearchIntegTestCase { | ||
|
||
List<String> luceneCodecs = List.of("default", "best_compression"); | ||
List<String> ZStandardCodecs = List.of("zstd", "zstd_no_dict"); | ||
|
||
public void testLuceneCodecsCreateIndexWithCompressionLevel() { | ||
|
||
internalCluster().ensureAtLeastNumDataNodes(1); | ||
final String index = "test-index"; | ||
|
||
// creating index | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> createIndex( | ||
index, | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.put("index.codec", getRandomCodec(luceneCodecs)) | ||
.put("index.codec.compression_level", randomIntBetween(1, 6)) | ||
.build() | ||
) | ||
); | ||
|
||
createIndex( | ||
index, | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.put("index.codec", getRandomCodec(luceneCodecs)) | ||
.build() | ||
); | ||
ensureGreen(index); | ||
} | ||
|
||
public void testZStandardCodecsCreateIndexWithCompressionLevel() { | ||
|
||
internalCluster().ensureAtLeastNumDataNodes(1); | ||
final String index = "test-index"; | ||
|
||
// creating index | ||
createIndex( | ||
index, | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.put("index.codec", getRandomCodec(ZStandardCodecs)) | ||
.put("index.codec.compression_level", randomIntBetween(1, 6)) | ||
.build() | ||
); | ||
|
||
ensureGreen(index); | ||
} | ||
|
||
public void testZStandardToLuceneCodecsWithCompressionLevel() throws ExecutionException, InterruptedException { | ||
|
||
internalCluster().ensureAtLeastNumDataNodes(1); | ||
final String index = "test-index"; | ||
|
||
// creating index | ||
createIndex( | ||
index, | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.put("index.codec", getRandomCodec(ZStandardCodecs)) | ||
.put("index.codec.compression_level", randomIntBetween(1, 6)) | ||
.build() | ||
); | ||
ensureGreen(index); | ||
|
||
assertAcked(client().admin().indices().prepareClose(index)); | ||
|
||
Throwable executionException = expectThrows( | ||
ExecutionException.class, | ||
() -> client().admin() | ||
.indices() | ||
.updateSettings( | ||
new UpdateSettingsRequest(index).settings(Settings.builder().put("index.codec", getRandomCodec(luceneCodecs))) | ||
) | ||
.get() | ||
); | ||
|
||
Throwable rootCause = Throwables.getRootCause(executionException); | ||
assertEquals(IllegalArgumentException.class, rootCause.getClass()); | ||
assertTrue(rootCause.getMessage().startsWith("Compression level cannot be set")); | ||
|
||
assertAcked( | ||
client().admin() | ||
.indices() | ||
.updateSettings( | ||
new UpdateSettingsRequest(index).settings( | ||
Settings.builder() | ||
.put("index.codec", getRandomCodec(luceneCodecs)) | ||
.put("index.codec.compression_level", (String) null) | ||
) | ||
) | ||
.get() | ||
); | ||
|
||
assertAcked(client().admin().indices().prepareOpen(index)); | ||
ensureGreen(index); | ||
} | ||
|
||
public void testLuceneToZStandardCodecsWithCompressionLevel() throws ExecutionException, InterruptedException { | ||
|
||
internalCluster().ensureAtLeastNumDataNodes(1); | ||
final String index = "test-index"; | ||
|
||
// creating index | ||
createIndex( | ||
index, | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.put("index.codec", getRandomCodec(luceneCodecs)) | ||
.build() | ||
); | ||
ensureGreen(index); | ||
|
||
assertAcked(client().admin().indices().prepareClose(index)); | ||
|
||
Throwable executionException = expectThrows( | ||
ExecutionException.class, | ||
() -> client().admin() | ||
.indices() | ||
.updateSettings( | ||
new UpdateSettingsRequest(index).settings( | ||
Settings.builder() | ||
.put("index.codec", getRandomCodec(luceneCodecs)) | ||
.put("index.codec.compression_level", randomIntBetween(1, 6)) | ||
) | ||
) | ||
.get() | ||
); | ||
|
||
Throwable rootCause = Throwables.getRootCause(executionException); | ||
assertEquals(IllegalArgumentException.class, rootCause.getClass()); | ||
assertTrue(rootCause.getMessage().startsWith("Compression level cannot be set")); | ||
|
||
assertAcked( | ||
client().admin() | ||
.indices() | ||
.updateSettings( | ||
new UpdateSettingsRequest(index).settings( | ||
Settings.builder() | ||
.put("index.codec", getRandomCodec(ZStandardCodecs)) | ||
.put("index.codec.compression_level", randomIntBetween(1, 6)) | ||
) | ||
) | ||
.get() | ||
); | ||
|
||
assertAcked(client().admin().indices().prepareOpen(index)); | ||
ensureGreen(index); | ||
} | ||
|
||
private String getRandomCodec(List<String> codecList) { | ||
return codecList.get(Randomness.get().nextInt(codecList.size())); | ||
} | ||
|
||
} |
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