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:
Islam AbdelRahman 2016-05-18 15:03:21 -07:00
parent c70a9335de
commit 533cda90ce
3 changed files with 39 additions and 1 deletions

View File

@ -5,8 +5,10 @@
#pragma once
#include <unordered_map>
#include <string>
#include <unordered_map>
#include <vector>
#include "rocksdb/db.h"
#include "rocksdb/options.h"
#include "rocksdb/table.h"
@ -76,6 +78,9 @@ Status GetStringFromColumnFamilyOptions(std::string* opts_str,
const ColumnFamilyOptions& db_options,
const std::string& delimiter = "; ");
Status GetStringFromCompressionType(std::string* compression_str,
CompressionType compression_type);
Status GetBlockBasedTableOptionsFromString(
const BlockBasedTableOptions& table_options,
const std::string& opts_str,

View File

@ -955,6 +955,17 @@ Status GetStringFromColumnFamilyOptions(std::string* opt_string,
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(
std::string* opt_string, const BlockBasedTableOptions& bbt_options,
const std::string& name, const std::string& delimiter) {

View File

@ -836,6 +836,28 @@ TEST_F(OptionsTest, StringToMapRandomTest) {
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
TEST_F(OptionsTest, ConvertOptionsTest) {