/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/table_properties_collector.cc
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 | | #include "yb/rocksdb/db/table_properties_collector.h" |
22 | | |
23 | | #include "yb/rocksdb/db/dbformat.h" |
24 | | #include "yb/rocksdb/util/coding.h" |
25 | | #include "yb/util/string_util.h" |
26 | | |
27 | | namespace rocksdb { |
28 | | |
29 | | Status InternalKeyPropertiesCollector::InternalAdd(const Slice& key, |
30 | | const Slice& value, |
31 | 70.9M | uint64_t file_size) { |
32 | 70.9M | ParsedInternalKey ikey; |
33 | 70.9M | if (!ParseInternalKey(key, &ikey)) { |
34 | 0 | return STATUS(InvalidArgument, "Invalid internal key"); |
35 | 0 | } |
36 | | |
37 | | // Note: We count both, deletions and single deletions here. |
38 | 70.9M | if (ikey.type == ValueType::kTypeDeletion || |
39 | 69.1M | ikey.type == ValueType::kTypeSingleDeletion) { |
40 | 1.91M | ++deleted_keys_; |
41 | 1.91M | } |
42 | | |
43 | 70.9M | return Status::OK(); |
44 | 70.9M | } |
45 | | |
46 | | Status InternalKeyPropertiesCollector::Finish( |
47 | 98.4k | UserCollectedProperties* properties) { |
48 | 98.4k | assert(properties); |
49 | 98.4k | assert(properties->find( |
50 | 98.4k | InternalKeyTablePropertiesNames::kDeletedKeys) == properties->end()); |
51 | 98.4k | std::string val; |
52 | | |
53 | 98.4k | PutVarint64(&val, deleted_keys_); |
54 | 98.4k | properties->insert({ InternalKeyTablePropertiesNames::kDeletedKeys, val }); |
55 | | |
56 | 98.4k | return Status::OK(); |
57 | 98.4k | } |
58 | | |
59 | | UserCollectedProperties |
60 | 48.5k | InternalKeyPropertiesCollector::GetReadableProperties() const { |
61 | 48.5k | return { |
62 | 48.5k | { "kDeletedKeys", ToString(deleted_keys_) } |
63 | 48.5k | }; |
64 | 48.5k | } |
65 | | |
66 | | namespace { |
67 | | |
68 | 6.44k | EntryType GetEntryType(ValueType value_type) { |
69 | 6.44k | switch (value_type) { |
70 | 5.57k | case kTypeValue: |
71 | 5.57k | return kEntryPut; |
72 | 852 | case kTypeDeletion: |
73 | 852 | return kEntryDelete; |
74 | 16 | case kTypeSingleDeletion: |
75 | 16 | return kEntrySingleDelete; |
76 | 0 | case kTypeMerge: |
77 | 0 | return kEntryMerge; |
78 | 0 | default: |
79 | 0 | return kEntryOther; |
80 | 6.44k | } |
81 | 6.44k | } |
82 | | |
83 | | } // namespace |
84 | | |
85 | | Status UserKeyTablePropertiesCollector::InternalAdd(const Slice& key, |
86 | | const Slice& value, |
87 | 6.44k | uint64_t file_size) { |
88 | 6.44k | ParsedInternalKey ikey; |
89 | 6.44k | if (!ParseInternalKey(key, &ikey)) { |
90 | 0 | return STATUS(InvalidArgument, "Invalid internal key"); |
91 | 0 | } |
92 | | |
93 | 6.44k | return collector_->AddUserKey(ikey.user_key, value, GetEntryType(ikey.type), |
94 | 6.44k | ikey.sequence, file_size); |
95 | 6.44k | } |
96 | | |
97 | | Status UserKeyTablePropertiesCollector::Finish( |
98 | 464 | UserCollectedProperties* properties) { |
99 | 464 | return collector_->Finish(properties); |
100 | 464 | } |
101 | | |
102 | | UserCollectedProperties |
103 | 224 | UserKeyTablePropertiesCollector::GetReadableProperties() const { |
104 | 224 | return collector_->GetReadableProperties(); |
105 | 224 | } |
106 | | |
107 | | |
108 | | const std::string InternalKeyTablePropertiesNames::kDeletedKeys |
109 | | = "rocksdb.deleted.keys"; |
110 | | |
111 | | uint64_t GetDeletedKeys( |
112 | 85.7k | const UserCollectedProperties& props) { |
113 | 85.7k | auto pos = props.find(InternalKeyTablePropertiesNames::kDeletedKeys); |
114 | 85.7k | if (pos == props.end()) { |
115 | 6.50k | return 0; |
116 | 6.50k | } |
117 | 79.2k | Slice raw = pos->second; |
118 | 79.2k | uint64_t val = 0; |
119 | 79.2k | return GetVarint64(&raw, &val) ? val : 0; |
120 | 79.2k | } |
121 | | |
122 | | } // namespace rocksdb |