Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose GetCompactionReasonString() publicly #6489

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
69 changes: 69 additions & 0 deletions db/listener.cc
Original file line number Diff line number Diff line change
@@ -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");
}
}

}
24 changes: 24 additions & 0 deletions db/listener_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -39,6 +40,8 @@

namespace ROCKSDB_NAMESPACE {

class ListenerTest : public testing::Test {};

class EventListenerTest : public DBTestBase {
public:
EventListenerTest() : DBTestBase("/listener_test") {}
Expand Down Expand Up @@ -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<CompactionReason>(-10)));
}
} // namespace ROCKSDB_NAMESPACE

#endif // ROCKSDB_LITE
Expand Down
3 changes: 3 additions & 0 deletions include/rocksdb/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ struct WriteStallInfo {
} condition;
};

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

#ifndef ROCKSDB_LITE

struct TableFileDeletionInfo {
Expand Down
1 change: 1 addition & 0 deletions src.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down