-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default compression setting via CS config (#13203)
- Loading branch information
1 parent
cbefb3a
commit fef7e41
Showing
10 changed files
with
191 additions
and
16 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
ydb/core/config/validation/column_shard_config_validator.cpp
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,55 @@ | ||
#include "validators.h" | ||
|
||
#include <ydb/core/formats/arrow/serializer/parsing.h> | ||
#include <ydb/core/formats/arrow/serializer/utils.h> | ||
#include <ydb/core/protos/config.pb.h> | ||
|
||
#include <util/generic/string.h> | ||
#include <util/string/builder.h> | ||
|
||
#include <vector> | ||
|
||
namespace NKikimr::NConfig { | ||
namespace { | ||
|
||
EValidationResult ValidateDefaultCompression(const NKikimrConfig::TColumnShardConfig& columnShardConfig, std::vector<TString>& msg) { | ||
if (!columnShardConfig.HasDefaultCompression() && !columnShardConfig.HasDefaultCompressionLevel()) { | ||
return EValidationResult::Ok; | ||
} | ||
if (!columnShardConfig.HasDefaultCompression() && columnShardConfig.HasDefaultCompressionLevel()) { | ||
msg.push_back("ColumnShardConfig: compression level is set without compression type"); | ||
return EValidationResult::Error; | ||
} | ||
std::optional<arrow::Compression::type> codec = NArrow::CompressionFromProto(columnShardConfig.GetDefaultCompression()); | ||
if (!codec.has_value()) { | ||
msg.push_back("ColumnShardConfig: Unknown compression"); | ||
return EValidationResult::Error; | ||
} | ||
if (columnShardConfig.HasDefaultCompressionLevel()) { | ||
if (!NArrow::SupportsCompressionLevel(codec.value())) { | ||
TString messageErr = TStringBuilder() << "ColumnShardConfig: compression `" << NArrow::CompressionToString(codec.value()) | ||
<< "` does not support compression level"; | ||
msg.push_back(messageErr); | ||
return EValidationResult::Error; | ||
} else if (!NArrow::SupportsCompressionLevel(codec.value(), columnShardConfig.GetDefaultCompressionLevel())) { | ||
TString messageErr = TStringBuilder() | ||
<< "ColumnShardConfig: compression `" << NArrow::CompressionToString(codec.value()) | ||
<< "` does not support compression level = " << std::to_string(columnShardConfig.GetDefaultCompressionLevel()); | ||
msg.push_back(messageErr); | ||
return EValidationResult::Error; | ||
} | ||
} | ||
return EValidationResult::Ok; | ||
} | ||
|
||
} // namespace | ||
|
||
EValidationResult ValidateColumnShardConfig(const NKikimrConfig::TColumnShardConfig& columnShardConfig, std::vector<TString>& msg) { | ||
EValidationResult validateDefaultCompressionResult = ValidateDefaultCompression(columnShardConfig, msg); | ||
if (validateDefaultCompressionResult == EValidationResult::Error) { | ||
return EValidationResult::Error; | ||
} | ||
return EValidationResult::Ok; | ||
} | ||
|
||
} // namespace NKikimr::NConfig |
97 changes: 97 additions & 0 deletions
97
...e/config/validation/column_shard_config_validator_ut/column_shard_config_validator_ut.cpp
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,97 @@ | ||
#include <ydb/core/config/validation/validators.h> | ||
#include <ydb/core/protos/config.pb.h> | ||
#include <ydb/core/protos/flat_scheme_op.pb.h> | ||
|
||
#include <library/cpp/testing/unittest/registar.h> | ||
|
||
#include <vector> | ||
|
||
using namespace NKikimr::NConfig; | ||
|
||
Y_UNIT_TEST_SUITE(ColumnShardConfigValidation) { | ||
Y_UNIT_TEST(AcceptDefaultCompression) { | ||
NKikimrConfig::TColumnShardConfig CSConfig; | ||
std::vector<TString> error; | ||
EValidationResult result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); | ||
UNIT_ASSERT_C(error.empty(), "Should not be errors"); | ||
} | ||
|
||
Y_UNIT_TEST(NotAcceptDefaultCompression) { | ||
NKikimrConfig::TColumnShardConfig CSConfig; | ||
std::vector<TString> error; | ||
CSConfig.SetDefaultCompressionLevel(2); | ||
EValidationResult result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Error); | ||
UNIT_ASSERT_VALUES_EQUAL(error.size(), 1); | ||
UNIT_ASSERT_STRINGS_EQUAL(error.front(), "ColumnShardConfig: compression level is set without compression type"); | ||
} | ||
|
||
Y_UNIT_TEST(CorrectPlainCompression) { | ||
NKikimrConfig::TColumnShardConfig CSConfig; | ||
std::vector<TString> error; | ||
CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecPlain); | ||
EValidationResult result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); | ||
UNIT_ASSERT_C(error.empty(), "Should not be errors"); | ||
} | ||
|
||
Y_UNIT_TEST(NotCorrectPlainCompression) { | ||
NKikimrConfig::TColumnShardConfig CSConfig; | ||
std::vector<TString> error; | ||
CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecPlain); | ||
CSConfig.SetDefaultCompressionLevel(1); | ||
EValidationResult result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Error); | ||
UNIT_ASSERT_VALUES_EQUAL(error.size(), 1); | ||
UNIT_ASSERT_STRINGS_EQUAL(error.front(), "ColumnShardConfig: compression `uncompressed` does not support compression level"); | ||
} | ||
|
||
Y_UNIT_TEST(CorrectLZ4Compression) { | ||
NKikimrConfig::TColumnShardConfig CSConfig; | ||
std::vector<TString> error; | ||
CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecLZ4); | ||
EValidationResult result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); | ||
UNIT_ASSERT_C(error.empty(), "Should not be errors"); | ||
} | ||
|
||
Y_UNIT_TEST(NotCorrectLZ4Compression) { | ||
NKikimrConfig::TColumnShardConfig CSConfig; | ||
std::vector<TString> error; | ||
CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecLZ4); | ||
CSConfig.SetDefaultCompressionLevel(1); | ||
EValidationResult result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Error); | ||
UNIT_ASSERT_VALUES_EQUAL(error.size(), 1); | ||
UNIT_ASSERT_STRINGS_EQUAL(error.front(), "ColumnShardConfig: compression `lz4` does not support compression level"); | ||
} | ||
|
||
Y_UNIT_TEST(CorrectZSTDCompression) { | ||
NKikimrConfig::TColumnShardConfig CSConfig; | ||
std::vector<TString> error; | ||
CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecZSTD); | ||
EValidationResult result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); | ||
UNIT_ASSERT_C(error.empty(), "Should not be errors"); | ||
CSConfig.SetDefaultCompressionLevel(0); | ||
result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); | ||
UNIT_ASSERT_C(error.empty(), "Should not be errors"); | ||
CSConfig.SetDefaultCompressionLevel(-100); | ||
result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); | ||
UNIT_ASSERT_C(error.empty(), "Should not be errors"); | ||
} | ||
|
||
Y_UNIT_TEST(NotCorrectZSTDCompression) { | ||
NKikimrConfig::TColumnShardConfig CSConfig; | ||
std::vector<TString> error; | ||
CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecZSTD); | ||
CSConfig.SetDefaultCompressionLevel(100); | ||
EValidationResult result = ValidateColumnShardConfig(CSConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Error); | ||
UNIT_ASSERT_VALUES_EQUAL(error.size(), 1); | ||
UNIT_ASSERT_STRINGS_EQUAL(error.front(), "ColumnShardConfig: compression `zstd` does not support compression level = 100"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
ydb/core/config/validation/column_shard_config_validator_ut/ya.make
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,7 @@ | ||
UNITTEST_FOR(ydb/core/config/validation) | ||
|
||
SRC( | ||
column_shard_config_validator_ut.cpp | ||
) | ||
|
||
END() |
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
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
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