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).
6 #include "db/table_properties_collector.h"
8 #include "db/dbformat.h"
9 #include "util/coding.h"
10 #include "util/string_util.h"
12 namespace ROCKSDB_NAMESPACE
{
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;
24 Slice raw
= pos
->second
;
26 *property_present
= true;
27 return GetVarint64(&raw
, &val
) ? val
: 0;
30 } // anonymous namespace
32 Status
UserKeyTablePropertiesCollector::InternalAdd(const Slice
& key
,
35 ParsedInternalKey ikey
;
36 Status s
= ParseInternalKey(key
, &ikey
, false /* log_err_key */); // TODO
41 return collector_
->AddUserKey(ikey
.user_key
, value
, GetEntryType(ikey
.type
),
42 ikey
.sequence
, file_size
);
45 void UserKeyTablePropertiesCollector::BlockAdd(
46 uint64_t block_uncomp_bytes
, uint64_t block_compressed_bytes_fast
,
47 uint64_t block_compressed_bytes_slow
) {
48 return collector_
->BlockAdd(block_uncomp_bytes
, block_compressed_bytes_fast
,
49 block_compressed_bytes_slow
);
52 Status
UserKeyTablePropertiesCollector::Finish(
53 UserCollectedProperties
* properties
) {
54 return collector_
->Finish(properties
);
57 UserCollectedProperties
UserKeyTablePropertiesCollector::GetReadableProperties()
59 return collector_
->GetReadableProperties();
62 uint64_t GetDeletedKeys(const UserCollectedProperties
& props
) {
63 bool property_present_ignored
;
64 return GetUint64Property(props
, TablePropertiesNames::kDeletedKeys
,
65 &property_present_ignored
);
68 uint64_t GetMergeOperands(const UserCollectedProperties
& props
,
69 bool* property_present
) {
70 return GetUint64Property(props
, TablePropertiesNames::kMergeOperands
,
74 } // namespace ROCKSDB_NAMESPACE