Skip to content

Commit 4cbc19d

Browse files
mrambacherfacebook-github-bot
authored andcommitted
Add a ConfigOptions for use in comparing objects and converting to/from strings (facebook#6389)
Summary: The methods in convenience.h are used to compare/convert objects to/from strings. There is a mishmash of parameters in use here with more needed in the future. This PR replaces those parameters with a single structure. Pull Request resolved: facebook#6389 Reviewed By: siying Differential Revision: D21163707 Pulled By: zhichao-cao fbshipit-source-id: f807b4cc7e2b0af3871536b69546b2604dfa81bd
1 parent c1ccd6b commit 4cbc19d

40 files changed

+2582
-753
lines changed

HISTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Finish implementation of BlockBasedTableOptions::IndexType::kBinarySearchWithFirstKey. It's now ready for use. Significantly reduces read amplification in some setups, especially for iterator seeks.
66

77
### Public API Change
8+
* Add a ConfigOptions argument to the APIs dealing with converting options to and from strings and files. The ConfigOptions is meant to replace some of the options (such as input_strings_escaped and ignore_unknown_options) and allow for more parameters to be passed in the future without changing the function signature.
89
* Add NewFileChecksumGenCrc32cFactory to the file checksum public API, such that the builtin Crc32c based file checksum generator factory can be used by applications.
910
* Add IsDirectory to Env and FS to indicate if a path is a directory.
1011

db/column_family_test.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
// found in the LICENSE file. See the AUTHORS file for names of contributors.
99

1010
#include <algorithm>
11-
#include <vector>
1211
#include <string>
1312
#include <thread>
13+
#include <vector>
1414

1515
#include "db/db_impl/db_impl.h"
1616
#include "db/db_test_util.h"
17-
#include "memtable/hash_skiplist_rep.h"
1817
#include "options/options_parser.h"
1918
#include "port/port.h"
2019
#include "port/stack_trace.h"
20+
#include "rocksdb/convenience.h"
2121
#include "rocksdb/db.h"
2222
#include "rocksdb/env.h"
2323
#include "rocksdb/iterator.h"
@@ -287,7 +287,9 @@ class ColumnFamilyTestBase : public testing::Test {
287287
// Verify the CF options of the returned CF handle.
288288
ColumnFamilyDescriptor desc;
289289
ASSERT_OK(handles_[cfi]->GetDescriptor(&desc));
290-
RocksDBOptionsParser::VerifyCFOptions(desc.options, current_cf_opt);
290+
RocksDBOptionsParser::VerifyCFOptions(ConfigOptions(), desc.options,
291+
current_cf_opt);
292+
291293
#endif // !ROCKSDB_LITE
292294
cfi++;
293295
}

db/db_bloom_filter_test.cc

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// found in the LICENSE file. See the AUTHORS file for names of contributors.
99

1010
#include "db/db_test_util.h"
11+
#include "options/options_helper.h"
1112
#include "port/stack_trace.h"
1213
#include "rocksdb/perf_context.h"
1314
#include "table/block_based/filter_policy_internal.h"

db/db_options_test.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class DBOptionsTest : public DBTestBase {
3333
std::unordered_map<std::string, std::string> GetMutableDBOptionsMap(
3434
const DBOptions& options) {
3535
std::string options_str;
36-
GetStringFromDBOptions(&options_str, options);
36+
ConfigOptions config_options;
37+
config_options.delimiter = "; ";
38+
GetStringFromDBOptions(config_options, options, &options_str);
3739
std::unordered_map<std::string, std::string> options_map;
3840
StringToMap(options_str, &options_map);
3941
std::unordered_map<std::string, std::string> mutable_map;
@@ -48,7 +50,10 @@ class DBOptionsTest : public DBTestBase {
4850
std::unordered_map<std::string, std::string> GetMutableCFOptionsMap(
4951
const ColumnFamilyOptions& options) {
5052
std::string options_str;
51-
GetStringFromColumnFamilyOptions(&options_str, options);
53+
ConfigOptions config_options;
54+
config_options.delimiter = "; ";
55+
56+
GetStringFromColumnFamilyOptions(config_options, options, &options_str);
5257
std::unordered_map<std::string, std::string> options_map;
5358
StringToMap(options_str, &options_map);
5459
std::unordered_map<std::string, std::string> mutable_map;

examples/options_file_example.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ int main() {
7979
// Load the options file.
8080
DBOptions loaded_db_opt;
8181
std::vector<ColumnFamilyDescriptor> loaded_cf_descs;
82-
s = LoadLatestOptions(kDBPath, Env::Default(), &loaded_db_opt,
82+
ConfigOptions config_options;
83+
s = LoadLatestOptions(config_options, kDBPath, &loaded_db_opt,
8384
&loaded_cf_descs);
8485
assert(s.ok());
8586
assert(loaded_db_opt.create_if_missing == db_opt.create_if_missing);

include/rocksdb/convenience.h

+139-10
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,74 @@
1010
#include <vector>
1111

1212
#include "rocksdb/db.h"
13-
#include "rocksdb/options.h"
13+
#include "rocksdb/status.h"
1414
#include "rocksdb/table.h"
1515

1616
namespace ROCKSDB_NAMESPACE {
17+
class Env;
18+
struct ColumnFamilyOptions;
19+
struct DBOptions;
20+
struct Options;
21+
22+
// ConfigOptions containing the parameters/controls for
23+
// comparing objects and converting to/from strings.
24+
// These settings control how the methods
25+
// treat errors (e.g. ignore_unknown_objects), the format
26+
// of the serialization (e.g. delimiter), and how to compare
27+
// options (sanity_level).
28+
struct ConfigOptions {
29+
// This enum defines the RocksDB options sanity level.
30+
enum SanityLevel : unsigned char {
31+
kSanityLevelNone = 0x01, // Performs no sanity check at all.
32+
// Performs minimum check to ensure the RocksDB instance can be
33+
// opened without corrupting / mis-interpreting the data.
34+
kSanityLevelLooselyCompatible = 0x02,
35+
// Perform exact match sanity check.
36+
kSanityLevelExactMatch = 0xFF,
37+
};
38+
39+
enum Depth {
40+
kDepthDefault, // Traverse nested options that are not flagged as "shallow"
41+
kDepthShallow, // Do not traverse into any nested options
42+
kDepthDetailed, // Traverse nested options, overriding the options shallow
43+
// setting
44+
};
45+
46+
// When true, any unused options will be ignored and OK will be returned
47+
bool ignore_unknown_options = false;
48+
49+
// If the strings are escaped (old-style?)
50+
bool input_strings_escaped = true;
51+
52+
// The separator between options when converting to a string
53+
std::string delimiter = ";";
54+
55+
// Controls how to traverse options during print/match stages
56+
Depth depth = Depth::kDepthDefault;
57+
58+
// Controls how options are serialized
59+
// Controls how pedantic the comparison must be for equivalency
60+
SanityLevel sanity_level = SanityLevel::kSanityLevelExactMatch;
61+
// `file_readahead_size` is used for readahead for the option file.
62+
size_t file_readahead_size = 512 * 1024;
63+
64+
// The environment to use for this option
65+
Env* env = Env::Default();
66+
67+
bool IsShallow() const { return depth == Depth::kDepthShallow; }
68+
bool IsDetailed() const { return depth == Depth::kDepthDetailed; }
69+
70+
bool IsCheckDisabled() const {
71+
return sanity_level == SanityLevel::kSanityLevelNone;
72+
}
73+
74+
bool IsCheckEnabled(SanityLevel level) const {
75+
return (level > SanityLevel::kSanityLevelNone && level <= sanity_level);
76+
}
77+
};
1778

1879
#ifndef ROCKSDB_LITE
80+
1981
// The following set of functions provide a way to construct RocksDB Options
2082
// from a string or a string-to-string map. Here're the general rule of
2183
// setting option values from strings by type. Some RocksDB types are also
@@ -134,13 +196,6 @@ namespace ROCKSDB_NAMESPACE {
134196
// [Example]:
135197
// * {"memtable", "vector:1024"} is equivalent to setting memtable
136198
// to VectorRepFactory(1024).
137-
// - HashCuckooRepFactory:
138-
// Pass "cuckoo:<write_buffer_size>" to use HashCuckooRepFactory with the
139-
// specified write buffer size, or simply "cuckoo" to use the default
140-
// HashCuckooRepFactory.
141-
// [Example]:
142-
// * {"memtable", "cuckoo:1024"} is equivalent to setting memtable
143-
// to NewHashCuckooRepFactory(1024).
144199
//
145200
// * compression_opts:
146201
// Use "compression_opts" to config compression_opts. The value format
@@ -153,6 +208,12 @@ namespace ROCKSDB_NAMESPACE {
153208
// cf_opt.compression_opts.strategy = 6;
154209
// cf_opt.compression_opts.max_dict_bytes = 7;
155210
//
211+
// The GetColumnFamilyOptionsFromMap(ConfigOptions, ...) should be used; the
212+
// alternative signature may be deprecated in a future release. The equivalent
213+
// functionality can be achieved by setting the corresponding options in
214+
// the ConfigOptions parameter.
215+
//
216+
// @param config_options controls how the map is processed.
156217
// @param base_options the default options of the output "new_options".
157218
// @param opts_map an option name to value map for specifying how "new_options"
158219
// should be set.
@@ -165,6 +226,11 @@ namespace ROCKSDB_NAMESPACE {
165226
// instead of resulting in an unknown-option error.
166227
// @return Status::OK() on success. Otherwise, a non-ok status indicating
167228
// error will be returned, and "new_options" will be set to "base_options".
229+
Status GetColumnFamilyOptionsFromMap(
230+
const ConfigOptions& config_options,
231+
const ColumnFamilyOptions& base_options,
232+
const std::unordered_map<std::string, std::string>& opts_map,
233+
ColumnFamilyOptions* new_options);
168234
Status GetColumnFamilyOptionsFromMap(
169235
const ColumnFamilyOptions& base_options,
170236
const std::unordered_map<std::string, std::string>& opts_map,
@@ -184,6 +250,12 @@ Status GetColumnFamilyOptionsFromMap(
184250
// - Passing {"rate_limiter_bytes_per_sec", "1024"} is equivalent to
185251
// passing NewGenericRateLimiter(1024) to rate_limiter_bytes_per_sec.
186252
//
253+
// The GetDBOptionsFromMap(ConfigOptions, ...) should be used; the
254+
// alternative signature may be deprecated in a future release. The equivalent
255+
// functionality can be achieved by setting the corresponding options in
256+
// the ConfigOptions parameter.
257+
//
258+
// @param config_options controls how the map is processed.
187259
// @param base_options the default options of the output "new_options".
188260
// @param opts_map an option name to value map for specifying how "new_options"
189261
// should be set.
@@ -196,6 +268,10 @@ Status GetColumnFamilyOptionsFromMap(
196268
// instead of resulting in an unknown-option error.
197269
// @return Status::OK() on success. Otherwise, a non-ok status indicating
198270
// error will be returned, and "new_options" will be set to "base_options".
271+
Status GetDBOptionsFromMap(
272+
const ConfigOptions& cfg_options, const DBOptions& base_options,
273+
const std::unordered_map<std::string, std::string>& opts_map,
274+
DBOptions* new_options);
199275
Status GetDBOptionsFromMap(
200276
const DBOptions& base_options,
201277
const std::unordered_map<std::string, std::string>& opts_map,
@@ -227,6 +303,12 @@ Status GetDBOptionsFromMap(
227303
// - Passing {"block_cache", "1M"} in GetBlockBasedTableOptionsFromMap is
228304
// equivalent to setting block_cache using NewLRUCache(1024 * 1024).
229305
//
306+
// The GetBlockBasedTableOptionsFromMap(ConfigOptions, ...) should be used;
307+
// the alternative signature may be deprecated in a future release. The
308+
// equivalent functionality can be achieved by setting the corresponding
309+
// options in the ConfigOptions parameter.
310+
//
311+
// @param config_options controls how the map is processed.
230312
// @param table_options the default options of the output "new_table_options".
231313
// @param opts_map an option name to value map for specifying how
232314
// "new_table_options" should be set.
@@ -240,6 +322,11 @@ Status GetDBOptionsFromMap(
240322
// @return Status::OK() on success. Otherwise, a non-ok status indicating
241323
// error will be returned, and "new_table_options" will be set to
242324
// "table_options".
325+
Status GetBlockBasedTableOptionsFromMap(
326+
const ConfigOptions& config_options,
327+
const BlockBasedTableOptions& table_options,
328+
const std::unordered_map<std::string, std::string>& opts_map,
329+
BlockBasedTableOptions* new_table_options);
243330
Status GetBlockBasedTableOptionsFromMap(
244331
const BlockBasedTableOptions& table_options,
245332
const std::unordered_map<std::string, std::string>& opts_map,
@@ -250,6 +337,12 @@ Status GetBlockBasedTableOptionsFromMap(
250337
// map "opts_map" of option name to option value to construct the new
251338
// PlainTableOptions "new_table_options".
252339
//
340+
// The GetPlainTableOptionsFromMap(ConfigOptions, ...) should be used; the
341+
// alternative signature may be deprecated in a future release. The equivalent
342+
// functionality can be achieved by setting the corresponding options in
343+
// the ConfigOptions parameter.
344+
//
345+
// @param config_options controls how the map is processed.
253346
// @param table_options the default options of the output "new_table_options".
254347
// @param opts_map an option name to value map for specifying how
255348
// "new_table_options" should be set.
@@ -263,36 +356,61 @@ Status GetBlockBasedTableOptionsFromMap(
263356
// @return Status::OK() on success. Otherwise, a non-ok status indicating
264357
// error will be returned, and "new_table_options" will be set to
265358
// "table_options".
359+
Status GetPlainTableOptionsFromMap(
360+
const ConfigOptions& config_options, const PlainTableOptions& table_options,
361+
const std::unordered_map<std::string, std::string>& opts_map,
362+
PlainTableOptions* new_table_options);
266363
Status GetPlainTableOptionsFromMap(
267364
const PlainTableOptions& table_options,
268365
const std::unordered_map<std::string, std::string>& opts_map,
269366
PlainTableOptions* new_table_options, bool input_strings_escaped = false,
270367
bool ignore_unknown_options = false);
271368

272-
// Take a string representation of option names and values, apply them into the
369+
// Take a string representation of option names and values, apply them into the
273370
// base_options, and return the new options as a result. The string has the
274371
// following format:
275372
// "write_buffer_size=1024;max_write_buffer_number=2"
276373
// Nested options config is also possible. For example, you can define
277374
// BlockBasedTableOptions as part of the string for block-based table factory:
278375
// "write_buffer_size=1024;block_based_table_factory={block_size=4k};"
279376
// "max_write_buffer_num=2"
377+
//
378+
//
379+
// The GetColumnFamilyOptionsFromString(ConfigOptions, ...) should be used; the
380+
// alternative signature may be deprecated in a future release. The equivalent
381+
// functionality can be achieved by setting the corresponding options in
382+
// the ConfigOptions parameter.
383+
Status GetColumnFamilyOptionsFromString(const ConfigOptions& config_options,
384+
const ColumnFamilyOptions& base_options,
385+
const std::string& opts_str,
386+
ColumnFamilyOptions* new_options);
280387
Status GetColumnFamilyOptionsFromString(const ColumnFamilyOptions& base_options,
281388
const std::string& opts_str,
282389
ColumnFamilyOptions* new_options);
283390

391+
Status GetDBOptionsFromString(const ConfigOptions& config_options,
392+
const DBOptions& base_options,
393+
const std::string& opts_str,
394+
DBOptions* new_options);
395+
284396
Status GetDBOptionsFromString(const DBOptions& base_options,
285397
const std::string& opts_str,
286398
DBOptions* new_options);
287399

400+
Status GetStringFromDBOptions(const ConfigOptions& config_options,
401+
const DBOptions& db_options,
402+
std::string* opts_str);
403+
288404
Status GetStringFromDBOptions(std::string* opts_str,
289405
const DBOptions& db_options,
290406
const std::string& delimiter = "; ");
291407

408+
Status GetStringFromColumnFamilyOptions(const ConfigOptions& config_options,
409+
const ColumnFamilyOptions& cf_options,
410+
std::string* opts_str);
292411
Status GetStringFromColumnFamilyOptions(std::string* opts_str,
293412
const ColumnFamilyOptions& cf_options,
294413
const std::string& delimiter = "; ");
295-
296414
Status GetStringFromCompressionType(std::string* compression_str,
297415
CompressionType compression_type);
298416

@@ -301,17 +419,28 @@ std::vector<CompressionType> GetSupportedCompressions();
301419
Status GetBlockBasedTableOptionsFromString(
302420
const BlockBasedTableOptions& table_options, const std::string& opts_str,
303421
BlockBasedTableOptions* new_table_options);
422+
Status GetBlockBasedTableOptionsFromString(
423+
const ConfigOptions& config_options,
424+
const BlockBasedTableOptions& table_options, const std::string& opts_str,
425+
BlockBasedTableOptions* new_table_options);
304426

305427
Status GetPlainTableOptionsFromString(const PlainTableOptions& table_options,
306428
const std::string& opts_str,
307429
PlainTableOptions* new_table_options);
430+
Status GetPlainTableOptionsFromString(const ConfigOptions& config_options,
431+
const PlainTableOptions& table_options,
432+
const std::string& opts_str,
433+
PlainTableOptions* new_table_options);
308434

309435
Status GetMemTableRepFactoryFromString(
310436
const std::string& opts_str,
311437
std::unique_ptr<MemTableRepFactory>* new_mem_factory);
312438

313439
Status GetOptionsFromString(const Options& base_options,
314440
const std::string& opts_str, Options* new_options);
441+
Status GetOptionsFromString(const ConfigOptions& config_options,
442+
const Options& base_options,
443+
const std::string& opts_str, Options* new_options);
315444

316445
Status StringToMap(const std::string& opts_str,
317446
std::unordered_map<std::string, std::string>* opts_map);

include/rocksdb/table.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,24 @@
2525
#include "rocksdb/cache.h"
2626
#include "rocksdb/env.h"
2727
#include "rocksdb/iterator.h"
28-
#include "rocksdb/options.h"
2928
#include "rocksdb/status.h"
3029

3130
namespace ROCKSDB_NAMESPACE {
3231

3332
// -- Block-based Table
33+
class FilterPolicy;
3434
class FlushBlockPolicyFactory;
3535
class PersistentCache;
3636
class RandomAccessFile;
3737
struct TableReaderOptions;
3838
struct TableBuilderOptions;
3939
class TableBuilder;
40+
class TableFactory;
4041
class TableReader;
4142
class WritableFileWriter;
43+
struct ColumnFamilyOptions;
44+
struct ConfigOptions;
45+
struct DBOptions;
4246
struct EnvOptions;
4347
struct Options;
4448

@@ -555,8 +559,8 @@ class TableFactory {
555559
// RocksDB prints configurations at DB Open().
556560
virtual std::string GetPrintableTableOptions() const = 0;
557561

558-
virtual Status GetOptionString(std::string* /*opt_string*/,
559-
const std::string& /*delimiter*/) const {
562+
virtual Status GetOptionString(const ConfigOptions& /*config_options*/,
563+
std::string* /*opt_string*/) const {
560564
return Status::NotSupported(
561565
"The table factory doesn't implement GetOptionString().");
562566
}

0 commit comments

Comments
 (0)