Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TableBuilderOptions::level and relevant changes #1335

Merged
merged 1 commit into from
Sep 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions db/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ TableBuilder* NewTableBuilder(
uint32_t column_family_id, const std::string& column_family_name,
WritableFileWriter* file, const CompressionType compression_type,
const CompressionOptions& compression_opts,
int level,
const std::string* compression_dict, const bool skip_filters) {
assert((column_family_id ==
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily) ==
Expand All @@ -53,7 +54,7 @@ TableBuilder* NewTableBuilder(
TableBuilderOptions(ioptions, internal_comparator,
int_tbl_prop_collector_factories, compression_type,
compression_opts, compression_dict, skip_filters,
column_family_name),
column_family_name, level),
column_family_id, file);
}

Expand Down Expand Up @@ -108,7 +109,7 @@ Status BuildTable(
builder = NewTableBuilder(
ioptions, internal_comparator, int_tbl_prop_collector_factories,
column_family_id, column_family_name, file_writer.get(), compression,
compression_opts);
compression_opts, level);
}

MergeHelper merge(env, internal_comparator.user_comparator(),
Expand Down
1 change: 1 addition & 0 deletions db/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ TableBuilder* NewTableBuilder(
uint32_t column_family_id, const std::string& column_family_name,
WritableFileWriter* file, const CompressionType compression_type,
const CompressionOptions& compression_opts,
int level,
const std::string* compression_dict = nullptr,
const bool skip_filters = false);

Expand Down
4 changes: 3 additions & 1 deletion db/compaction_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,9 @@ Status CompactionJob::OpenCompactionOutputFile(
*cfd->ioptions(), cfd->internal_comparator(),
cfd->int_tbl_prop_collector_factories(), cfd->GetID(), cfd->GetName(),
sub_compact->outfile.get(), sub_compact->compaction->output_compression(),
cfd->ioptions()->compression_opts, &sub_compact->compression_dict,
cfd->ioptions()->compression_opts,
sub_compact->compaction->output_level(),
&sub_compact->compression_dict,
skip_filters));
LogFlush(db_options_.info_log);
return s;
Expand Down
5 changes: 3 additions & 2 deletions db/table_properties_collector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ void MakeBuilder(const Options& options, const ImmutableCFOptions& ioptions,
std::unique_ptr<TableBuilder>* builder) {
unique_ptr<WritableFile> wf(new test::StringSink);
writable->reset(new WritableFileWriter(std::move(wf), EnvOptions()));

int unknown_level = -1;
builder->reset(NewTableBuilder(
ioptions, internal_comparator, int_tbl_prop_collector_factories,
kTestColumnFamilyId, kTestColumnFamilyName,
writable->get(), options.compression, options.compression_opts));
writable->get(), options.compression, options.compression_opts,
unknown_level));
}
} // namespace

Expand Down
4 changes: 2 additions & 2 deletions table/sst_file_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ Status SstFileWriter::Open(const std::string& file_path) {
new UserKeyTablePropertiesCollectorFactory(
user_collector_factories[i]));
}

int unknown_level = -1;
TableBuilderOptions table_builder_options(
r->ioptions, r->internal_comparator, &int_tbl_prop_collector_factories,
compression_type, r->ioptions.compression_opts,
nullptr /* compression_dict */, false /* skip_filters */,
r->column_family_name);
r->column_family_name, unknown_level);
r->file_writer.reset(
new WritableFileWriter(std::move(sst_file), r->env_options));
r->builder.reset(r->ioptions.table_factory->NewTableBuilder(
Expand Down
6 changes: 4 additions & 2 deletions table/table_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ struct TableBuilderOptions {
CompressionType _compression_type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind making TableBuilderOptions constructor explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'explicit' keyword for constructor is useful only when parameter number can be 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right ! please ignore my comment

const CompressionOptions& _compression_opts,
const std::string* _compression_dict, bool _skip_filters,
const std::string& _column_family_name)
const std::string& _column_family_name, int _level)
: ioptions(_ioptions),
internal_comparator(_internal_comparator),
int_tbl_prop_collector_factories(_int_tbl_prop_collector_factories),
compression_type(_compression_type),
compression_opts(_compression_opts),
compression_dict(_compression_dict),
skip_filters(_skip_filters),
column_family_name(_column_family_name) {}
column_family_name(_column_family_name),
level(_level) {}
const ImmutableCFOptions& ioptions;
const InternalKeyComparator& internal_comparator;
const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
Expand All @@ -73,6 +74,7 @@ struct TableBuilderOptions {
const std::string* compression_dict;
bool skip_filters; // only used by BlockBasedTableBuilder
const std::string& column_family_name;
int level; // what level this table/file is on, -1 for "not set, don't know"
};

// TableBuilder provides the interface used to build a Table
Expand Down
5 changes: 3 additions & 2 deletions table/table_reader_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ void TableReaderBenchmark(Options& opts, EnvOptions& env_options,
int_tbl_prop_collector_factories;

file_writer.reset(new WritableFileWriter(std::move(file), env_options));

int unknown_level = -1;
tb = opts.table_factory->NewTableBuilder(
TableBuilderOptions(ioptions, ikc, &int_tbl_prop_collector_factories,
CompressionType::kNoCompression,
CompressionOptions(),
nullptr /* compression_dict */,
false /* skip_filters */, kDefaultColumnFamilyName),
false /* skip_filters */, kDefaultColumnFamilyName,
unknown_level),
0 /* column_family_id */, file_writer.get());
} else {
s = DB::Open(opts, dbname, &db);
Expand Down
8 changes: 6 additions & 2 deletions table/table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,14 @@ class TableConstructor: public Constructor {
std::vector<std::unique_ptr<IntTblPropCollectorFactory>>
int_tbl_prop_collector_factories;
std::string column_family_name;
int unknown_level = -1;
builder.reset(ioptions.table_factory->NewTableBuilder(
TableBuilderOptions(ioptions, internal_comparator,
&int_tbl_prop_collector_factories,
options.compression, CompressionOptions(),
nullptr /* compression_dict */,
false /* skip_filters */, column_family_name),
false /* skip_filters */, column_family_name,
unknown_level),
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily,
file_writer_.get()));

Expand Down Expand Up @@ -2210,11 +2212,13 @@ TEST_F(PlainTableTest, BasicPlainTableProperties) {
std::vector<std::unique_ptr<IntTblPropCollectorFactory>>
int_tbl_prop_collector_factories;
std::string column_family_name;
int unknown_level = -1;
std::unique_ptr<TableBuilder> builder(factory.NewTableBuilder(
TableBuilderOptions(ioptions, ikc, &int_tbl_prop_collector_factories,
kNoCompression, CompressionOptions(),
nullptr /* compression_dict */,
false /* skip_filters */, column_family_name),
false /* skip_filters */, column_family_name,
unknown_level),
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily,
file_writer.get()));

Expand Down
4 changes: 3 additions & 1 deletion tools/sst_dump_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ void createSST(const std::string& file_name,
unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(file), EnvOptions()));
std::string column_family_name;
int unknown_level = -1;
tb.reset(opts.table_factory->NewTableBuilder(
TableBuilderOptions(imoptions, ikc, &int_tbl_prop_collector_factories,
CompressionType::kNoCompression, CompressionOptions(),
nullptr /* compression_dict */,
false /* skip_filters */, column_family_name),
false /* skip_filters */, column_family_name,
unknown_level),
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily,
file_writer.get()));

Expand Down
4 changes: 3 additions & 1 deletion tools/sst_dump_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ int SstFileReader::ShowAllCompressionSizes(size_t block_size) {
if (CompressionTypeSupported(i.first)) {
CompressionOptions compress_opt;
std::string column_family_name;
int unknown_level = -1;
TableBuilderOptions tb_opts(imoptions, ikc, &block_based_table_factories,
i.first, compress_opt,
nullptr /* compression_dict */,
false /* skip_filters */, column_family_name);
false /* skip_filters */, column_family_name,
unknown_level);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about just passing -1 directly (without using a variable) and adding a comment /* unknown level */

Something like this

false /* skip_filters */, column_family_name,
-1 /* unknown level */);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review, self explainable variable should be preferred to a comment. thought they are equivalent, as explained in:
http://www.refactoring.com/catalog/extractVariable.html

uint64_t file_size = CalculateCompressedTableSize(tb_opts, block_size);
fprintf(stdout, "Compression: %s", i.second);
fprintf(stdout, " Size: %" PRIu64 "\n", file_size);
Expand Down