]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/table_properties_collector.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / db / table_properties_collector.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 #include "db/table_properties_collector.h"
7
8 #include "db/dbformat.h"
9 #include "util/coding.h"
10 #include "util/string_util.h"
11
12 namespace rocksdb {
13
14 Status InternalKeyPropertiesCollector::InternalAdd(const Slice& key,
15 const Slice& /*value*/,
16 uint64_t /*file_size*/) {
17 ParsedInternalKey ikey;
18 if (!ParseInternalKey(key, &ikey)) {
19 return Status::InvalidArgument("Invalid internal key");
20 }
21
22 // Note: We count both, deletions and single deletions here.
23 if (ikey.type == ValueType::kTypeDeletion ||
24 ikey.type == ValueType::kTypeSingleDeletion) {
25 ++deleted_keys_;
26 } else if (ikey.type == ValueType::kTypeMerge) {
27 ++merge_operands_;
28 }
29
30 return Status::OK();
31 }
32
33 Status InternalKeyPropertiesCollector::Finish(
34 UserCollectedProperties* properties) {
35 assert(properties);
36 assert(properties->find(
37 InternalKeyTablePropertiesNames::kDeletedKeys) == properties->end());
38 assert(properties->find(InternalKeyTablePropertiesNames::kMergeOperands) ==
39 properties->end());
40
41 std::string val_deleted_keys;
42 PutVarint64(&val_deleted_keys, deleted_keys_);
43 properties->insert(
44 {InternalKeyTablePropertiesNames::kDeletedKeys, val_deleted_keys});
45
46 std::string val_merge_operands;
47 PutVarint64(&val_merge_operands, merge_operands_);
48 properties->insert(
49 {InternalKeyTablePropertiesNames::kMergeOperands, val_merge_operands});
50
51 return Status::OK();
52 }
53
54 UserCollectedProperties
55 InternalKeyPropertiesCollector::GetReadableProperties() const {
56 return {{"kDeletedKeys", ToString(deleted_keys_)},
57 {"kMergeOperands", ToString(merge_operands_)}};
58 }
59
60 namespace {
61
62 uint64_t GetUint64Property(const UserCollectedProperties& props,
63 const std::string& property_name,
64 bool* property_present) {
65 auto pos = props.find(property_name);
66 if (pos == props.end()) {
67 *property_present = false;
68 return 0;
69 }
70 Slice raw = pos->second;
71 uint64_t val = 0;
72 *property_present = true;
73 return GetVarint64(&raw, &val) ? val : 0;
74 }
75
76 } // namespace
77
78 Status UserKeyTablePropertiesCollector::InternalAdd(const Slice& key,
79 const Slice& value,
80 uint64_t file_size) {
81 ParsedInternalKey ikey;
82 if (!ParseInternalKey(key, &ikey)) {
83 return Status::InvalidArgument("Invalid internal key");
84 }
85
86 return collector_->AddUserKey(ikey.user_key, value, GetEntryType(ikey.type),
87 ikey.sequence, file_size);
88 }
89
90 Status UserKeyTablePropertiesCollector::Finish(
91 UserCollectedProperties* properties) {
92 return collector_->Finish(properties);
93 }
94
95 UserCollectedProperties
96 UserKeyTablePropertiesCollector::GetReadableProperties() const {
97 return collector_->GetReadableProperties();
98 }
99
100
101 const std::string InternalKeyTablePropertiesNames::kDeletedKeys
102 = "rocksdb.deleted.keys";
103 const std::string InternalKeyTablePropertiesNames::kMergeOperands =
104 "rocksdb.merge.operands";
105
106 uint64_t GetDeletedKeys(
107 const UserCollectedProperties& props) {
108 bool property_present_ignored;
109 return GetUint64Property(props, InternalKeyTablePropertiesNames::kDeletedKeys,
110 &property_present_ignored);
111 }
112
113 uint64_t GetMergeOperands(const UserCollectedProperties& props,
114 bool* property_present) {
115 return GetUint64Property(
116 props, InternalKeyTablePropertiesNames::kMergeOperands, property_present);
117 }
118
119 } // namespace rocksdb