diff --git a/db/builder.cc b/db/builder.cc index 96fb29eef..08e76b539 100644 --- a/db/builder.cc +++ b/db/builder.cc @@ -18,8 +18,8 @@ #include "rocksdb/env.h" #include "rocksdb/iterator.h" #include "rocksdb/options.h" +#include "rocksdb/table.h" #include "table/block_based_table_builder.h" -#include "table/table_factory.h" #include "util/stop_watch.h" namespace rocksdb { diff --git a/db/table_cache.h b/db/table_cache.h index 316a31888..5ec0838cb 100644 --- a/db/table_cache.h +++ b/db/table_cache.h @@ -17,7 +17,7 @@ #include "port/port.h" #include "rocksdb/cache.h" #include "rocksdb/env.h" -#include "table/table_factory.h" +#include "rocksdb/table.h" #include "table/table_reader.h" namespace rocksdb { diff --git a/include/rocksdb/table.h b/include/rocksdb/table.h index 1bdea049f..d4965ca45 100644 --- a/include/rocksdb/table.h +++ b/include/rocksdb/table.h @@ -29,6 +29,14 @@ namespace rocksdb { // -- Block-based Table class FlushBlockPolicyFactory; +class RandomAccessFile; +class TableBuilder; +class TableReader; +class WritableFile; +struct EnvOptions; +struct Options; + +using std::unique_ptr; // For advanced user only struct BlockBasedTableOptions { @@ -67,4 +75,62 @@ extern TableFactory* NewPlainTableFactory( uint32_t user_key_len = kPlainTableVariableLength, int bloom_bits_per_key = 10, double hash_table_ratio = 0.75); +// A base class for table factories. +class TableFactory { + public: + virtual ~TableFactory() {} + + // The type of the table. + // + // The client of this package should switch to a new name whenever + // the table format implementation changes. + // + // Names starting with "rocksdb." are reserved and should not be used + // by any clients of this package. + virtual const char* Name() const = 0; + + // Returns a Table object table that can fetch data from file specified + // in parameter file. It's the caller's responsibility to make sure + // file is in the correct format. + // + // NewTableReader() is called in two places: + // (1) TableCache::FindTable() calls the function when table cache miss + // and cache the table object returned. + // (1) SstFileReader (for SST Dump) opens the table and dump the table + // contents using the interator of the table. + // options and soptions are options. options is the general options. + // Multiple configured can be accessed from there, including and not + // limited to block cache and key comparators. + // file is a file handler to handle the file for the table + // file_size is the physical file size of the file + // table_reader is the output table reader + virtual Status NewTableReader( + const Options& options, const EnvOptions& soptions, + const InternalKeyComparator& internal_comparator, + unique_ptr&& file, uint64_t file_size, + unique_ptr* table_reader) const = 0; + + // Return a table builder to write to a file for this table type. + // + // It is called in several places: + // (1) When flushing memtable to a level-0 output file, it creates a table + // builder (In DBImpl::WriteLevel0Table(), by calling BuildTable()) + // (2) During compaction, it gets the builder for writing compaction output + // files in DBImpl::OpenCompactionOutputFile(). + // (3) When recovering from transaction logs, it creates a table builder to + // write to a level-0 output file (In DBImpl::WriteLevel0TableForRecovery, + // by calling BuildTable()) + // (4) When running Repairer, it creates a table builder to convert logs to + // SST files (In Repairer::ConvertLogToTable() by calling BuildTable()) + // + // options is the general options. Multiple configured can be acceseed from + // there, including and not limited to compression options. + // file is a handle of a writable file. It is the caller's responsibility to + // keep the file open and close the file after closing the table builder. + // compression_type is the compression type to use in this table. + virtual TableBuilder* NewTableBuilder( + const Options& options, const InternalKeyComparator& internal_comparator, + WritableFile* file, CompressionType compression_type) const = 0; +}; + } // namespace rocksdb diff --git a/table/block_based_table_factory.h b/table/block_based_table_factory.h index 2513b9f83..556997065 100644 --- a/table/block_based_table_factory.h +++ b/table/block_based_table_factory.h @@ -14,7 +14,6 @@ #include "rocksdb/flush_block_policy.h" #include "rocksdb/options.h" #include "rocksdb/table.h" -#include "table/table_factory.h" namespace rocksdb { diff --git a/table/plain_table_factory.h b/table/plain_table_factory.h index 88745ca1b..382efe3c1 100644 --- a/table/plain_table_factory.h +++ b/table/plain_table_factory.h @@ -8,7 +8,6 @@ #include "rocksdb/options.h" #include "rocksdb/table.h" -#include "table/table_factory.h" namespace rocksdb { diff --git a/table/table_factory.h b/table/table_factory.h deleted file mode 100644 index f606a916a..000000000 --- a/table/table_factory.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2013, Facebook, Inc. All rights reserved. -// This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. -// -// 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. -#pragma once - -#include -#include "rocksdb/status.h" - -namespace rocksdb { - -using std::unique_ptr; - -class RandomAccessFile; -class TableBuilder; -class TableReader; -class WritableFile; -struct EnvOptions; -struct Options; - -// A base class for table factories -class TableFactory { - public: - virtual ~TableFactory() {} - - // The type of the table. - // - // The client of this package should switch to a new name whenever - // the table format implementation changes. - // - // Names starting with "rocksdb." are reserved and should not be used - // by any clients of this package. - virtual const char* Name() const = 0; - - // Returns a Table object table that can fetch data from file specified - // in parameter file. It's the caller's responsibility to make sure - // file is in the correct format. - // - // NewTableReader() is called in two places: - // (1) TableCache::FindTable() calls the function when table cache miss - // and cache the table object returned. - // (1) SstFileReader (for SST Dump) opens the table and dump the table - // contents using the interator of the table. - // options and soptions are options. options is the general options. - // Multiple configured can be accessed from there, including and not - // limited to block cache and key comparators. - // file is a file handler to handle the file for the table - // file_size is the physical file size of the file - // table_reader is the output table reader - virtual Status NewTableReader( - const Options& options, const EnvOptions& soptions, - const InternalKeyComparator& internal_comparator, - unique_ptr&& file, uint64_t file_size, - unique_ptr* table_reader) const = 0; - - // Return a table builder to write to a file for this table type. - // - // It is called in several places: - // (1) When flushing memtable to a level-0 output file, it creates a table - // builder (In DBImpl::WriteLevel0Table(), by calling BuildTable()) - // (2) During compaction, it gets the builder for writing compaction output - // files in DBImpl::OpenCompactionOutputFile(). - // (3) When recovering from transaction logs, it creates a table builder to - // write to a level-0 output file (In DBImpl::WriteLevel0TableForRecovery, - // by calling BuildTable()) - // (4) When running Repairer, it creates a table builder to convert logs to - // SST files (In Repairer::ConvertLogToTable() by calling BuildTable()) - // - // options is the general options. Multiple configured can be acceseed from - // there, including and not limited to compression options. - // file is a handle of a writable file. It is the caller's responsibility to - // keep the file open and close the file after closing the table builder. - // compression_type is the compression type to use in this table. - virtual TableBuilder* NewTableBuilder( - const Options& options, const InternalKeyComparator& internal_comparator, - WritableFile* file, CompressionType compression_type) const = 0; -}; - -} // namespace rocksdb diff --git a/table/table_reader.h b/table/table_reader.h index 681ce7233..9acbb33d0 100644 --- a/table/table_reader.h +++ b/table/table_reader.h @@ -12,7 +12,7 @@ namespace rocksdb { class Iterator; -class ParsedInternalKey; +struct ParsedInternalKey; class Slice; struct ReadOptions; struct TableProperties;