From e5cc030b5145280462f9a56c2a8a4bacd02c49e1 Mon Sep 17 00:00:00 2001 From: Pulkit Agarwal Date: Mon, 9 Mar 2020 09:40:11 -0700 Subject: [PATCH] Make GetCompactionReasonString() publicly visible --- include/rocksdb/convenience.h | 4 ++++ options/options_helper.cc | 31 +++++++++++++++++++++++++++++++ options/options_helper.h | 8 ++++++-- options/options_test.cc | 23 +++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/include/rocksdb/convenience.h b/include/rocksdb/convenience.h index 442303d9486..f1b5623df13 100644 --- a/include/rocksdb/convenience.h +++ b/include/rocksdb/convenience.h @@ -10,6 +10,7 @@ #include #include "rocksdb/db.h" +#include "rocksdb/listener.h" #include "rocksdb/options.h" #include "rocksdb/table.h" @@ -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 GetSupportedCompressions(); Status GetBlockBasedTableOptionsFromString( diff --git a/options/options_helper.cc b/options/options_helper.cc index bc36dbcfe72..3961d6cddab 100644 --- a/options/options_helper.cc +++ b/options/options_helper.cc @@ -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" @@ -253,6 +254,25 @@ std::unordered_map {"kZSTD", kZSTD}, {"kZSTDNotFinalCompression", kZSTDNotFinalCompression}, {"kDisableCompressionOption", kDisableCompressionOption}}; + +std::unordered_map + 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"; @@ -1184,6 +1204,17 @@ std::vector GetSupportedCompressions() { return supported_compressions; } +Status GetStringFromCompactionReason(std::string* compaction_str, + CompactionReason compaction_reason) { + bool ok = SerializeEnum(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, diff --git a/options/options_helper.h b/options/options_helper.h index c75fdb1ceb4..60422ec25cc 100644 --- a/options/options_helper.h +++ b/options/options_helper.h @@ -155,6 +155,8 @@ struct OptionsHelper { static std::unordered_map checksum_type_string_map; static std::unordered_map compression_type_string_map; + static std::unordered_map + compaction_reason_string_map; #ifndef ROCKSDB_LITE static std::unordered_map cf_options_type_info; static std::unordered_map @@ -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 = @@ -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 = diff --git a/options/options_test.cc b/options/options_test.cc index 9ff99532cda..a8af5df0b53 100644 --- a/options/options_test.cc +++ b/options/options_test.cc @@ -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" @@ -1079,6 +1080,28 @@ TEST_F(OptionsTest, GetStringFromCompressionType) { ASSERT_NOK( GetStringFromCompressionType(&res, static_cast(-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(-10))); +} #endif // !ROCKSDB_LITE TEST_F(OptionsTest, ConvertOptionsTest) {