Add GetStringFromCompressionType to include/rocksdb/convenience.h
Summary: Expose a simple function to convert CompressionType to it's corresponding option string This is for a diff @yoshinorim is working on for MyRocks Test Plan: unittest Reviewers: yhchiang, andrewkr, sdong Reviewed By: sdong Subscribers: andrewkr, dhruba, yoshinorim Differential Revision: https://reviews.facebook.net/D58215
This commit is contained in:
parent
c70a9335de
commit
533cda90ce
@ -5,8 +5,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "rocksdb/db.h"
|
#include "rocksdb/db.h"
|
||||||
#include "rocksdb/options.h"
|
#include "rocksdb/options.h"
|
||||||
#include "rocksdb/table.h"
|
#include "rocksdb/table.h"
|
||||||
@ -76,6 +78,9 @@ Status GetStringFromColumnFamilyOptions(std::string* opts_str,
|
|||||||
const ColumnFamilyOptions& db_options,
|
const ColumnFamilyOptions& db_options,
|
||||||
const std::string& delimiter = "; ");
|
const std::string& delimiter = "; ");
|
||||||
|
|
||||||
|
Status GetStringFromCompressionType(std::string* compression_str,
|
||||||
|
CompressionType compression_type);
|
||||||
|
|
||||||
Status GetBlockBasedTableOptionsFromString(
|
Status GetBlockBasedTableOptionsFromString(
|
||||||
const BlockBasedTableOptions& table_options,
|
const BlockBasedTableOptions& table_options,
|
||||||
const std::string& opts_str,
|
const std::string& opts_str,
|
||||||
|
@ -955,6 +955,17 @@ Status GetStringFromColumnFamilyOptions(std::string* opt_string,
|
|||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status GetStringFromCompressionType(std::string* compression_str,
|
||||||
|
CompressionType compression_type) {
|
||||||
|
bool ok = SerializeEnum<CompressionType>(compression_type_string_map,
|
||||||
|
compression_type, compression_str);
|
||||||
|
if (ok) {
|
||||||
|
return Status::OK();
|
||||||
|
} else {
|
||||||
|
return Status::InvalidArgument("Invalid compression types");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool SerializeSingleBlockBasedTableOption(
|
bool SerializeSingleBlockBasedTableOption(
|
||||||
std::string* opt_string, const BlockBasedTableOptions& bbt_options,
|
std::string* opt_string, const BlockBasedTableOptions& bbt_options,
|
||||||
const std::string& name, const std::string& delimiter) {
|
const std::string& name, const std::string& delimiter) {
|
||||||
|
@ -836,6 +836,28 @@ TEST_F(OptionsTest, StringToMapRandomTest) {
|
|||||||
opts_map.clear();
|
opts_map.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(OptionsTest, GetStringFromCompressionType) {
|
||||||
|
std::string res;
|
||||||
|
|
||||||
|
ASSERT_OK(GetStringFromCompressionType(&res, kNoCompression));
|
||||||
|
ASSERT_EQ(res, "kNoCompression");
|
||||||
|
|
||||||
|
ASSERT_OK(GetStringFromCompressionType(&res, kSnappyCompression));
|
||||||
|
ASSERT_EQ(res, "kSnappyCompression");
|
||||||
|
|
||||||
|
ASSERT_OK(GetStringFromCompressionType(&res, kDisableCompressionOption));
|
||||||
|
ASSERT_EQ(res, "kDisableCompressionOption");
|
||||||
|
|
||||||
|
ASSERT_OK(GetStringFromCompressionType(&res, kLZ4Compression));
|
||||||
|
ASSERT_EQ(res, "kLZ4Compression");
|
||||||
|
|
||||||
|
ASSERT_OK(GetStringFromCompressionType(&res, kZlibCompression));
|
||||||
|
ASSERT_EQ(res, "kZlibCompression");
|
||||||
|
|
||||||
|
ASSERT_NOK(
|
||||||
|
GetStringFromCompressionType(&res, static_cast<CompressionType>(-10)));
|
||||||
|
}
|
||||||
#endif // !ROCKSDB_LITE
|
#endif // !ROCKSDB_LITE
|
||||||
|
|
||||||
TEST_F(OptionsTest, ConvertOptionsTest) {
|
TEST_F(OptionsTest, ConvertOptionsTest) {
|
||||||
|
Loading…
Reference in New Issue
Block a user