1 | /* |
2 | Copyright (c) 2014, SkySQL Ab |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; version 2 of the License. |
7 | |
8 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License |
14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
16 | |
17 | #pragma once |
18 | |
19 | /* C++ system header files */ |
20 | #include <string> |
21 | #include <unordered_map> |
22 | |
23 | /* RocksDB header files */ |
24 | #include "rocksdb/table.h" |
25 | #include "rocksdb/utilities/options_util.h" |
26 | |
27 | /* MyRocks header files */ |
28 | #include "./rdb_comparator.h" |
29 | |
30 | namespace myrocks { |
31 | |
32 | /* |
33 | Per-column family options configs. |
34 | |
35 | Per-column family option can be set |
36 | - Globally (the same value applies to all column families) |
37 | - Per column family: there is a {cf_name -> value} map, |
38 | and also there is a default value which applies to column |
39 | families not found in the map. |
40 | */ |
41 | class Rdb_cf_options { |
42 | public: |
43 | using Name_to_config_t = std::unordered_map<std::string, std::string>; |
44 | |
45 | Rdb_cf_options(const Rdb_cf_options &) = delete; |
46 | Rdb_cf_options &operator=(const Rdb_cf_options &) = delete; |
47 | Rdb_cf_options() = default; |
48 | |
49 | void get(const std::string &cf_name, |
50 | rocksdb::ColumnFamilyOptions *const opts); |
51 | |
52 | void update(const std::string &cf_name, const std::string &cf_options); |
53 | |
54 | bool init(const rocksdb::BlockBasedTableOptions &table_options, |
55 | std::shared_ptr<rocksdb::TablePropertiesCollectorFactory> |
56 | prop_coll_factory, |
57 | const char *const default_cf_options, |
58 | const char *const override_cf_options); |
59 | |
60 | const rocksdb::ColumnFamilyOptions &get_defaults() const { |
61 | return m_default_cf_opts; |
62 | } |
63 | |
64 | static const rocksdb::Comparator * |
65 | get_cf_comparator(const std::string &cf_name); |
66 | |
67 | std::shared_ptr<rocksdb::MergeOperator> |
68 | get_cf_merge_operator(const std::string &cf_name); |
69 | |
70 | void get_cf_options(const std::string &cf_name, |
71 | rocksdb::ColumnFamilyOptions *const opts) |
72 | MY_ATTRIBUTE((__nonnull__)); |
73 | |
74 | static bool parse_cf_options(const std::string &cf_options, |
75 | Name_to_config_t *option_map); |
76 | |
77 | private: |
78 | bool set_default(const std::string &default_config); |
79 | bool set_override(const std::string &overide_config); |
80 | |
81 | /* Helper string manipulation functions */ |
82 | static void skip_spaces(const std::string &input, size_t *const pos); |
83 | static bool find_column_family(const std::string &input, size_t *const pos, |
84 | std::string *const key); |
85 | static bool find_options(const std::string &input, size_t *const pos, |
86 | std::string *const options); |
87 | static bool find_cf_options_pair(const std::string &input, size_t *const pos, |
88 | std::string *const cf, |
89 | std::string *const opt_str); |
90 | |
91 | private: |
92 | static Rdb_pk_comparator s_pk_comparator; |
93 | static Rdb_rev_comparator s_rev_pk_comparator; |
94 | |
95 | /* CF name -> value map */ |
96 | Name_to_config_t m_name_map; |
97 | |
98 | /* The default value (if there is only one value, it is stored here) */ |
99 | std::string m_default_config; |
100 | |
101 | rocksdb::ColumnFamilyOptions m_default_cf_opts; |
102 | }; |
103 | |
104 | } // namespace myrocks |
105 | |