2020-09-15 01:59:00 +02: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 18:07:10 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
2020-09-15 01:59:00 +02:00
|
|
|
#include "rocksdb/convenience.h"
|
|
|
|
#include "rocksdb/table.h"
|
2021-06-29 18:07:10 +02:00
|
|
|
#include "rocksdb/utilities/customizable_util.h"
|
|
|
|
#include "rocksdb/utilities/object_registry.h"
|
2020-09-15 01:59:00 +02: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 18:07:10 +02:00
|
|
|
static void RegisterTableFactories(const std::string& /*arg*/) {
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
static std::once_flag loaded;
|
|
|
|
std::call_once(loaded, []() {
|
|
|
|
auto library = ObjectLibrary::Default();
|
|
|
|
library->Register<TableFactory>(
|
|
|
|
TableFactory::kBlockBasedTableName(),
|
|
|
|
[](const std::string& /*uri*/, std::unique_ptr<TableFactory>* guard,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
guard->reset(new BlockBasedTableFactory());
|
|
|
|
return guard->get();
|
|
|
|
});
|
|
|
|
library->Register<TableFactory>(
|
|
|
|
TableFactory::kPlainTableName(),
|
|
|
|
[](const std::string& /*uri*/, std::unique_ptr<TableFactory>* guard,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
guard->reset(new PlainTableFactory());
|
|
|
|
return guard->get();
|
|
|
|
});
|
|
|
|
library->Register<TableFactory>(
|
|
|
|
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-12 00:09:14 +01:00
|
|
|
static bool LoadFactory(const std::string& name,
|
|
|
|
std::shared_ptr<TableFactory>* factory) {
|
2020-09-15 01:59:00 +02:00
|
|
|
if (name == TableFactory::kBlockBasedTableName()) {
|
|
|
|
factory->reset(new BlockBasedTableFactory());
|
2021-06-29 18:07:10 +02:00
|
|
|
return true;
|
2020-09-15 01:59:00 +02:00
|
|
|
} else {
|
2021-06-29 18:07:10 +02:00
|
|
|
return false;
|
2020-09-15 01:59:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 00:09:14 +01:00
|
|
|
Status TableFactory::CreateFromString(const ConfigOptions& config_options,
|
|
|
|
const std::string& value,
|
|
|
|
std::shared_ptr<TableFactory>* factory) {
|
2021-06-29 18:07:10 +02:00
|
|
|
RegisterTableFactories("");
|
2020-11-12 00:09:14 +01:00
|
|
|
return LoadSharedObject<TableFactory>(config_options, value, LoadFactory,
|
|
|
|
factory);
|
|
|
|
}
|
2020-09-15 01:59:00 +02:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|