fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.9 KiB
125 lines
4.9 KiB
6 years ago
|
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||
11 years ago
|
// 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.
|
||
|
|
||
|
#ifndef ROCKSDB_LITE
|
||
6 years ago
|
#include "table/adaptive/adaptive_table_factory.h"
|
||
11 years ago
|
|
||
9 years ago
|
#include "table/table_builder.h"
|
||
11 years ago
|
#include "table/format.h"
|
||
10 years ago
|
#include "port/port.h"
|
||
11 years ago
|
|
||
|
namespace rocksdb {
|
||
|
|
||
|
AdaptiveTableFactory::AdaptiveTableFactory(
|
||
11 years ago
|
std::shared_ptr<TableFactory> table_factory_to_write,
|
||
11 years ago
|
std::shared_ptr<TableFactory> block_based_table_factory,
|
||
11 years ago
|
std::shared_ptr<TableFactory> plain_table_factory,
|
||
|
std::shared_ptr<TableFactory> cuckoo_table_factory)
|
||
11 years ago
|
: table_factory_to_write_(table_factory_to_write),
|
||
|
block_based_table_factory_(block_based_table_factory),
|
||
11 years ago
|
plain_table_factory_(plain_table_factory),
|
||
|
cuckoo_table_factory_(cuckoo_table_factory) {
|
||
11 years ago
|
if (!plain_table_factory_) {
|
||
|
plain_table_factory_.reset(NewPlainTableFactory());
|
||
|
}
|
||
|
if (!block_based_table_factory_) {
|
||
|
block_based_table_factory_.reset(NewBlockBasedTableFactory());
|
||
|
}
|
||
11 years ago
|
if (!cuckoo_table_factory_) {
|
||
|
cuckoo_table_factory_.reset(NewCuckooTableFactory());
|
||
|
}
|
||
8 years ago
|
if (!table_factory_to_write_) {
|
||
|
table_factory_to_write_ = block_based_table_factory_;
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
extern const uint64_t kPlainTableMagicNumber;
|
||
|
extern const uint64_t kLegacyPlainTableMagicNumber;
|
||
|
extern const uint64_t kBlockBasedTableMagicNumber;
|
||
|
extern const uint64_t kLegacyBlockBasedTableMagicNumber;
|
||
11 years ago
|
extern const uint64_t kCuckooTableMagicNumber;
|
||
11 years ago
|
|
||
|
Status AdaptiveTableFactory::NewTableReader(
|
||
9 years ago
|
const TableReaderOptions& table_reader_options,
|
||
6 years ago
|
std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
|
||
|
std::unique_ptr<TableReader>* table,
|
||
7 years ago
|
bool /*prefetch_index_and_filter_in_cache*/) const {
|
||
11 years ago
|
Footer footer;
|
||
7 years ago
|
auto s = ReadFooterFromFile(file.get(), nullptr /* prefetch_buffer */,
|
||
|
file_size, &footer);
|
||
11 years ago
|
if (!s.ok()) {
|
||
|
return s;
|
||
|
}
|
||
|
if (footer.table_magic_number() == kPlainTableMagicNumber ||
|
||
|
footer.table_magic_number() == kLegacyPlainTableMagicNumber) {
|
||
|
return plain_table_factory_->NewTableReader(
|
||
9 years ago
|
table_reader_options, std::move(file), file_size, table);
|
||
11 years ago
|
} else if (footer.table_magic_number() == kBlockBasedTableMagicNumber ||
|
||
|
footer.table_magic_number() == kLegacyBlockBasedTableMagicNumber) {
|
||
|
return block_based_table_factory_->NewTableReader(
|
||
9 years ago
|
table_reader_options, std::move(file), file_size, table);
|
||
11 years ago
|
} else if (footer.table_magic_number() == kCuckooTableMagicNumber) {
|
||
|
return cuckoo_table_factory_->NewTableReader(
|
||
9 years ago
|
table_reader_options, std::move(file), file_size, table);
|
||
11 years ago
|
} else {
|
||
|
return Status::NotSupported("Unidentified table format");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TableBuilder* AdaptiveTableFactory::NewTableBuilder(
|
||
9 years ago
|
const TableBuilderOptions& table_builder_options, uint32_t column_family_id,
|
||
10 years ago
|
WritableFileWriter* file) const {
|
||
9 years ago
|
return table_factory_to_write_->NewTableBuilder(table_builder_options,
|
||
|
column_family_id, file);
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
std::string AdaptiveTableFactory::GetPrintableTableOptions() const {
|
||
|
std::string ret;
|
||
|
ret.reserve(20000);
|
||
|
const int kBufferSize = 200;
|
||
|
char buffer[kBufferSize];
|
||
|
|
||
9 years ago
|
if (table_factory_to_write_) {
|
||
10 years ago
|
snprintf(buffer, kBufferSize, " write factory (%s) options:\n%s\n",
|
||
9 years ago
|
(table_factory_to_write_->Name() ? table_factory_to_write_->Name()
|
||
|
: ""),
|
||
10 years ago
|
table_factory_to_write_->GetPrintableTableOptions().c_str());
|
||
|
ret.append(buffer);
|
||
|
}
|
||
9 years ago
|
if (plain_table_factory_) {
|
||
10 years ago
|
snprintf(buffer, kBufferSize, " %s options:\n%s\n",
|
||
9 years ago
|
plain_table_factory_->Name() ? plain_table_factory_->Name() : "",
|
||
10 years ago
|
plain_table_factory_->GetPrintableTableOptions().c_str());
|
||
|
ret.append(buffer);
|
||
|
}
|
||
9 years ago
|
if (block_based_table_factory_) {
|
||
9 years ago
|
snprintf(
|
||
|
buffer, kBufferSize, " %s options:\n%s\n",
|
||
|
(block_based_table_factory_->Name() ? block_based_table_factory_->Name()
|
||
|
: ""),
|
||
|
block_based_table_factory_->GetPrintableTableOptions().c_str());
|
||
10 years ago
|
ret.append(buffer);
|
||
|
}
|
||
9 years ago
|
if (cuckoo_table_factory_) {
|
||
10 years ago
|
snprintf(buffer, kBufferSize, " %s options:\n%s\n",
|
||
9 years ago
|
cuckoo_table_factory_->Name() ? cuckoo_table_factory_->Name() : "",
|
||
10 years ago
|
cuckoo_table_factory_->GetPrintableTableOptions().c_str());
|
||
|
ret.append(buffer);
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
11 years ago
|
extern TableFactory* NewAdaptiveTableFactory(
|
||
11 years ago
|
std::shared_ptr<TableFactory> table_factory_to_write,
|
||
11 years ago
|
std::shared_ptr<TableFactory> block_based_table_factory,
|
||
11 years ago
|
std::shared_ptr<TableFactory> plain_table_factory,
|
||
|
std::shared_ptr<TableFactory> cuckoo_table_factory) {
|
||
|
return new AdaptiveTableFactory(table_factory_to_write,
|
||
|
block_based_table_factory, plain_table_factory, cuckoo_table_factory);
|
||
11 years ago
|
}
|
||
|
|
||
|
} // namespace rocksdb
|
||
|
#endif // ROCKSDB_LITE
|