]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/table_properties_collector.cc
d877a52c83a8153f832070f5a3e55e95748df1b3
[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_NAMESPACE {
13
14 namespace {
15
16 uint64_t GetUint64Property(const UserCollectedProperties& props,
17 const std::string& property_name,
18 bool* property_present) {
19 auto pos = props.find(property_name);
20 if (pos == props.end()) {
21 *property_present = false;
22 return 0;
23 }
24 Slice raw = pos->second;
25 uint64_t val = 0;
26 *property_present = true;
27 return GetVarint64(&raw, &val) ? val : 0;
28 }
29
30 } // namespace
31
32 Status UserKeyTablePropertiesCollector::InternalAdd(const Slice& key,
33 const Slice& value,
34 uint64_t file_size) {
35 ParsedInternalKey ikey;
36 Status s = ParseInternalKey(key, &ikey, false /* log_err_key */); // TODO
37 if (!s.ok()) {
38 return s;
39 }
40
41 return collector_->AddUserKey(ikey.user_key, value, GetEntryType(ikey.type),
42 ikey.sequence, file_size);
43 }
44
45 void UserKeyTablePropertiesCollector::BlockAdd(
46 uint64_t bLockRawBytes, uint64_t blockCompressedBytesFast,
47 uint64_t blockCompressedBytesSlow) {
48 return collector_->BlockAdd(bLockRawBytes, blockCompressedBytesFast,
49 blockCompressedBytesSlow);
50 }
51
52 Status UserKeyTablePropertiesCollector::Finish(
53 UserCollectedProperties* properties) {
54 return collector_->Finish(properties);
55 }
56
57 UserCollectedProperties
58 UserKeyTablePropertiesCollector::GetReadableProperties() const {
59 return collector_->GetReadableProperties();
60 }
61
62 uint64_t GetDeletedKeys(
63 const UserCollectedProperties& props) {
64 bool property_present_ignored;
65 return GetUint64Property(props, TablePropertiesNames::kDeletedKeys,
66 &property_present_ignored);
67 }
68
69 uint64_t GetMergeOperands(const UserCollectedProperties& props,
70 bool* property_present) {
71 return GetUint64Property(
72 props, TablePropertiesNames::kMergeOperands, property_present);
73 }
74
75 } // namespace ROCKSDB_NAMESPACE