Skip to content

Commit

Permalink
Make GetCompactionReasonString() publicly visible
Browse files Browse the repository at this point in the history
  • Loading branch information
Pulkit Agarwal committed Mar 9, 2020
1 parent f46df84 commit e5cc030
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/rocksdb/convenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>

#include "rocksdb/db.h"
#include "rocksdb/listener.h"
#include "rocksdb/options.h"
#include "rocksdb/table.h"

Expand Down Expand Up @@ -296,6 +297,9 @@ Status GetStringFromColumnFamilyOptions(std::string* opts_str,
Status GetStringFromCompressionType(std::string* compression_str,
CompressionType compression_type);

Status GetStringFromCompactionReason(std::string* compression_str,
CompactionReason compaction_reason);

std::vector<CompressionType> GetSupportedCompressions();

Status GetBlockBasedTableOptionsFromString(
Expand Down
31 changes: 31 additions & 0 deletions options/options_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "rocksdb/compaction_filter.h"
#include "rocksdb/convenience.h"
#include "rocksdb/filter_policy.h"
#include "rocksdb/listener.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/merge_operator.h"
#include "rocksdb/options.h"
Expand Down Expand Up @@ -253,6 +254,25 @@ std::unordered_map<std::string, CompressionType>
{"kZSTD", kZSTD},
{"kZSTDNotFinalCompression", kZSTDNotFinalCompression},
{"kDisableCompressionOption", kDisableCompressionOption}};

std::unordered_map<std::string, CompactionReason>
OptionsHelper::compaction_reason_string_map = {
{"Unknown", CompactionReason::kUnknown},
{"LevelL0FilesNum", CompactionReason::kLevelL0FilesNum},
{"LevelMaxLevelSize", CompactionReason::kLevelMaxLevelSize},
{"UniversalSizeAmplification", CompactionReason::kUniversalSizeAmplification},
{"UniversalSizeRatio", CompactionReason::kUniversalSizeRatio},
{"UniversalSortedRunNum", CompactionReason::kUniversalSortedRunNum},
{"FIFOMaxSize", CompactionReason::kFIFOMaxSize},
{"FIFOReduceNumFiles", CompactionReason::kFIFOReduceNumFiles},
{"FIFOTtl", CompactionReason::kFIFOTtl},
{"ManualCompaction", CompactionReason::kManualCompaction},
{"FilesMarkedForCompaction", CompactionReason::kFilesMarkedForCompaction},
{"BottommostFiles", CompactionReason::kBottommostFiles},
{"Ttl", CompactionReason::kTtl},
{"Flush", CompactionReason::kFlush},
{"ExternalSstIngestion", CompactionReason::kExternalSstIngestion},
{"PeriodicCompaction", CompactionReason::kPeriodicCompaction}};
#ifndef ROCKSDB_LITE

const std::string kNameComparator = "comparator";
Expand Down Expand Up @@ -1184,6 +1204,17 @@ std::vector<CompressionType> GetSupportedCompressions() {
return supported_compressions;
}

Status GetStringFromCompactionReason(std::string* compaction_str,
CompactionReason compaction_reason) {
bool ok = SerializeEnum<CompactionReason>(compaction_reason_string_map,
compaction_reason, compaction_str);
if (ok) {
return Status::OK();
} else {
return Status::InvalidArgument("Invalid compaction reason");
}
}

Status ParseDBOption(const std::string& name,
const std::string& org_value,
DBOptions* new_options,
Expand Down
8 changes: 6 additions & 2 deletions options/options_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ struct OptionsHelper {
static std::unordered_map<std::string, ChecksumType> checksum_type_string_map;
static std::unordered_map<std::string, CompressionType>
compression_type_string_map;
static std::unordered_map<std::string, CompactionReason>
compaction_reason_string_map;
#ifndef ROCKSDB_LITE
static std::unordered_map<std::string, OptionTypeInfo> cf_options_type_info;
static std::unordered_map<std::string, OptionTypeInfo>
Expand Down Expand Up @@ -199,6 +201,10 @@ static auto& compaction_pri_to_string = OptionsHelper::compaction_pri_to_string;
static auto& compaction_stop_style_to_string =
OptionsHelper::compaction_stop_style_to_string;
static auto& checksum_type_string_map = OptionsHelper::checksum_type_string_map;
static auto& compression_type_string_map =
OptionsHelper::compression_type_string_map;
static auto& compaction_reason_string_map =
OptionsHelper::compaction_reason_string_map;
#ifndef ROCKSDB_LITE
static auto& cf_options_type_info = OptionsHelper::cf_options_type_info;
static auto& fifo_compaction_options_type_info =
Expand All @@ -210,8 +216,6 @@ static auto& compaction_stop_style_string_map =
static auto& db_options_type_info = OptionsHelper::db_options_type_info;
static auto& lru_cache_options_type_info =
OptionsHelper::lru_cache_options_type_info;
static auto& compression_type_string_map =
OptionsHelper::compression_type_string_map;
static auto& block_base_table_index_type_string_map =
OptionsHelper::block_base_table_index_type_string_map;
static auto& block_base_table_data_block_index_type_string_map =
Expand Down
23 changes: 23 additions & 0 deletions options/options_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "port/port.h"
#include "rocksdb/cache.h"
#include "rocksdb/convenience.h"
#include "rocksdb/listener.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/utilities/leveldb_options.h"
#include "rocksdb/utilities/object_registry.h"
Expand Down Expand Up @@ -1079,6 +1080,28 @@ TEST_F(OptionsTest, GetStringFromCompressionType) {
ASSERT_NOK(
GetStringFromCompressionType(&res, static_cast<CompressionType>(-10)));
}

TEST_F(OptionsTest, GetStringFromCompactionReason) {
std::string res;

ASSERT_OK(GetStringFromCompactionReason(&res, CompactionReason::kUnknown));
ASSERT_EQ(res, "Unknown");

ASSERT_OK(GetStringFromCompactionReason(&res, CompactionReason::kLevelL0FilesNum));
ASSERT_EQ(res, "LevelL0FilesNum");

ASSERT_OK(GetStringFromCompactionReason(&res, CompactionReason::kLevelMaxLevelSize));
ASSERT_EQ(res, "LevelMaxLevelSize");

ASSERT_OK(GetStringFromCompactionReason(&res, CompactionReason::kUniversalSizeAmplification));
ASSERT_EQ(res, "UniversalSizeAmplification");

ASSERT_OK(GetStringFromCompactionReason(&res, CompactionReason::kUniversalSizeRatio));
ASSERT_EQ(res, "UniversalSizeRatio");

ASSERT_NOK(
GetStringFromCompactionReason(&res, static_cast<CompactionReason>(-10)));
}
#endif // !ROCKSDB_LITE

TEST_F(OptionsTest, ConvertOptionsTest) {
Expand Down

0 comments on commit e5cc030

Please sign in to comment.