table_properties_collector.cc 2.4 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. } // anonymous namespace
  25. Status UserKeyTablePropertiesCollector::InternalAdd(const Slice& key,
  26. const Slice& value,
  27. uint64_t file_size) {
  28. ParsedInternalKey ikey;
  29. Status s = ParseInternalKey(key, &ikey, false /* log_err_key */); // TODO
  30. if (!s.ok()) {
  31. return s;
  32. }
  33. return collector_->AddUserKey(ikey.user_key, value, GetEntryType(ikey.type),
  34. ikey.sequence, file_size);
  35. }
  36. void UserKeyTablePropertiesCollector::BlockAdd(
  37. uint64_t block_uncomp_bytes, uint64_t block_compressed_bytes_fast,
  38. uint64_t block_compressed_bytes_slow) {
  39. return collector_->BlockAdd(block_uncomp_bytes, block_compressed_bytes_fast,
  40. block_compressed_bytes_slow);
  41. }
  42. Status UserKeyTablePropertiesCollector::Finish(
  43. UserCollectedProperties* properties) {
  44. return collector_->Finish(properties);
  45. }
  46. UserCollectedProperties UserKeyTablePropertiesCollector::GetReadableProperties()
  47. const {
  48. return collector_->GetReadableProperties();
  49. }
  50. uint64_t GetDeletedKeys(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(props, TablePropertiesNames::kMergeOperands,
  58. property_present);
  59. }
  60. } // namespace ROCKSDB_NAMESPACE