From be88f8b69a3b5f3e08c180ebc3e1c7d71e148c9f Mon Sep 17 00:00:00 2001 From: Pulkit Agarwal Date: Fri, 6 Mar 2020 09:45:49 -0800 Subject: [PATCH 1/6] Expose GetCompactionReasonString() publicly --- db/compaction/compaction.cc | 42 +++++++++++++++++++++++++++++++ db/compaction/compaction.h | 2 ++ db/compaction/compaction_job.cc | 44 +-------------------------------- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/db/compaction/compaction.cc b/db/compaction/compaction.cc index 5c34fdcaa87..3472d8bacbf 100644 --- a/db/compaction/compaction.cc +++ b/db/compaction/compaction.cc @@ -561,4 +561,46 @@ int Compaction::GetInputBaseLevel() const { return input_vstorage_->base_level(); } +const char* Compaction::GetCompactionReasonString() const { + switch (compaction_reason_) { + case CompactionReason::kUnknown: + return "Unknown"; + case CompactionReason::kLevelL0FilesNum: + return "LevelL0FilesNum"; + case CompactionReason::kLevelMaxLevelSize: + return "LevelMaxLevelSize"; + case CompactionReason::kUniversalSizeAmplification: + return "UniversalSizeAmplification"; + case CompactionReason::kUniversalSizeRatio: + return "UniversalSizeRatio"; + case CompactionReason::kUniversalSortedRunNum: + return "UniversalSortedRunNum"; + case CompactionReason::kFIFOMaxSize: + return "FIFOMaxSize"; + case CompactionReason::kFIFOReduceNumFiles: + return "FIFOReduceNumFiles"; + case CompactionReason::kFIFOTtl: + return "FIFOTtl"; + case CompactionReason::kManualCompaction: + return "ManualCompaction"; + case CompactionReason::kFilesMarkedForCompaction: + return "FilesMarkedForCompaction"; + case CompactionReason::kBottommostFiles: + return "BottommostFiles"; + case CompactionReason::kTtl: + return "Ttl"; + case CompactionReason::kFlush: + return "Flush"; + case CompactionReason::kExternalSstIngestion: + return "ExternalSstIngestion"; + case CompactionReason::kPeriodicCompaction: + return "PeriodicCompaction"; + case CompactionReason::kNumOfReasons: + // fall through + default: + assert(false); + return "Invalid"; + } +} + } // namespace ROCKSDB_NAMESPACE diff --git a/db/compaction/compaction.h b/db/compaction/compaction.h index 9358e50fff1..1c4a5bba7a4 100644 --- a/db/compaction/compaction.h +++ b/db/compaction/compaction.h @@ -281,6 +281,8 @@ class Compaction { int GetInputBaseLevel() const; + const char* GetCompactionReasonString() const; + CompactionReason compaction_reason() { return compaction_reason_; } const std::vector& grandparents() const { diff --git a/db/compaction/compaction_job.cc b/db/compaction/compaction_job.cc index 9f42f00eea2..137b79fae19 100644 --- a/db/compaction/compaction_job.cc +++ b/db/compaction/compaction_job.cc @@ -61,48 +61,6 @@ namespace ROCKSDB_NAMESPACE { -const char* GetCompactionReasonString(CompactionReason compaction_reason) { - switch (compaction_reason) { - case CompactionReason::kUnknown: - return "Unknown"; - case CompactionReason::kLevelL0FilesNum: - return "LevelL0FilesNum"; - case CompactionReason::kLevelMaxLevelSize: - return "LevelMaxLevelSize"; - case CompactionReason::kUniversalSizeAmplification: - return "UniversalSizeAmplification"; - case CompactionReason::kUniversalSizeRatio: - return "UniversalSizeRatio"; - case CompactionReason::kUniversalSortedRunNum: - return "UniversalSortedRunNum"; - case CompactionReason::kFIFOMaxSize: - return "FIFOMaxSize"; - case CompactionReason::kFIFOReduceNumFiles: - return "FIFOReduceNumFiles"; - case CompactionReason::kFIFOTtl: - return "FIFOTtl"; - case CompactionReason::kManualCompaction: - return "ManualCompaction"; - case CompactionReason::kFilesMarkedForCompaction: - return "FilesMarkedForCompaction"; - case CompactionReason::kBottommostFiles: - return "BottommostFiles"; - case CompactionReason::kTtl: - return "Ttl"; - case CompactionReason::kFlush: - return "Flush"; - case CompactionReason::kExternalSstIngestion: - return "ExternalSstIngestion"; - case CompactionReason::kPeriodicCompaction: - return "PeriodicCompaction"; - case CompactionReason::kNumOfReasons: - // fall through - default: - assert(false); - return "Invalid"; - } -} - // Maintains state for each sub-compaction struct CompactionJob::SubcompactionState { const Compaction* compaction; @@ -1683,7 +1641,7 @@ void CompactionJob::LogCompaction() { stream << "job" << job_id_ << "event" << "compaction_started" << "compaction_reason" - << GetCompactionReasonString(compaction->compaction_reason()); + << compaction->GetCompactionReasonString(); for (size_t i = 0; i < compaction->num_input_levels(); ++i) { stream << ("files_L" + ToString(compaction->level(i))); stream.StartArray(); From f46df8428d00541fd3a4edd42d9ca8dccbf7a13d Mon Sep 17 00:00:00 2001 From: Pulkit Agarwal Date: Mon, 9 Mar 2020 09:48:19 -0700 Subject: [PATCH 2/6] Revert "Expose GetCompactionReasonString() publicly" This reverts commit be88f8b69a3b5f3e08c180ebc3e1c7d71e148c9f. --- db/compaction/compaction.cc | 42 ------------------------------- db/compaction/compaction.h | 2 -- db/compaction/compaction_job.cc | 44 ++++++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 45 deletions(-) diff --git a/db/compaction/compaction.cc b/db/compaction/compaction.cc index 3472d8bacbf..5c34fdcaa87 100644 --- a/db/compaction/compaction.cc +++ b/db/compaction/compaction.cc @@ -561,46 +561,4 @@ int Compaction::GetInputBaseLevel() const { return input_vstorage_->base_level(); } -const char* Compaction::GetCompactionReasonString() const { - switch (compaction_reason_) { - case CompactionReason::kUnknown: - return "Unknown"; - case CompactionReason::kLevelL0FilesNum: - return "LevelL0FilesNum"; - case CompactionReason::kLevelMaxLevelSize: - return "LevelMaxLevelSize"; - case CompactionReason::kUniversalSizeAmplification: - return "UniversalSizeAmplification"; - case CompactionReason::kUniversalSizeRatio: - return "UniversalSizeRatio"; - case CompactionReason::kUniversalSortedRunNum: - return "UniversalSortedRunNum"; - case CompactionReason::kFIFOMaxSize: - return "FIFOMaxSize"; - case CompactionReason::kFIFOReduceNumFiles: - return "FIFOReduceNumFiles"; - case CompactionReason::kFIFOTtl: - return "FIFOTtl"; - case CompactionReason::kManualCompaction: - return "ManualCompaction"; - case CompactionReason::kFilesMarkedForCompaction: - return "FilesMarkedForCompaction"; - case CompactionReason::kBottommostFiles: - return "BottommostFiles"; - case CompactionReason::kTtl: - return "Ttl"; - case CompactionReason::kFlush: - return "Flush"; - case CompactionReason::kExternalSstIngestion: - return "ExternalSstIngestion"; - case CompactionReason::kPeriodicCompaction: - return "PeriodicCompaction"; - case CompactionReason::kNumOfReasons: - // fall through - default: - assert(false); - return "Invalid"; - } -} - } // namespace ROCKSDB_NAMESPACE diff --git a/db/compaction/compaction.h b/db/compaction/compaction.h index 1c4a5bba7a4..9358e50fff1 100644 --- a/db/compaction/compaction.h +++ b/db/compaction/compaction.h @@ -281,8 +281,6 @@ class Compaction { int GetInputBaseLevel() const; - const char* GetCompactionReasonString() const; - CompactionReason compaction_reason() { return compaction_reason_; } const std::vector& grandparents() const { diff --git a/db/compaction/compaction_job.cc b/db/compaction/compaction_job.cc index 137b79fae19..9f42f00eea2 100644 --- a/db/compaction/compaction_job.cc +++ b/db/compaction/compaction_job.cc @@ -61,6 +61,48 @@ namespace ROCKSDB_NAMESPACE { +const char* GetCompactionReasonString(CompactionReason compaction_reason) { + switch (compaction_reason) { + case CompactionReason::kUnknown: + return "Unknown"; + case CompactionReason::kLevelL0FilesNum: + return "LevelL0FilesNum"; + case CompactionReason::kLevelMaxLevelSize: + return "LevelMaxLevelSize"; + case CompactionReason::kUniversalSizeAmplification: + return "UniversalSizeAmplification"; + case CompactionReason::kUniversalSizeRatio: + return "UniversalSizeRatio"; + case CompactionReason::kUniversalSortedRunNum: + return "UniversalSortedRunNum"; + case CompactionReason::kFIFOMaxSize: + return "FIFOMaxSize"; + case CompactionReason::kFIFOReduceNumFiles: + return "FIFOReduceNumFiles"; + case CompactionReason::kFIFOTtl: + return "FIFOTtl"; + case CompactionReason::kManualCompaction: + return "ManualCompaction"; + case CompactionReason::kFilesMarkedForCompaction: + return "FilesMarkedForCompaction"; + case CompactionReason::kBottommostFiles: + return "BottommostFiles"; + case CompactionReason::kTtl: + return "Ttl"; + case CompactionReason::kFlush: + return "Flush"; + case CompactionReason::kExternalSstIngestion: + return "ExternalSstIngestion"; + case CompactionReason::kPeriodicCompaction: + return "PeriodicCompaction"; + case CompactionReason::kNumOfReasons: + // fall through + default: + assert(false); + return "Invalid"; + } +} + // Maintains state for each sub-compaction struct CompactionJob::SubcompactionState { const Compaction* compaction; @@ -1641,7 +1683,7 @@ void CompactionJob::LogCompaction() { stream << "job" << job_id_ << "event" << "compaction_started" << "compaction_reason" - << compaction->GetCompactionReasonString(); + << GetCompactionReasonString(compaction->compaction_reason()); for (size_t i = 0; i < compaction->num_input_levels(); ++i) { stream << ("files_L" + ToString(compaction->level(i))); stream.StartArray(); From e5cc030b5145280462f9a56c2a8a4bacd02c49e1 Mon Sep 17 00:00:00 2001 From: Pulkit Agarwal Date: Mon, 9 Mar 2020 09:40:11 -0700 Subject: [PATCH 3/6] 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) { From 9eb2cdefbc2759316f9914dfd8b89311716ebe32 Mon Sep 17 00:00:00 2001 From: Pulkit Agarwal Date: Mon, 9 Mar 2020 12:04:28 -0700 Subject: [PATCH 4/6] Fix typo --- include/rocksdb/convenience.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rocksdb/convenience.h b/include/rocksdb/convenience.h index f1b5623df13..c884e41f5f3 100644 --- a/include/rocksdb/convenience.h +++ b/include/rocksdb/convenience.h @@ -297,7 +297,7 @@ Status GetStringFromColumnFamilyOptions(std::string* opts_str, Status GetStringFromCompressionType(std::string* compression_str, CompressionType compression_type); -Status GetStringFromCompactionReason(std::string* compression_str, +Status GetStringFromCompactionReason(std::string* compaction_str, CompactionReason compaction_reason); std::vector GetSupportedCompressions(); From 408c987d808840d180b26abd078fe690d4a9ebf1 Mon Sep 17 00:00:00 2001 From: Pulkit Agarwal Date: Mon, 9 Mar 2020 14:13:16 -0700 Subject: [PATCH 5/6] Revert "Make GetCompactionReasonString() publicly visible" This reverts commit e5cc030b5145280462f9a56c2a8a4bacd02c49e1. --- include/rocksdb/convenience.h | 4 ---- options/options_helper.cc | 31 ------------------------------- options/options_helper.h | 8 ++------ options/options_test.cc | 23 ----------------------- 4 files changed, 2 insertions(+), 64 deletions(-) diff --git a/include/rocksdb/convenience.h b/include/rocksdb/convenience.h index c884e41f5f3..442303d9486 100644 --- a/include/rocksdb/convenience.h +++ b/include/rocksdb/convenience.h @@ -10,7 +10,6 @@ #include #include "rocksdb/db.h" -#include "rocksdb/listener.h" #include "rocksdb/options.h" #include "rocksdb/table.h" @@ -297,9 +296,6 @@ Status GetStringFromColumnFamilyOptions(std::string* opts_str, Status GetStringFromCompressionType(std::string* compression_str, CompressionType compression_type); -Status GetStringFromCompactionReason(std::string* compaction_str, - CompactionReason compaction_reason); - std::vector GetSupportedCompressions(); Status GetBlockBasedTableOptionsFromString( diff --git a/options/options_helper.cc b/options/options_helper.cc index 3961d6cddab..bc36dbcfe72 100644 --- a/options/options_helper.cc +++ b/options/options_helper.cc @@ -14,7 +14,6 @@ #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" @@ -254,25 +253,6 @@ 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"; @@ -1204,17 +1184,6 @@ 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 60422ec25cc..c75fdb1ceb4 100644 --- a/options/options_helper.h +++ b/options/options_helper.h @@ -155,8 +155,6 @@ 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 @@ -201,10 +199,6 @@ 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 = @@ -216,6 +210,8 @@ 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 a8af5df0b53..9ff99532cda 100644 --- a/options/options_test.cc +++ b/options/options_test.cc @@ -20,7 +20,6 @@ #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" @@ -1080,28 +1079,6 @@ 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) { From d1baf59d519896ac583c38c53da4bbb932984896 Mon Sep 17 00:00:00 2001 From: Pulkit Agarwal Date: Sun, 5 Apr 2020 20:00:27 -0700 Subject: [PATCH 6/6] Add GetCompactionReasonString() to listener.h --- CMakeLists.txt | 1 + TARGETS | 1 + db/listener.cc | 69 ++++++++++++++++++++++++++++++++++++++ db/listener_test.cc | 24 +++++++++++++ include/rocksdb/listener.h | 3 ++ src.mk | 1 + 6 files changed, 99 insertions(+) create mode 100644 db/listener.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ec3e7d2307..e9bb0587321 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -537,6 +537,7 @@ set(SOURCES db/forward_iterator.cc db/import_column_family_job.cc db/internal_stats.cc + db/listener.cc db/logs_with_prep_tracker.cc db/log_reader.cc db/log_writer.cc diff --git a/TARGETS b/TARGETS index afd52bd8848..117b646867a 100644 --- a/TARGETS +++ b/TARGETS @@ -152,6 +152,7 @@ cpp_library( "db/forward_iterator.cc", "db/import_column_family_job.cc", "db/internal_stats.cc", + "db/listener.cc", "db/log_reader.cc", "db/log_writer.cc", "db/logs_with_prep_tracker.cc", diff --git a/db/listener.cc b/db/listener.cc new file mode 100644 index 00000000000..69d7b379790 --- /dev/null +++ b/db/listener.cc @@ -0,0 +1,69 @@ +// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. +// 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). +// + +#include "rocksdb/listener.h" + +namespace ROCKSDB_NAMESPACE { + +Status GetStringFromCompactionReason(std::string* compaction_str, + CompactionReason compaction_reason) { + switch (compaction_reason) { + case CompactionReason::kUnknown: + *compaction_str = "Unknown"; + return Status::OK(); + case CompactionReason::kLevelL0FilesNum: + *compaction_str = "LevelL0FilesNum"; + return Status::OK(); + case CompactionReason::kLevelMaxLevelSize: + *compaction_str = "LevelMaxLevelSize"; + return Status::OK(); + case CompactionReason::kUniversalSizeAmplification: + *compaction_str = "UniversalSizeAmplification"; + return Status::OK(); + case CompactionReason::kUniversalSizeRatio: + *compaction_str = "UniversalSizeRatio"; + return Status::OK(); + case CompactionReason::kUniversalSortedRunNum: + *compaction_str = "UniversalSortedRunNum"; + return Status::OK(); + case CompactionReason::kFIFOMaxSize: + *compaction_str = "FIFOMaxSize"; + return Status::OK(); + case CompactionReason::kFIFOReduceNumFiles: + *compaction_str = "FIFOReduceNumFiles"; + return Status::OK(); + case CompactionReason::kFIFOTtl: + *compaction_str = "FIFOTtl"; + return Status::OK(); + case CompactionReason::kManualCompaction: + *compaction_str = "ManualCompaction"; + return Status::OK(); + case CompactionReason::kFilesMarkedForCompaction: + *compaction_str = "FilesMarkedForCompaction"; + return Status::OK(); + case CompactionReason::kBottommostFiles: + *compaction_str = "BottommostFiles"; + return Status::OK(); + case CompactionReason::kTtl: + *compaction_str = "Ttl"; + return Status::OK(); + case CompactionReason::kFlush: + *compaction_str = "Flush"; + return Status::OK(); + case CompactionReason::kExternalSstIngestion: + *compaction_str = "ExternalSstIngestion"; + return Status::OK(); + case CompactionReason::kPeriodicCompaction: + *compaction_str = "PeriodicCompaction"; + return Status::OK(); + case CompactionReason::kNumOfReasons: + // fall through + default: + return Status::InvalidArgument("Invalid compaction reason"); + } +} + +} diff --git a/db/listener_test.cc b/db/listener_test.cc index eb1a08a3548..3d6408ec4fc 100644 --- a/db/listener_test.cc +++ b/db/listener_test.cc @@ -18,6 +18,7 @@ #include "rocksdb/db.h" #include "rocksdb/env.h" #include "rocksdb/filter_policy.h" +#include "rocksdb/listener.h" #include "rocksdb/options.h" #include "rocksdb/perf_context.h" #include "rocksdb/slice.h" @@ -39,6 +40,8 @@ namespace ROCKSDB_NAMESPACE { +class ListenerTest : public testing::Test {}; + class EventListenerTest : public DBTestBase { public: EventListenerTest() : DBTestBase("/listener_test") {} @@ -1032,6 +1035,27 @@ TEST_F(EventListenerTest, OnFileOperationTest) { ASSERT_GT(listener->file_reads_.load(), 0); } +TEST_F(ListenerTest, 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))); +} } // namespace ROCKSDB_NAMESPACE #endif // ROCKSDB_LITE diff --git a/include/rocksdb/listener.h b/include/rocksdb/listener.h index d1c953f0f0e..2da690c43d1 100644 --- a/include/rocksdb/listener.h +++ b/include/rocksdb/listener.h @@ -135,6 +135,9 @@ struct WriteStallInfo { } condition; }; +Status GetStringFromCompactionReason(std::string* compaction_str, + CompactionReason compaction_reason); + #ifndef ROCKSDB_LITE struct TableFileDeletionInfo { diff --git a/src.mk b/src.mk index 9e9dd1a9e81..7a978bb5687 100644 --- a/src.mk +++ b/src.mk @@ -40,6 +40,7 @@ LIB_SOURCES = \ db/forward_iterator.cc \ db/import_column_family_job.cc \ db/internal_stats.cc \ + db/listener.cc \ db/logs_with_prep_tracker.cc \ db/log_reader.cc \ db/log_writer.cc \