Coverage Report

Created: 2025-07-23 07:17

/src/rocksdb/table/cuckoo/cuckoo_table_factory.cc
Line
Count
Source (jump to first uncovered line)
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
#include "table/cuckoo/cuckoo_table_factory.h"
7
8
#include "db/dbformat.h"
9
#include "options/configurable_helper.h"
10
#include "rocksdb/utilities/options_type.h"
11
#include "table/cuckoo/cuckoo_table_builder.h"
12
#include "table/cuckoo/cuckoo_table_reader.h"
13
14
namespace ROCKSDB_NAMESPACE {
15
16
Status CuckooTableFactory::NewTableReader(
17
    const ReadOptions& /*ro*/, const TableReaderOptions& table_reader_options,
18
    std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
19
    std::unique_ptr<TableReader>* table,
20
0
    bool /*prefetch_index_and_filter_in_cache*/) const {
21
0
  std::unique_ptr<CuckooTableReader> new_reader(new CuckooTableReader(
22
0
      table_reader_options.ioptions, std::move(file), file_size,
23
0
      table_reader_options.internal_comparator.user_comparator(), nullptr));
24
0
  Status s = new_reader->status();
25
0
  if (s.ok()) {
26
0
    *table = std::move(new_reader);
27
0
  }
28
0
  return s;
29
0
}
30
31
TableBuilder* CuckooTableFactory::NewTableBuilder(
32
    const TableBuilderOptions& table_builder_options,
33
0
    WritableFileWriter* file) const {
34
  // TODO: change builder to take the option struct
35
0
  return new CuckooTableBuilder(
36
0
      file, table_options_.hash_table_ratio, 64,
37
0
      table_options_.max_search_depth,
38
0
      table_builder_options.internal_comparator.user_comparator(),
39
0
      table_options_.cuckoo_block_size, table_options_.use_module_hash,
40
0
      table_options_.identity_as_first_hash, nullptr /* get_slice_hash */,
41
0
      table_builder_options.column_family_id,
42
0
      table_builder_options.column_family_name, table_builder_options.db_id,
43
0
      table_builder_options.db_session_id, table_builder_options.cur_file_num);
44
0
}
45
46
0
std::string CuckooTableFactory::GetPrintableOptions() const {
47
0
  std::string ret;
48
0
  ret.reserve(2000);
49
0
  const int kBufferSize = 200;
50
0
  char buffer[kBufferSize];
51
52
0
  snprintf(buffer, kBufferSize, "  hash_table_ratio: %lf\n",
53
0
           table_options_.hash_table_ratio);
54
0
  ret.append(buffer);
55
0
  snprintf(buffer, kBufferSize, "  max_search_depth: %u\n",
56
0
           table_options_.max_search_depth);
57
0
  ret.append(buffer);
58
0
  snprintf(buffer, kBufferSize, "  cuckoo_block_size: %u\n",
59
0
           table_options_.cuckoo_block_size);
60
0
  ret.append(buffer);
61
0
  snprintf(buffer, kBufferSize, "  identity_as_first_hash: %d\n",
62
0
           table_options_.identity_as_first_hash);
63
0
  ret.append(buffer);
64
0
  return ret;
65
0
}
66
67
static std::unordered_map<std::string, OptionTypeInfo> cuckoo_table_type_info =
68
    {
69
        {"hash_table_ratio",
70
         {offsetof(struct CuckooTableOptions, hash_table_ratio),
71
          OptionType::kDouble, OptionVerificationType::kNormal,
72
          OptionTypeFlags::kNone}},
73
        {"max_search_depth",
74
         {offsetof(struct CuckooTableOptions, max_search_depth),
75
          OptionType::kUInt32T, OptionVerificationType::kNormal,
76
          OptionTypeFlags::kNone}},
77
        {"cuckoo_block_size",
78
         {offsetof(struct CuckooTableOptions, cuckoo_block_size),
79
          OptionType::kUInt32T, OptionVerificationType::kNormal,
80
          OptionTypeFlags::kNone}},
81
        {"identity_as_first_hash",
82
         {offsetof(struct CuckooTableOptions, identity_as_first_hash),
83
          OptionType::kBoolean, OptionVerificationType::kNormal,
84
          OptionTypeFlags::kNone}},
85
        {"use_module_hash",
86
         {offsetof(struct CuckooTableOptions, use_module_hash),
87
          OptionType::kBoolean, OptionVerificationType::kNormal,
88
          OptionTypeFlags::kNone}},
89
};
90
91
CuckooTableFactory::CuckooTableFactory(const CuckooTableOptions& table_options)
92
0
    : table_options_(table_options) {
93
0
  RegisterOptions(&table_options_, &cuckoo_table_type_info);
94
0
}
95
96
0
TableFactory* NewCuckooTableFactory(const CuckooTableOptions& table_options) {
97
0
  return new CuckooTableFactory(table_options);
98
0
}
99
100
}  // namespace ROCKSDB_NAMESPACE