]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
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 | ||
f67539c2 | 12 | namespace ROCKSDB_NAMESPACE { |
7c673cae | 13 | |
7c673cae FG |
14 | namespace { |
15 | ||
7c673cae | 16 | uint64_t GetUint64Property(const UserCollectedProperties& props, |
11fdf7f2 | 17 | const std::string& property_name, |
7c673cae FG |
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 | if (!ParseInternalKey(key, &ikey)) { | |
37 | return Status::InvalidArgument("Invalid internal key"); | |
38 | } | |
39 | ||
40 | return collector_->AddUserKey(ikey.user_key, value, GetEntryType(ikey.type), | |
41 | ikey.sequence, file_size); | |
42 | } | |
43 | ||
494da23a TL |
44 | void UserKeyTablePropertiesCollector::BlockAdd( |
45 | uint64_t bLockRawBytes, uint64_t blockCompressedBytesFast, | |
46 | uint64_t blockCompressedBytesSlow) { | |
47 | return collector_->BlockAdd(bLockRawBytes, blockCompressedBytesFast, | |
48 | blockCompressedBytesSlow); | |
49 | } | |
50 | ||
7c673cae FG |
51 | Status UserKeyTablePropertiesCollector::Finish( |
52 | UserCollectedProperties* properties) { | |
53 | return collector_->Finish(properties); | |
54 | } | |
55 | ||
56 | UserCollectedProperties | |
57 | UserKeyTablePropertiesCollector::GetReadableProperties() const { | |
58 | return collector_->GetReadableProperties(); | |
59 | } | |
60 | ||
7c673cae FG |
61 | uint64_t GetDeletedKeys( |
62 | const UserCollectedProperties& props) { | |
63 | bool property_present_ignored; | |
494da23a | 64 | return GetUint64Property(props, TablePropertiesNames::kDeletedKeys, |
7c673cae FG |
65 | &property_present_ignored); |
66 | } | |
67 | ||
68 | uint64_t GetMergeOperands(const UserCollectedProperties& props, | |
69 | bool* property_present) { | |
70 | return GetUint64Property( | |
494da23a | 71 | props, TablePropertiesNames::kMergeOperands, property_present); |
7c673cae FG |
72 | } |
73 | ||
f67539c2 | 74 | } // namespace ROCKSDB_NAMESPACE |