forked from continuwuation/rocksdb
Summary: while debugging stress test failure, I noticed that sst_dump and ldb do not work if custom db_stress compression manager is used. This PR adds support for it. ``` ./sst_dump --command=raw --show_properties --file=/tmp/rocksdb_crashtest_whitebox4ny5mass/000589.sst options.env is 0x7f2b1f4b9000 Process /tmp/rocksdb_crashtest_whitebox4ny5mass/000589.sst Sst file format: block-based /tmp/rocksdb_crashtest_whitebox4ny5mass/000589.sst: Not implemented: Could not load CompressionManager: DbStressCustom1 /tmp/rocksdb_crashtest_whitebox4ny5mass/000589.sst is not a valid SST file ./ldb idump --db=/tmp/rocksdb_crashtest_whiteboxy_emah11 --ignore_unknown_options --hex >> /tmp/i_dump Failed: Not implemented: Could not load CompressionManager: DbStressCustom1 ``` Pull Request resolved: https://github.com/facebook/rocksdb/pull/13827 Test Plan: manually tested that ldb and sst_dump work with DbStressCustomCompressionManager after this PR Reviewed By: pdillinger Differential Revision: D79461175 Pulled By: cbi42 fbshipit-source-id: c8c092b10b4fde3a295b00751057749e8f0cf095
67 lines
2.4 KiB
C++
67 lines
2.4 KiB
C++
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#pragma once
|
|
|
|
#include "test_util/testutil.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
class DbStressCustomCompressionManager : public CompressionManager {
|
|
public:
|
|
const char* Name() const override {
|
|
return "DbStressCustomCompressionManager";
|
|
}
|
|
const char* CompatibilityName() const override { return "DbStressCustom1"; }
|
|
|
|
bool SupportsCompressionType(CompressionType type) const override {
|
|
return default_->SupportsCompressionType(type) ||
|
|
type == kCustomCompressionAA || type == kCustomCompressionAB ||
|
|
type == kCustomCompressionAC;
|
|
}
|
|
|
|
std::unique_ptr<Compressor> GetCompressor(const CompressionOptions& opts,
|
|
CompressionType type) override {
|
|
// db_stress never specifies a custom type, so we randomly use them anyway
|
|
// when this compression manager is used.
|
|
std::array<CompressionType, 4> choices = {
|
|
type, kCustomCompressionAA, kCustomCompressionAB, kCustomCompressionAC};
|
|
type = choices[Random::GetTLSInstance()->Uniform(4)];
|
|
switch (static_cast<unsigned char>(type)) {
|
|
case kCustomCompressionAA:
|
|
return std::make_unique<
|
|
test::CompressorCustomAlg<kCustomCompressionAA>>();
|
|
case kCustomCompressionAB:
|
|
return std::make_unique<
|
|
test::CompressorCustomAlg<kCustomCompressionAB>>();
|
|
case kCustomCompressionAC:
|
|
return std::make_unique<
|
|
test::CompressorCustomAlg<kCustomCompressionAC>>();
|
|
// Also support built-in compression algorithms
|
|
default:
|
|
return GetBuiltinV2CompressionManager()->GetCompressor(opts, type);
|
|
}
|
|
}
|
|
|
|
std::shared_ptr<Decompressor> GetDecompressor() override {
|
|
return std::make_shared<test::DecompressorCustomAlg>();
|
|
}
|
|
|
|
std::shared_ptr<Decompressor> GetDecompressorForTypes(
|
|
const CompressionType* types_begin,
|
|
const CompressionType* types_end) override {
|
|
auto decomp = std::make_shared<test::DecompressorCustomAlg>();
|
|
decomp->SetAllowedTypes(types_begin, types_end);
|
|
return decomp;
|
|
}
|
|
|
|
static void Register();
|
|
|
|
protected:
|
|
std::shared_ptr<CompressionManager> default_ =
|
|
GetBuiltinV2CompressionManager();
|
|
};
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|