adaptive_table_factory.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  2. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style license that can be
  4. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  5. #pragma once
  6. #include <string>
  7. #include "rocksdb/options.h"
  8. #include "rocksdb/table.h"
  9. namespace ROCKSDB_NAMESPACE {
  10. struct EnvOptions;
  11. class Status;
  12. class RandomAccessFile;
  13. class WritableFile;
  14. class Table;
  15. class TableBuilder;
  16. class AdaptiveTableFactory : public TableFactory {
  17. public:
  18. ~AdaptiveTableFactory() {}
  19. explicit AdaptiveTableFactory(
  20. std::shared_ptr<TableFactory> table_factory_to_write,
  21. std::shared_ptr<TableFactory> block_based_table_factory,
  22. std::shared_ptr<TableFactory> plain_table_factory,
  23. std::shared_ptr<TableFactory> cuckoo_table_factory);
  24. const char* Name() const override { return "AdaptiveTableFactory"; }
  25. using TableFactory::NewTableReader;
  26. Status NewTableReader(
  27. const ReadOptions& ro, const TableReaderOptions& table_reader_options,
  28. std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
  29. std::unique_ptr<TableReader>* table,
  30. bool prefetch_index_and_filter_in_cache = true) const override;
  31. TableBuilder* NewTableBuilder(
  32. const TableBuilderOptions& table_builder_options,
  33. WritableFileWriter* file) const override;
  34. std::string GetPrintableOptions() const override;
  35. std::unique_ptr<TableFactory> Clone() const override {
  36. return std::make_unique<AdaptiveTableFactory>(*this);
  37. }
  38. private:
  39. std::shared_ptr<TableFactory> table_factory_to_write_;
  40. std::shared_ptr<TableFactory> block_based_table_factory_;
  41. std::shared_ptr<TableFactory> plain_table_factory_;
  42. std::shared_ptr<TableFactory> cuckoo_table_factory_;
  43. };
  44. } // namespace ROCKSDB_NAMESPACE