Skip to content

Commit

Permalink
First phase API clean up
Browse files Browse the repository at this point in the history
Summary:
Addressed all the issues in https://reviews.facebook.net/D15447.
Now most table-related modules are hidden from user land.

Test Plan: make check

Reviewers: sdong, haobo, dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D15525
  • Loading branch information
liukai committed Feb 3, 2014
1 parent 4e0298f commit 4f6cb17
Show file tree
Hide file tree
Showing 32 changed files with 400 additions and 351 deletions.
11 changes: 5 additions & 6 deletions db/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@

#include "db/builder.h"

#include "db/filename.h"
#include "db/dbformat.h"
#include "db/filename.h"
#include "db/merge_helper.h"
#include "db/table_cache.h"
#include "db/version_edit.h"
#include "rocksdb/db.h"
#include "rocksdb/table.h"
#include "rocksdb/env.h"
#include "rocksdb/iterator.h"
#include "rocksdb/options.h"
#include "table/block_based_table_builder.h"
#include "table/table_factory.h"
#include "util/stop_watch.h"

namespace rocksdb {

class TableFactory;

TableBuilder* GetTableBuilder(const Options& options, WritableFile* file,
TableBuilder* NewTableBuilder(const Options& options, WritableFile* file,
CompressionType compression_type) {
return options.table_factory->GetTableBuilder(options, file,
return options.table_factory->NewTableBuilder(options, file,
compression_type);
}

Expand Down Expand Up @@ -64,8 +64,7 @@ Status BuildTable(const std::string& dbname,
return s;
}

TableBuilder* builder = GetTableBuilder(options, file.get(),
compression);
TableBuilder* builder = NewTableBuilder(options, file.get(), compression);

// the first key is the smallest key
Slice key = iter->key();
Expand Down
3 changes: 1 addition & 2 deletions db/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class VersionEdit;
class TableBuilder;
class WritableFile;


extern TableBuilder* GetTableBuilder(const Options& options, WritableFile* file,
extern TableBuilder* NewTableBuilder(const Options& options, WritableFile* file,
CompressionType compression_type);

// Build a Table file from the contents of *iter. The generated file
Expand Down
6 changes: 3 additions & 3 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@
#include "table/block.h"
#include "table/block_based_table_factory.h"
#include "table/merger.h"
#include "table/table_builder.h"
#include "table/two_level_iterator.h"
#include "util/autovector.h"
#include "util/auto_roll_logger.h"
#include "util/autovector.h"
#include "util/build_version.h"
#include "util/coding.h"
#include "util/hash_skiplist_rep.h"
#include "util/logging.h"
#include "util/mutexlock.h"
#include "util/perf_context_imp.h"
#include "util/stop_watch.h"
#include "util/autovector.h"

namespace rocksdb {

Expand Down Expand Up @@ -2138,7 +2138,7 @@ Status DBImpl::OpenCompactionOutputFile(CompactionState* compact) {
compact->compaction->enable_compression());

compact->builder.reset(
GetTableBuilder(options_, compact->outfile.get(), compression_type));
NewTableBuilder(options_, compact->outfile.get(), compression_type));
}
LogFlush(options_.info_log);
return s;
Expand Down
2 changes: 1 addition & 1 deletion db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "rocksdb/env.h"
#include "rocksdb/filter_policy.h"
#include "rocksdb/perf_context.h"
#include "rocksdb/plain_table_factory.h"
#include "table/plain_table_factory.h"
#include "rocksdb/slice.h"
#include "rocksdb/slice_transform.h"
#include "rocksdb/table.h"
Expand Down
2 changes: 1 addition & 1 deletion db/plain_table_db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "rocksdb/db.h"
#include "rocksdb/env.h"
#include "rocksdb/filter_policy.h"
#include "rocksdb/plain_table_factory.h"
#include "rocksdb/slice_transform.h"
#include "rocksdb/table.h"
#include "table/plain_table_factory.h"
#include "util/hash.h"
#include "util/logging.h"
#include "util/mutexlock.h"
Expand Down
22 changes: 8 additions & 14 deletions db/simple_table_db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "rocksdb/compaction_filter.h"
#include "rocksdb/env.h"
#include "rocksdb/table.h"
#include "rocksdb/table_properties.h"
#include "table/table_builder.h"
#include "util/hash.h"
#include "util/logging.h"
#include "util/mutexlock.h"
Expand Down Expand Up @@ -92,8 +94,6 @@ class SimpleTableReader: public TableReader {

uint64_t ApproximateOffsetOf(const Slice& key) override;

bool TEST_KeyInCache(const ReadOptions& options, const Slice& key) override;

void SetupForCompaction() override;

TableProperties& GetTableProperties() override;
Expand Down Expand Up @@ -296,11 +296,6 @@ Status SimpleTableReader::Get(
return s;
}

bool SimpleTableReader::TEST_KeyInCache(const ReadOptions& options,
const Slice& key) {
return false;
}

uint64_t SimpleTableReader::ApproximateOffsetOf(const Slice& key) {
return 0;
}
Expand Down Expand Up @@ -541,25 +536,24 @@ class SimpleTableFactory: public TableFactory {
const char* Name() const override {
return "SimpleTable";
}
Status GetTableReader(const Options& options, const EnvOptions& soptions,
unique_ptr<RandomAccessFile> && file,
uint64_t file_size,
Status NewTableReader(const Options& options, const EnvOptions& soptions,
unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
unique_ptr<TableReader>* table_reader) const;

TableBuilder* GetTableBuilder(const Options& options, WritableFile* file,
TableBuilder* NewTableBuilder(const Options& options, WritableFile* file,
CompressionType compression_type) const;
};

Status SimpleTableFactory::GetTableReader(
Status SimpleTableFactory::NewTableReader(
const Options& options, const EnvOptions& soptions,
unique_ptr<RandomAccessFile> && file, uint64_t file_size,
unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
unique_ptr<TableReader>* table_reader) const {

return SimpleTableReader::Open(options, soptions, std::move(file), file_size,
table_reader);
}

TableBuilder* SimpleTableFactory::GetTableBuilder(
TableBuilder* SimpleTableFactory::NewTableBuilder(
const Options& options, WritableFile* file,
CompressionType compression_type) const {
return new SimpleTableBuilder(options, file, compression_type);
Expand Down
7 changes: 3 additions & 4 deletions db/table_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "db/version_edit.h"

#include "rocksdb/statistics.h"
#include "rocksdb/table.h"
#include "table/table_reader.h"
#include "util/coding.h"
#include "util/stop_watch.h"

Expand Down Expand Up @@ -83,9 +83,8 @@ Status TableCache::FindTable(const EnvOptions& toptions,
file->Hint(RandomAccessFile::RANDOM);
}
StopWatch sw(env_, options_->statistics.get(), TABLE_OPEN_IO_MICROS);
s = options_->table_factory->GetTableReader(*options_, toptions,
std::move(file), file_size,
&table_reader);
s = options_->table_factory->NewTableReader(
*options_, toptions, std::move(file), file_size, &table_reader);
}

if (!s.ok()) {
Expand Down
8 changes: 5 additions & 3 deletions db/table_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#pragma once
#include <string>
#include <stdint.h>

#include "db/dbformat.h"
#include "rocksdb/env.h"
#include "rocksdb/cache.h"
#include "port/port.h"
#include "rocksdb/table.h"
#include "rocksdb/cache.h"
#include "rocksdb/env.h"
#include "table/table_factory.h"
#include "table/table_reader.h"

namespace rocksdb {

Expand Down
11 changes: 5 additions & 6 deletions db/table_properties_collector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include <memory>
#include <string>

#include "db/dbformat.h"
#include "db/db_impl.h"
#include "db/dbformat.h"
#include "db/table_properties_collector.h"
#include "rocksdb/table_properties.h"
#include "rocksdb/table.h"
#include "rocksdb/plain_table_factory.h"
#include "table/block_based_table_factory.h"
#include "table/meta_blocks.h"
#include "table/plain_table_factory.h"
#include "table/table_builder.h"
#include "util/coding.h"
#include "util/testharness.h"
#include "util/testutil.h"
Expand Down Expand Up @@ -88,9 +88,8 @@ void MakeBuilder(
std::unique_ptr<FakeWritableFile>* writable,
std::unique_ptr<TableBuilder>* builder) {
writable->reset(new FakeWritableFile);
builder->reset(
options.table_factory->GetTableBuilder(options, writable->get(),
options.compression));
builder->reset(options.table_factory->NewTableBuilder(
options, writable->get(), options.compression));
}

// Collects keys that starts with "A" in a table.
Expand Down
3 changes: 2 additions & 1 deletion db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <algorithm>
#include <climits>
#include <stdio.h>

#include "db/filename.h"
#include "db/log_reader.h"
#include "db/log_writer.h"
Expand All @@ -21,7 +22,7 @@
#include "db/compaction.h"
#include "rocksdb/env.h"
#include "rocksdb/merge_operator.h"
#include "rocksdb/table.h"
#include "table/table_reader.h"
#include "table/merger.h"
#include "table/two_level_iterator.h"
#include "util/coding.h"
Expand Down
Loading

0 comments on commit 4f6cb17

Please sign in to comment.