cuckoo_table_reader.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  7. // Use of this source code is governed by a BSD-style license that can be
  8. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  9. #pragma once
  10. #ifndef ROCKSDB_LITE
  11. #include <string>
  12. #include <memory>
  13. #include <utility>
  14. #include <vector>
  15. #include "db/dbformat.h"
  16. #include "file/random_access_file_reader.h"
  17. #include "options/cf_options.h"
  18. #include "rocksdb/env.h"
  19. #include "rocksdb/options.h"
  20. #include "table/table_reader.h"
  21. namespace ROCKSDB_NAMESPACE {
  22. class Arena;
  23. class TableReader;
  24. class CuckooTableReader: public TableReader {
  25. public:
  26. CuckooTableReader(const ImmutableCFOptions& ioptions,
  27. std::unique_ptr<RandomAccessFileReader>&& file,
  28. uint64_t file_size, const Comparator* user_comparator,
  29. uint64_t (*get_slice_hash)(const Slice&, uint32_t,
  30. uint64_t));
  31. ~CuckooTableReader() {}
  32. std::shared_ptr<const TableProperties> GetTableProperties() const override {
  33. return table_props_;
  34. }
  35. Status status() const { return status_; }
  36. Status Get(const ReadOptions& readOptions, const Slice& key,
  37. GetContext* get_context, const SliceTransform* prefix_extractor,
  38. bool skip_filters = false) override;
  39. // Returns a new iterator over table contents
  40. // compaction_readahead_size: its value will only be used if for_compaction =
  41. // true
  42. InternalIterator* NewIterator(const ReadOptions&,
  43. const SliceTransform* prefix_extractor,
  44. Arena* arena, bool skip_filters,
  45. TableReaderCaller caller,
  46. size_t compaction_readahead_size = 0) override;
  47. void Prepare(const Slice& target) override;
  48. // Report an approximation of how much memory has been used.
  49. size_t ApproximateMemoryUsage() const override;
  50. // Following methods are not implemented for Cuckoo Table Reader
  51. uint64_t ApproximateOffsetOf(const Slice& /*key*/,
  52. TableReaderCaller /*caller*/) override {
  53. return 0;
  54. }
  55. uint64_t ApproximateSize(const Slice& /*start*/, const Slice& /*end*/,
  56. TableReaderCaller /*caller*/) override {
  57. return 0;
  58. }
  59. void SetupForCompaction() override {}
  60. // End of methods not implemented.
  61. private:
  62. friend class CuckooTableIterator;
  63. void LoadAllKeys(std::vector<std::pair<Slice, uint32_t>>* key_to_bucket_id);
  64. std::unique_ptr<RandomAccessFileReader> file_;
  65. Slice file_data_;
  66. bool is_last_level_;
  67. bool identity_as_first_hash_;
  68. bool use_module_hash_;
  69. std::shared_ptr<const TableProperties> table_props_;
  70. Status status_;
  71. uint32_t num_hash_func_;
  72. std::string unused_key_;
  73. uint32_t key_length_;
  74. uint32_t user_key_length_;
  75. uint32_t value_length_;
  76. uint32_t bucket_length_;
  77. uint32_t cuckoo_block_size_;
  78. uint32_t cuckoo_block_bytes_minus_one_;
  79. uint64_t table_size_;
  80. const Comparator* ucomp_;
  81. uint64_t (*get_slice_hash_)(const Slice& s, uint32_t index,
  82. uint64_t max_num_buckets);
  83. };
  84. } // namespace ROCKSDB_NAMESPACE
  85. #endif // ROCKSDB_LITE