table_factory.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include <mutex>
  6. #include "rocksdb/convenience.h"
  7. #include "rocksdb/table.h"
  8. #include "rocksdb/utilities/customizable_util.h"
  9. #include "rocksdb/utilities/object_registry.h"
  10. #include "table/block_based/block_based_table_factory.h"
  11. #include "table/cuckoo/cuckoo_table_factory.h"
  12. #include "table/plain/plain_table_factory.h"
  13. namespace ROCKSDB_NAMESPACE {
  14. static void RegisterTableFactories(const std::string& /*arg*/) {
  15. static std::once_flag loaded;
  16. std::call_once(loaded, []() {
  17. auto library = ObjectLibrary::Default();
  18. library->AddFactory<TableFactory>(
  19. TableFactory::kBlockBasedTableName(),
  20. [](const std::string& /*uri*/, std::unique_ptr<TableFactory>* guard,
  21. std::string* /* errmsg */) {
  22. guard->reset(new BlockBasedTableFactory());
  23. return guard->get();
  24. });
  25. library->AddFactory<TableFactory>(
  26. TableFactory::kPlainTableName(),
  27. [](const std::string& /*uri*/, std::unique_ptr<TableFactory>* guard,
  28. std::string* /* errmsg */) {
  29. guard->reset(new PlainTableFactory());
  30. return guard->get();
  31. });
  32. library->AddFactory<TableFactory>(
  33. TableFactory::kCuckooTableName(),
  34. [](const std::string& /*uri*/, std::unique_ptr<TableFactory>* guard,
  35. std::string* /* errmsg */) {
  36. guard->reset(new CuckooTableFactory());
  37. return guard->get();
  38. });
  39. });
  40. }
  41. Status TableFactory::CreateFromString(const ConfigOptions& config_options,
  42. const std::string& value,
  43. std::shared_ptr<TableFactory>* factory) {
  44. RegisterTableFactories("");
  45. return LoadSharedObject<TableFactory>(config_options, value, factory);
  46. }
  47. } // namespace ROCKSDB_NAMESPACE