-
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 (#8737)
* Disallowing compression level for lz4 and best_compression codec * setting up codec settings interface for validation Signed-off-by: Sarthak Aggarwal <[email protected]> (cherry picked from commit 82b5f3c) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d711f66
commit f89c785
Showing
7 changed files
with
332 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
178 changes: 178 additions & 0 deletions
178
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,178 @@ | ||
/* | ||
* 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.settings.Settings; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST) | ||
public class CodecCompressionLevelIT extends OpenSearchIntegTestCase { | ||
|
||
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", randomFrom(CodecService.DEFAULT_CODEC, CodecService.BEST_COMPRESSION_CODEC)) | ||
.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", randomFrom(CodecService.DEFAULT_CODEC, CodecService.BEST_COMPRESSION_CODEC)) | ||
.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", randomFrom(CodecService.ZSTD_CODEC, CodecService.ZSTD_NO_DICT_CODEC)) | ||
.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", randomFrom(CodecService.ZSTD_CODEC, CodecService.ZSTD_NO_DICT_CODEC)) | ||
.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", randomFrom(CodecService.DEFAULT_CODEC, CodecService.BEST_COMPRESSION_CODEC)) | ||
) | ||
) | ||
.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", randomFrom(CodecService.DEFAULT_CODEC, CodecService.BEST_COMPRESSION_CODEC)) | ||
.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", randomFrom(CodecService.DEFAULT_CODEC, CodecService.BEST_COMPRESSION_CODEC)) | ||
.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", randomFrom(CodecService.DEFAULT_CODEC, CodecService.BEST_COMPRESSION_CODEC)) | ||
.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", randomFrom(CodecService.ZSTD_CODEC, CodecService.ZSTD_NO_DICT_CODEC)) | ||
.put("index.codec.compression_level", randomIntBetween(1, 6)) | ||
) | ||
) | ||
.get() | ||
); | ||
|
||
assertAcked(client().admin().indices().prepareOpen(index)); | ||
ensureGreen(index); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
server/src/main/java/org/opensearch/index/codec/CodecSettings.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,21 @@ | ||
/* | ||
* 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.lucene.codecs.Codec; | ||
import org.opensearch.common.settings.Setting; | ||
|
||
/** | ||
* This {@link CodecSettings} allows us to manage the settings with {@link Codec}. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public interface CodecSettings { | ||
boolean supports(Setting<?> setting); | ||
} |
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
Oops, something went wrong.