]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/utilities/options/options_util.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / utilities / options / options_util.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5
6 #ifndef ROCKSDB_LITE
7
8 #include "rocksdb/utilities/options_util.h"
9
10 #include "options/options_parser.h"
11 #include "rocksdb/options.h"
12 #include "util/filename.h"
13
14 namespace rocksdb {
15 Status LoadOptionsFromFile(const std::string& file_name, Env* env,
16 DBOptions* db_options,
17 std::vector<ColumnFamilyDescriptor>* cf_descs,
18 bool ignore_unknown_options) {
19 RocksDBOptionsParser parser;
20 Status s = parser.Parse(file_name, env, ignore_unknown_options);
21 if (!s.ok()) {
22 return s;
23 }
24
25 *db_options = *parser.db_opt();
26
27 const std::vector<std::string>& cf_names = *parser.cf_names();
28 const std::vector<ColumnFamilyOptions>& cf_opts = *parser.cf_opts();
29 cf_descs->clear();
30 for (size_t i = 0; i < cf_opts.size(); ++i) {
31 cf_descs->push_back({cf_names[i], cf_opts[i]});
32 }
33 return Status::OK();
34 }
35
36 Status GetLatestOptionsFileName(const std::string& dbpath,
37 Env* env, std::string* options_file_name) {
38 Status s;
39 std::string latest_file_name;
40 uint64_t latest_time_stamp = 0;
41 std::vector<std::string> file_names;
42 s = env->GetChildren(dbpath, &file_names);
43 if (!s.ok()) {
44 return s;
45 }
46 for (auto& file_name : file_names) {
47 uint64_t time_stamp;
48 FileType type;
49 if (ParseFileName(file_name, &time_stamp, &type) && type == kOptionsFile) {
50 if (time_stamp > latest_time_stamp) {
51 latest_time_stamp = time_stamp;
52 latest_file_name = file_name;
53 }
54 }
55 }
56 if (latest_file_name.size() == 0) {
57 return Status::NotFound("No options files found in the DB directory.");
58 }
59 *options_file_name = latest_file_name;
60 return Status::OK();
61 }
62
63 Status LoadLatestOptions(const std::string& dbpath, Env* env,
64 DBOptions* db_options,
65 std::vector<ColumnFamilyDescriptor>* cf_descs,
66 bool ignore_unknown_options) {
67 std::string options_file_name;
68 Status s = GetLatestOptionsFileName(dbpath, env, &options_file_name);
69 if (!s.ok()) {
70 return s;
71 }
72
73 return LoadOptionsFromFile(dbpath + "/" + options_file_name, env, db_options,
74 cf_descs, ignore_unknown_options);
75 }
76
77 Status CheckOptionsCompatibility(
78 const std::string& dbpath, Env* env, const DBOptions& db_options,
79 const std::vector<ColumnFamilyDescriptor>& cf_descs,
80 bool ignore_unknown_options) {
81 std::string options_file_name;
82 Status s = GetLatestOptionsFileName(dbpath, env, &options_file_name);
83 if (!s.ok()) {
84 return s;
85 }
86
87 std::vector<std::string> cf_names;
88 std::vector<ColumnFamilyOptions> cf_opts;
89 for (const auto& cf_desc : cf_descs) {
90 cf_names.push_back(cf_desc.name);
91 cf_opts.push_back(cf_desc.options);
92 }
93
94 const OptionsSanityCheckLevel kDefaultLevel = kSanityLevelLooselyCompatible;
95
96 return RocksDBOptionsParser::VerifyRocksDBOptionsFromFile(
97 db_options, cf_names, cf_opts, dbpath + "/" + options_file_name, env,
98 kDefaultLevel, ignore_unknown_options);
99 }
100
101 } // namespace rocksdb
102 #endif // !ROCKSDB_LITE