2020-09-14 23:59:00 +00:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2021-06-29 16:07:10 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
2020-09-14 23:59:00 +00:00
|
|
|
#include "rocksdb/convenience.h"
|
|
|
|
#include "rocksdb/table.h"
|
2021-06-29 16:07:10 +00:00
|
|
|
#include "rocksdb/utilities/customizable_util.h"
|
|
|
|
#include "rocksdb/utilities/object_registry.h"
|
2020-09-14 23:59:00 +00:00
|
|
|
#include "table/block_based/block_based_table_factory.h"
|
|
|
|
#include "table/cuckoo/cuckoo_table_factory.h"
|
|
|
|
#include "table/plain/plain_table_factory.h"
|
|
|
|
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
|
2021-06-29 16:07:10 +00:00
|
|
|
static void RegisterTableFactories(const std::string& /*arg*/) {
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
static std::once_flag loaded;
|
|
|
|
std::call_once(loaded, []() {
|
|
|
|
auto library = ObjectLibrary::Default();
|
2022-01-11 14:32:42 +00:00
|
|
|
library->AddFactory<TableFactory>(
|
2021-06-29 16:07:10 +00:00
|
|
|
TableFactory::kBlockBasedTableName(),
|
|
|
|
[](const std::string& /*uri*/, std::unique_ptr<TableFactory>* guard,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
guard->reset(new BlockBasedTableFactory());
|
|
|
|
return guard->get();
|
|
|
|
});
|
2022-01-11 14:32:42 +00:00
|
|
|
library->AddFactory<TableFactory>(
|
2021-06-29 16:07:10 +00:00
|
|
|
TableFactory::kPlainTableName(),
|
|
|
|
[](const std::string& /*uri*/, std::unique_ptr<TableFactory>* guard,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
guard->reset(new PlainTableFactory());
|
|
|
|
return guard->get();
|
|
|
|
});
|
2022-01-11 14:32:42 +00:00
|
|
|
library->AddFactory<TableFactory>(
|
2021-06-29 16:07:10 +00:00
|
|
|
TableFactory::kCuckooTableName(),
|
|
|
|
[](const std::string& /*uri*/, std::unique_ptr<TableFactory>* guard,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
guard->reset(new CuckooTableFactory());
|
|
|
|
return guard->get();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:09:14 +00:00
|
|
|
static bool LoadFactory(const std::string& name,
|
|
|
|
std::shared_ptr<TableFactory>* factory) {
|
2020-09-14 23:59:00 +00:00
|
|
|
if (name == TableFactory::kBlockBasedTableName()) {
|
|
|
|
factory->reset(new BlockBasedTableFactory());
|
2021-06-29 16:07:10 +00:00
|
|
|
return true;
|
2020-09-14 23:59:00 +00:00
|
|
|
} else {
|
2021-06-29 16:07:10 +00:00
|
|
|
return false;
|
2020-09-14 23:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:09:14 +00:00
|
|
|
Status TableFactory::CreateFromString(const ConfigOptions& config_options,
|
|
|
|
const std::string& value,
|
|
|
|
std::shared_ptr<TableFactory>* factory) {
|
2021-06-29 16:07:10 +00:00
|
|
|
RegisterTableFactories("");
|
2020-11-11 23:09:14 +00:00
|
|
|
return LoadSharedObject<TableFactory>(config_options, value, LoadFactory,
|
|
|
|
factory);
|
|
|
|
}
|
2020-09-14 23:59:00 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|