Skip to content

Commit

Permalink
support to_string about listeners enum classes
Browse files Browse the repository at this point in the history
  • Loading branch information
darionyaphet committed Sep 4, 2023
1 parent f66df58 commit c2684a1
Showing 1 changed file with 156 additions and 2 deletions.
158 changes: 156 additions & 2 deletions include/rocksdb/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,79 @@ enum class CompactionReason : int {
kNumOfReasons,
};

inline std::string ToString(CompactionReason compactionReason) {
std::string result;
switch (compactionReason) {
case CompactionReason::kUnknown:
result = "Unknown";
break;
case CompactionReason::kLevelL0FilesNum:
result = "LevelL0FilesNum";
break;
case CompactionReason::kLevelMaxLevelSize:
result = "LevelMaxLevelSize";
break;
case CompactionReason::kUniversalSizeAmplification:
result = "UniversalSizeAmplification";
break;
case CompactionReason::kUniversalSizeRatio:
result = "UniversalSizeRatio";
break;
case CompactionReason::kUniversalSortedRunNum:
result = "UniversalSortedRunNum";
break;
case CompactionReason::kFIFOMaxSize:
result = "FIFOMaxSize";
break;
case CompactionReason::kFIFOReduceNumFiles:
result = "FIFOReduceNumFiles";
break;
case CompactionReason::kFIFOTtl:
result = "FIFOTtl";
break;
case CompactionReason::kManualCompaction:
result = "ManualCompaction";
break;
case CompactionReason::kFilesMarkedForCompaction:
result = "FilesMarkedForCompaction";
break;
case CompactionReason::kBottommostFiles:
result = "BottommostFiles";
break;
case CompactionReason::kTtl:
result = "Ttl";
break;
case CompactionReason::kFlush:
result = "Flush";
break;
case CompactionReason::kExternalSstIngestion:
result = "ExternalSstIngestion";
break;
case CompactionReason::kPeriodicCompaction:
result = "PeriodicCompaction";
break;
case CompactionReason::kChangeTemperature:
result = "ChangeTemperature";
break;
case CompactionReason::kForcedBlobGC:
result = "ForcedBlobGC";
break;
case CompactionReason::kRoundRobinTtl:
result = "RoundRobinTtl";
break;
case CompactionReason::kRefitLevel:
result = "RefitLevel";
break;
case CompactionReason::kNumOfReasons:
result = "NumOfReasons";
break;
default:
result = "UnSupport";
break;
}
return result;
}

enum class FlushReason : int {
kOthers = 0x00,
kGetLiveFiles = 0x01,
Expand All @@ -180,6 +253,58 @@ enum class FlushReason : int {
kWalFull = 0xd,
};

inline std::string ToString(FlushReason flushReason) {
std::string result;
switch (flushReason) {
case FlushReason::kOthers:
result = "Others";
break;
case FlushReason::kGetLiveFiles:
result = "GetLiveFiles";
break;
case FlushReason::kShutDown:
result = "ShutDown";
break;
case FlushReason::kExternalFileIngestion:
result = "ExternalFileIngestion";
break;
case FlushReason::kManualCompaction:
result = "ManualCompaction";
break;
case FlushReason::kWriteBufferManager:
result = "WriteBufferManager";
break;
case FlushReason::kWriteBufferFull:
result = "WriteBufferFull";
break;
case FlushReason::kTest:
result = "Test";
break;
case FlushReason::kDeleteFiles:
result = "DeleteFiles";
break;
case FlushReason::kAutoCompaction:
result = "AutoCompaction";
break;
case FlushReason::kManualFlush:
result = "ManualFlush";
break;
case FlushReason::kErrorRecovery:
result = "ErrorRecovery";
break;
case FlushReason::kErrorRecoveryRetryFlush:
result = "ErrorRecoveryRetryFlush";
break;
case FlushReason::kWalFull:
result = "WalFull";
break;
default:
result = "UnSupport";
break;
}
return result;
}

// TODO: In the future, BackgroundErrorReason will only be used to indicate
// why the BG Error is happening (e.g., flush, compaction). We may introduce
// other data structure to indicate other essential information such as
Expand All @@ -194,6 +319,37 @@ enum class BackgroundErrorReason {
kManifestWriteNoWAL,
};

inline std::string ToString(BackgroundErrorReason backgroundErrorReason) {
std::string result;
switch (backgroundErrorReason) {
case BackgroundErrorReason::kFlush:
result = "Flush";
break;
case BackgroundErrorReason::kCompaction:
result = "Compaction";
break;
case BackgroundErrorReason::kWriteCallback:
result = "WriteCallback";
break;
case BackgroundErrorReason::kMemTable:
result = "MemTable";
break;
case BackgroundErrorReason::kManifestWrite:
result = "ManifestWrite";
break;
case BackgroundErrorReason::kFlushNoWAL:
result = "FlushNoWAL";
break;
case BackgroundErrorReason::kManifestWriteNoWAL:
result = "ManifestWriteNoWAL";
break;
default:
result = "UnSupport";
break;
}
return result;
}

struct WriteStallInfo {
// the name of the column family
std::string cf_name;
Expand All @@ -204,7 +360,6 @@ struct WriteStallInfo {
} condition;
};


struct FileDeletionInfo {
FileDeletionInfo() = default;

Expand Down Expand Up @@ -836,5 +991,4 @@ class EventListener : public Customizable {
~EventListener() override {}
};


} // namespace ROCKSDB_NAMESPACE

0 comments on commit c2684a1

Please sign in to comment.