Skip to content

Commit

Permalink
move enum class to_string into options_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
darionyaphet committed Sep 5, 2023
1 parent 288dacc commit 1a0e42f
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 156 deletions.
8 changes: 8 additions & 0 deletions include/rocksdb/convenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,20 @@ Status GetStringFromDBOptions(std::string* opts_str,
Status GetStringFromColumnFamilyOptions(const ConfigOptions& config_options,
const ColumnFamilyOptions& cf_options,
std::string* opts_str);

Status GetStringFromColumnFamilyOptions(std::string* opts_str,
const ColumnFamilyOptions& cf_options,
const std::string& delimiter = "; ");

Status GetStringFromCompressionType(std::string* compression_str,
CompressionType compression_type);

std::string GetStringFromCompactionReason(CompactionReason compression_reason);

std::string GetStringFromFlushReason(FlushReason flush_reason);

std::string GetStringFromBackgroundErrorReason(BackgroundErrorReason background_error_reason);

std::vector<CompressionType> GetSupportedCompressions();

Status GetBlockBasedTableOptionsFromString(
Expand Down
156 changes: 0 additions & 156 deletions include/rocksdb/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,79 +161,6 @@ 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 @@ -253,58 +180,6 @@ 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 @@ -319,37 +194,6 @@ 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 Down
156 changes: 156 additions & 0 deletions options/options_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,162 @@ Status GetStringFromCompressionType(std::string* compression_str,
}
}

std::string GetStringFromCompactionReason(CompactionReason compression_reason) {
std::string result;
switch (compression_reason) {
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;
}

std::string GetStringFromFlushReason(FlushReason flush_reason) {
std::string result;
switch (flush_reason) {
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;
}

std::string GetStringFromBackgroundErrorReason(BackgroundErrorReason background_error_reason) {
std::string result;
switch (background_error_reason) {
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;
}

Status GetColumnFamilyOptionsFromMap(
const ConfigOptions& config_options,
const ColumnFamilyOptions& base_options,
Expand Down

0 comments on commit 1a0e42f

Please sign in to comment.