YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/util/options_parser.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
// This source code is licensed under the BSD-style license found in the
3
// LICENSE file in the root directory of this source tree. An additional grant
4
// of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
21
#ifndef YB_ROCKSDB_UTIL_OPTIONS_PARSER_H
22
#define YB_ROCKSDB_UTIL_OPTIONS_PARSER_H
23
24
#pragma once
25
26
#include <map>
27
#include <string>
28
#include <vector>
29
30
#include "yb/rocksdb/env.h"
31
#include "yb/rocksdb/options.h"
32
#include "yb/rocksdb/table/block_based_table_factory.h"
33
#include "yb/rocksdb/util/options_sanity_check.h"
34
35
namespace rocksdb {
36
37
#define ROCKSDB_OPTION_FILE_MAJOR 1
38
#define ROCKSDB_OPTION_FILE_MINOR 1
39
40
enum OptionSection : char {
41
  kOptionSectionVersion = 0,
42
  kOptionSectionDBOptions,
43
  kOptionSectionCFOptions,
44
  kOptionSectionTableOptions,
45
  kOptionSectionUnknown
46
};
47
48
static const std::string opt_section_titles[] = {
49
    "Version", "DBOptions", "CFOptions", "TableOptions/", "Unknown"};
50
51
YB_STRONGLY_TYPED_BOOL(IncludeHeader);
52
YB_STRONGLY_TYPED_BOOL(IncludeFileVersion);
53
54
Status PersistRocksDBOptions(const DBOptions& db_opt,
55
                             const std::vector<std::string>& cf_names,
56
                             const std::vector<ColumnFamilyOptions>& cf_opts,
57
                             const std::string& file_name, Env* env,
58
                             IncludeHeader include_header = IncludeHeader::kTrue,
59
                             IncludeFileVersion include_file_version = IncludeFileVersion::kTrue);
60
61
class RocksDBOptionsParser {
62
 public:
63
  RocksDBOptionsParser();
64
1.27M
  ~RocksDBOptionsParser() {}
65
  void Reset();
66
67
  Status Parse(const std::string& file_name, Env* env);
68
  static std::string TrimAndRemoveComment(const std::string& line,
69
                                          const bool trim_only = false);
70
71
1.27M
  const DBOptions* db_opt() const { return &db_opt_; }
72
1.27M
  const std::unordered_map<std::string, std::string>* db_opt_map() const {
73
1.27M
    return &db_opt_map_;
74
1.27M
  }
75
3.85M
  const std::vector<ColumnFamilyOptions>* cf_opts() const { return &cf_opts_; }
76
2.56M
  const std::vector<std::string>* cf_names() const { return &cf_names_; }
77
  const std::vector<std::unordered_map<std::string, std::string>>* cf_opt_maps()
78
1.28M
      const {
79
1.28M
    return &cf_opt_maps_;
80
1.28M
  }
81
82
5.14M
  const ColumnFamilyOptions* GetCFOptions(const std::string& name) {
83
5.14M
    return GetCFOptionsImpl(name);
84
5.14M
  }
85
  size_t NumColumnFamilies() { return cf_opts_.size(); }
86
87
  static Status VerifyRocksDBOptionsFromFile(
88
      const DBOptions& db_opt, const std::vector<std::string>& cf_names,
89
      const std::vector<ColumnFamilyOptions>& cf_opts,
90
      const std::string& file_name, Env* env,
91
      OptionsSanityCheckLevel sanity_check_level = kSanityLevelExactMatch);
92
93
  static Status VerifyDBOptions(
94
      const DBOptions& base_opt, const DBOptions& new_opt,
95
      const std::unordered_map<std::string, std::string>* new_opt_map = nullptr,
96
      OptionsSanityCheckLevel sanity_check_level = kSanityLevelExactMatch);
97
98
  static Status VerifyCFOptions(
99
      const ColumnFamilyOptions& base_opt, const ColumnFamilyOptions& new_opt,
100
      const std::unordered_map<std::string, std::string>* new_opt_map = nullptr,
101
      OptionsSanityCheckLevel sanity_check_level = kSanityLevelExactMatch);
102
103
  static Status VerifyTableFactory(
104
      const TableFactory* base_tf, const TableFactory* file_tf,
105
      OptionsSanityCheckLevel sanity_check_level = kSanityLevelExactMatch);
106
107
  static Status VerifyBlockBasedTableFactory(
108
      const BlockBasedTableFactory* base_tf,
109
      const BlockBasedTableFactory* file_tf,
110
      OptionsSanityCheckLevel sanity_check_level);
111
112
  static Status ExtraParserCheck(const RocksDBOptionsParser& input_parser);
113
114
 protected:
115
  bool IsSection(const std::string& line);
116
  Status ParseSection(OptionSection* section, std::string* title,
117
                      std::string* argument, const std::string& line,
118
                      const int line_num);
119
120
  Status CheckSection(const OptionSection section,
121
                      const std::string& section_arg, const int line_num);
122
123
  Status ParseStatement(std::string* name, std::string* value,
124
                        const std::string& line, const int line_num);
125
126
  Status EndSection(
127
      const OptionSection section, const std::string& title,
128
      const std::string& section_arg,
129
      const std::unordered_map<std::string, std::string>& opt_map);
130
131
  Status ValidityCheck();
132
133
  Status InvalidArgument(const int line_num, const std::string& message);
134
135
  Status ParseVersionNumber(const std::string& ver_name,
136
                            const std::string& ver_string, const int max_count,
137
                            int* version);
138
139
6.42M
  ColumnFamilyOptions* GetCFOptionsImpl(const std::string& name) {
140
6.42M
    assert(cf_names_.size() == cf_opts_.size());
141
6.48M
    for (size_t i = 0; i < cf_names_.size(); 
++i59.5k
) {
142
3.91M
      if (cf_names_[i] == name) {
143
3.85M
        return &cf_opts_[i];
144
3.85M
      }
145
3.91M
    }
146
2.57M
    return nullptr;
147
6.42M
  }
148
149
 private:
150
  DBOptions db_opt_;
151
  std::unordered_map<std::string, std::string> db_opt_map_;
152
  std::vector<std::string> cf_names_;
153
  std::vector<ColumnFamilyOptions> cf_opts_;
154
  std::vector<std::unordered_map<std::string, std::string>> cf_opt_maps_;
155
  bool has_version_section_;
156
  bool has_db_options_;
157
  bool has_default_cf_options_;
158
  int db_version[3];
159
  int opt_file_version[3];
160
};
161
162
}  // namespace rocksdb
163
164
#endif // YB_ROCKSDB_UTIL_OPTIONS_PARSER_H