table_properties_collector.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include "db/table_properties_collector.h"
  6. #include "db/dbformat.h"
  7. #include "util/coding.h"
  8. #include "util/string_util.h"
  9. namespace ROCKSDB_NAMESPACE {
  10. namespace {
  11. uint64_t GetUint64Property(const UserCollectedProperties& props,
  12. const std::string& property_name,
  13. bool* property_present) {
  14. auto pos = props.find(property_name);
  15. if (pos == props.end()) {
  16. *property_present = false;
  17. return 0;
  18. }
  19. Slice raw = pos->second;
  20. uint64_t val = 0;
  21. *property_present = true;
  22. return GetVarint64(&raw, &val) ? val : 0;
  23. }
  24. } // namespace
  25. Status UserKeyTablePropertiesCollector::InternalAdd(const Slice& key,
  26. const Slice& value,
  27. uint64_t file_size) {
  28. ParsedInternalKey ikey;
  29. if (!ParseInternalKey(key, &ikey)) {
  30. return Status::InvalidArgument("Invalid internal key");
  31. }
  32. return collector_->AddUserKey(ikey.user_key, value, GetEntryType(ikey.type),
  33. ikey.sequence, file_size);
  34. }
  35. void UserKeyTablePropertiesCollector::BlockAdd(
  36. uint64_t bLockRawBytes, uint64_t blockCompressedBytesFast,
  37. uint64_t blockCompressedBytesSlow) {
  38. return collector_->BlockAdd(bLockRawBytes, blockCompressedBytesFast,
  39. blockCompressedBytesSlow);
  40. }
  41. Status UserKeyTablePropertiesCollector::Finish(
  42. UserCollectedProperties* properties) {
  43. return collector_->Finish(properties);
  44. }
  45. UserCollectedProperties
  46. UserKeyTablePropertiesCollector::GetReadableProperties() const {
  47. return collector_->GetReadableProperties();
  48. }
  49. uint64_t GetDeletedKeys(
  50. const UserCollectedProperties& props) {
  51. bool property_present_ignored;
  52. return GetUint64Property(props, TablePropertiesNames::kDeletedKeys,
  53. &property_present_ignored);
  54. }
  55. uint64_t GetMergeOperands(const UserCollectedProperties& props,
  56. bool* property_present) {
  57. return GetUint64Property(
  58. props, TablePropertiesNames::kMergeOperands, property_present);
  59. }
  60. } // namespace ROCKSDB_NAMESPACE