]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/cache/cache.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / cache / cache.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 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10 #include "rocksdb/cache.h"
11
12 #include "cache/lru_cache.h"
13 #include "rocksdb/utilities/options_type.h"
14 #include "util/string_util.h"
15
16 namespace ROCKSDB_NAMESPACE {
17 #ifndef ROCKSDB_LITE
18 static std::unordered_map<std::string, OptionTypeInfo>
19 lru_cache_options_type_info = {
20 {"capacity",
21 {offsetof(struct LRUCacheOptions, capacity), OptionType::kSizeT,
22 OptionVerificationType::kNormal, OptionTypeFlags::kMutable}},
23 {"num_shard_bits",
24 {offsetof(struct LRUCacheOptions, num_shard_bits), OptionType::kInt,
25 OptionVerificationType::kNormal, OptionTypeFlags::kMutable}},
26 {"strict_capacity_limit",
27 {offsetof(struct LRUCacheOptions, strict_capacity_limit),
28 OptionType::kBoolean, OptionVerificationType::kNormal,
29 OptionTypeFlags::kMutable}},
30 {"high_pri_pool_ratio",
31 {offsetof(struct LRUCacheOptions, high_pri_pool_ratio),
32 OptionType::kDouble, OptionVerificationType::kNormal,
33 OptionTypeFlags::kMutable}},
34 };
35 #endif // ROCKSDB_LITE
36
37 Status Cache::CreateFromString(const ConfigOptions& config_options,
38 const std::string& value,
39 std::shared_ptr<Cache>* result) {
40 Status status;
41 std::shared_ptr<Cache> cache;
42 if (value.find('=') == std::string::npos) {
43 cache = NewLRUCache(ParseSizeT(value));
44 } else {
45 #ifndef ROCKSDB_LITE
46 LRUCacheOptions cache_opts;
47 status = OptionTypeInfo::ParseStruct(
48 config_options, "", &lru_cache_options_type_info, "", value,
49 reinterpret_cast<char*>(&cache_opts));
50 if (status.ok()) {
51 cache = NewLRUCache(cache_opts);
52 }
53 #else
54 (void)config_options;
55 status = Status::NotSupported("Cannot load cache in LITE mode ", value);
56 #endif //! ROCKSDB_LITE
57 }
58 if (status.ok()) {
59 result->swap(cache);
60 }
61 return status;
62 }
63 } // namespace ROCKSDB_NAMESPACE