cuckoo_table_factory.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef ROCKSDB_LITE
  6. #include "table/cuckoo/cuckoo_table_factory.h"
  7. #include "db/dbformat.h"
  8. #include "table/cuckoo/cuckoo_table_builder.h"
  9. #include "table/cuckoo/cuckoo_table_reader.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. Status CuckooTableFactory::NewTableReader(
  12. const TableReaderOptions& table_reader_options,
  13. std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
  14. std::unique_ptr<TableReader>* table,
  15. bool /*prefetch_index_and_filter_in_cache*/) const {
  16. std::unique_ptr<CuckooTableReader> new_reader(new CuckooTableReader(
  17. table_reader_options.ioptions, std::move(file), file_size,
  18. table_reader_options.internal_comparator.user_comparator(), nullptr));
  19. Status s = new_reader->status();
  20. if (s.ok()) {
  21. *table = std::move(new_reader);
  22. }
  23. return s;
  24. }
  25. TableBuilder* CuckooTableFactory::NewTableBuilder(
  26. const TableBuilderOptions& table_builder_options, uint32_t column_family_id,
  27. WritableFileWriter* file) const {
  28. // Ignore the skipFIlters flag. Does not apply to this file format
  29. //
  30. // TODO: change builder to take the option struct
  31. return new CuckooTableBuilder(
  32. file, table_options_.hash_table_ratio, 64,
  33. table_options_.max_search_depth,
  34. table_builder_options.internal_comparator.user_comparator(),
  35. table_options_.cuckoo_block_size, table_options_.use_module_hash,
  36. table_options_.identity_as_first_hash, nullptr /* get_slice_hash */,
  37. column_family_id, table_builder_options.column_family_name);
  38. }
  39. std::string CuckooTableFactory::GetPrintableTableOptions() const {
  40. std::string ret;
  41. ret.reserve(2000);
  42. const int kBufferSize = 200;
  43. char buffer[kBufferSize];
  44. snprintf(buffer, kBufferSize, " hash_table_ratio: %lf\n",
  45. table_options_.hash_table_ratio);
  46. ret.append(buffer);
  47. snprintf(buffer, kBufferSize, " max_search_depth: %u\n",
  48. table_options_.max_search_depth);
  49. ret.append(buffer);
  50. snprintf(buffer, kBufferSize, " cuckoo_block_size: %u\n",
  51. table_options_.cuckoo_block_size);
  52. ret.append(buffer);
  53. snprintf(buffer, kBufferSize, " identity_as_first_hash: %d\n",
  54. table_options_.identity_as_first_hash);
  55. ret.append(buffer);
  56. return ret;
  57. }
  58. TableFactory* NewCuckooTableFactory(const CuckooTableOptions& table_options) {
  59. return new CuckooTableFactory(table_options);
  60. }
  61. } // namespace ROCKSDB_NAMESPACE
  62. #endif // ROCKSDB_LITE