Skip to content

Commit 2dcfc54

Browse files
Sujit Maharjanfacebook-github-bot
authored andcommitted
Mixed compressor adding RandomCompressorManager to db_stress_test (facebook#13691)
Summary: **Summary:** This pull request configures RocksDB to optionally utilize this customized compressor (RandomCompressor) in the db stress test. It randomly selects the compression algorithm among the blocks. Pull Request resolved: facebook#13691 Test Plan: Testing was performed by verifying the stdout output from both RandomCompressor. Reviewed By: hx235 Differential Revision: D76624220 Pulled By: shubhajeet fbshipit-source-id: d9c458eeee930b25e8a87a77dc29f0647836310e
1 parent 504ff4e commit 2dcfc54

5 files changed

Lines changed: 36 additions & 28 deletions

File tree

db/db_test2.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,9 +1936,9 @@ TEST_F(DBTest2, RoundRobinManager) {
19361936
}
19371937
}
19381938

1939-
TEST_F(DBTest2, SimpleMixedCompressionManager) {
1939+
TEST_F(DBTest2, RandomMixedCompressionManager) {
19401940
if (ZSTD_Supported()) {
1941-
auto mgr = std::make_shared<SimpleMixedCompressionManager>(
1941+
auto mgr = std::make_shared<RandomMixedCompressionManager>(
19421942
GetDefaultBuiltinCompressionManager());
19431943
// Currently mixedmanager only supports with preffered compression manager
19441944
// zstd

db_stress_tool/db_stress_test_base.cc

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,27 +3412,32 @@ void StressTest::Open(SharedState* shared, bool reopen) {
34123412
InitializeOptionsFromFlags(cache_, filter_policy_, options_);
34133413
}
34143414
InitializeOptionsGeneral(cache_, filter_policy_, sqfc_factory_, options_);
3415-
if (strcasecmp(FLAGS_compression_manager.c_str(), "none")) {
3415+
if (!strcasecmp(FLAGS_compression_manager.c_str(), "mixed") ||
3416+
!strcasecmp(FLAGS_compression_manager.c_str(), "randommixed")) {
3417+
// Currently limited to ZSTD compression. Table property compression_name
3418+
// needs to set to zstd for now even when there can be more than one
3419+
// algorithm in the table under your compressor.
3420+
if (!ZSTD_Supported()) {
3421+
fprintf(stderr,
3422+
"ZSTD compression not supported thus mixed compression cannot be "
3423+
"used\n");
3424+
exit(1);
3425+
}
34163426
if (!strcasecmp(FLAGS_compression_manager.c_str(), "mixed")) {
3417-
// Currently limited to ZSTD compression. Table property compression_name
3418-
// needs to set to zstd for now even when there can be more than one
3419-
// algorithm in the table under your compressor.
3420-
if (!ZSTD_Supported()) {
3421-
fprintf(
3422-
stderr,
3423-
"ZSTD compression not supported thus mixed compression cannot be "
3424-
"used\n");
3425-
exit(1);
3426-
}
34273427
auto mgr = std::make_shared<RoundRobinManager>(
34283428
GetDefaultBuiltinCompressionManager());
34293429
options_.compression_manager = mgr;
3430-
options_.compression = kZSTD;
3431-
options_.bottommost_compression = kZSTD;
3432-
} else if (!strcasecmp(FLAGS_compression_manager.c_str(), "autoskip")) {
3433-
options_.compression_manager = CreateAutoSkipCompressionManager(
3430+
} else if (!strcasecmp(FLAGS_compression_manager.c_str(), "randommixed")) {
3431+
auto mgr = std::make_shared<RandomMixedCompressionManager>(
34343432
GetDefaultBuiltinCompressionManager());
3433+
options_.compression_manager = mgr;
34353434
}
3435+
options_.compression = kZSTD;
3436+
options_.bottommost_compression = kZSTD;
3437+
3438+
} else if (!strcasecmp(FLAGS_compression_manager.c_str(), "autoskip")) {
3439+
options_.compression_manager =
3440+
CreateAutoSkipCompressionManager(GetDefaultBuiltinCompressionManager());
34363441
} else if (!strcasecmp(FLAGS_compression_manager.c_str(), "none")) {
34373442
// Nothing to do using default compression manager
34383443
} else {

tools/db_crashtest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@
349349
"memtable_avg_op_scan_flush_trigger": lambda: random.choice([0, 2, 20, 200]),
350350
"ingest_wbwi_one_in": lambda: random.choice([0, 0, 100, 500]),
351351
"universal_reduce_file_locking": lambda: random.randint(0, 1),
352-
"compression_manager": lambda: random.choice(["mixed", "none", "autoskip"]),
352+
"compression_manager": lambda: random.choice(
353+
["mixed"] * 1 + ["none"] * 2 + ["autoskip"] * 2 + ["randommixed"] * 2
354+
),
353355
}
354356

355357
_TEST_DIR_ENV_VAR = "TEST_TMPDIR"
@@ -1000,7 +1002,10 @@ def finalize_and_sanitize(src_params):
10001002
dest_params["exclude_wal_from_write_fault_injection"] = 1
10011003
dest_params["metadata_write_fault_one_in"] = 0
10021004
# Disabling block align if mixed manager is neing used
1003-
if dest_params.get("compression_manager") == "mixed":
1005+
if (
1006+
dest_params.get("compression_manager") == "mixed"
1007+
or dest_params.get("compression_manager") == "randommixed"
1008+
):
10041009
if dest_params.get("block_align") == 1:
10051010
dest_params["block_align"] = 0
10061011
dest_params["compression_type"] = "zstd"

util/simple_mixed_compressor.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ std::unique_ptr<Compressor> MultiCompressorWrapper::MaybeCloneSpecialized(
5555
std::move(dict_samples));
5656
}
5757

58-
// SimpleMixedCompressor implementation
59-
Status SimpleMixedCompressor::CompressBlock(
58+
Status RandomMixedCompressor::CompressBlock(
6059
Slice uncompressed_data, std::string* compressed_output,
6160
CompressionType* out_compression_type, ManagedWorkingArea* wa) {
6261
auto selected =
@@ -66,18 +65,17 @@ Status SimpleMixedCompressor::CompressBlock(
6665
out_compression_type, wa);
6766
}
6867

69-
// SimpleMixedCompressionManager implementation
70-
const char* SimpleMixedCompressionManager::Name() const {
68+
const char* RandomMixedCompressionManager::Name() const {
7169
return wrapped_->Name();
72-
// return "SimpleMixedCompressionManager";
70+
// return "RandomMixedCompressionManager";
7371
}
7472

75-
std::unique_ptr<Compressor> SimpleMixedCompressionManager::GetCompressorForSST(
73+
std::unique_ptr<Compressor> RandomMixedCompressionManager::GetCompressorForSST(
7674
const FilterBuildingContext& context, const CompressionOptions& opts,
7775
CompressionType preferred) {
7876
assert(preferred == kZSTD);
7977
(void)context;
80-
return std::make_unique<SimpleMixedCompressor>(opts, preferred);
78+
return std::make_unique<RandomMixedCompressor>(opts, preferred);
8179
}
8280

8381
// RoundRobinCompressor implementation

util/simple_mixed_compressor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class MultiCompressorWrapper : public Compressor {
3333
std::vector<std::unique_ptr<Compressor>> compressors_;
3434
};
3535

36-
struct SimpleMixedCompressor : public MultiCompressorWrapper {
36+
struct RandomMixedCompressor : public MultiCompressorWrapper {
3737
using MultiCompressorWrapper::MultiCompressorWrapper;
3838
Status CompressBlock(Slice uncompressed_data, std::string* compressed_output,
3939
CompressionType* out_compression_type,
4040
ManagedWorkingArea* wa) override;
4141
};
4242

43-
class SimpleMixedCompressionManager : public CompressionManagerWrapper {
43+
class RandomMixedCompressionManager : public CompressionManagerWrapper {
4444
using CompressionManagerWrapper::CompressionManagerWrapper;
4545
const char* Name() const override;
4646
std::unique_ptr<Compressor> GetCompressorForSST(

0 commit comments

Comments
 (0)