2014-12-23 22:24:07 +01:00
|
|
|
// 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) 2012 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.
|
|
|
|
|
2015-07-20 20:24:54 +02:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2014-12-23 22:24:07 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include "rocksdb/sst_dump_tool.h"
|
|
|
|
|
|
|
|
#include "rocksdb/filter_policy.h"
|
|
|
|
#include "table/block_based_table_factory.h"
|
|
|
|
#include "table/table_builder.h"
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
#include "util/file_reader_writer.h"
|
2014-12-23 22:24:07 +01:00
|
|
|
#include "util/testharness.h"
|
|
|
|
#include "util/testutil.h"
|
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
const uint32_t optLength = 100;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
static std::string MakeKey(int i) {
|
|
|
|
char buf[100];
|
|
|
|
snprintf(buf, sizeof(buf), "k_%04d", i);
|
|
|
|
InternalKey key(std::string(buf), 0, ValueType::kTypeValue);
|
|
|
|
return key.Encode().ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string MakeValue(int i) {
|
|
|
|
char buf[100];
|
|
|
|
snprintf(buf, sizeof(buf), "v_%04d", i);
|
|
|
|
InternalKey key(std::string(buf), 0, ValueType::kTypeValue);
|
|
|
|
return key.Encode().ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void createSST(const std::string& file_name,
|
|
|
|
const BlockBasedTableOptions& table_options) {
|
|
|
|
std::shared_ptr<rocksdb::TableFactory> tf;
|
|
|
|
tf.reset(new rocksdb::BlockBasedTableFactory(table_options));
|
|
|
|
|
|
|
|
unique_ptr<WritableFile> file;
|
|
|
|
Env* env = Env::Default();
|
|
|
|
EnvOptions env_options;
|
|
|
|
ReadOptions read_options;
|
|
|
|
Options opts;
|
|
|
|
const ImmutableCFOptions imoptions(opts);
|
|
|
|
rocksdb::InternalKeyComparator ikc(opts.comparator);
|
2014-12-01 04:00:31 +01:00
|
|
|
unique_ptr<TableBuilder> tb;
|
2014-12-23 22:24:07 +01:00
|
|
|
|
|
|
|
env->NewWritableFile(file_name, &file, env_options);
|
|
|
|
opts.table_factory = tf;
|
A new call back to TablePropertiesCollector to allow users know the entry is add, delete or merge
Summary:
Currently users have no idea a key is add, delete or merge from TablePropertiesCollector call back. Add a new function to add it.
Also refactor the codes so that
(1) make table property collector and internal table property collector two separate data structures with the later one now exposed
(2) table builders only receive internal table properties
Test Plan: Add cases in table_properties_collector_test to cover both of old and new ways of using TablePropertiesCollector.
Reviewers: yhchiang, igor.sugak, rven, igor
Reviewed By: rven, igor
Subscribers: meyering, yoshinorim, maykov, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D35373
2015-04-06 19:04:30 +02:00
|
|
|
std::vector<std::unique_ptr<IntTblPropCollectorFactory> >
|
|
|
|
int_tbl_prop_collector_factories;
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
unique_ptr<WritableFileWriter> file_writer(
|
|
|
|
new WritableFileWriter(std::move(file), EnvOptions()));
|
A new call back to TablePropertiesCollector to allow users know the entry is add, delete or merge
Summary:
Currently users have no idea a key is add, delete or merge from TablePropertiesCollector call back. Add a new function to add it.
Also refactor the codes so that
(1) make table property collector and internal table property collector two separate data structures with the later one now exposed
(2) table builders only receive internal table properties
Test Plan: Add cases in table_properties_collector_test to cover both of old and new ways of using TablePropertiesCollector.
Reviewers: yhchiang, igor.sugak, rven, igor
Reviewed By: rven, igor
Subscribers: meyering, yoshinorim, maykov, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D35373
2015-04-06 19:04:30 +02:00
|
|
|
tb.reset(opts.table_factory->NewTableBuilder(
|
|
|
|
TableBuilderOptions(imoptions, ikc, &int_tbl_prop_collector_factories,
|
|
|
|
CompressionType::kNoCompression, CompressionOptions(),
|
|
|
|
false),
|
2015-10-09 01:57:35 +02:00
|
|
|
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily,
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
file_writer.get()));
|
2014-12-23 22:24:07 +01:00
|
|
|
|
|
|
|
// Populate slightly more than 1K keys
|
|
|
|
uint32_t num_keys = 1024;
|
|
|
|
for (uint32_t i = 0; i < num_keys; i++) {
|
|
|
|
tb->Add(MakeKey(i), MakeValue(i));
|
|
|
|
}
|
|
|
|
tb->Finish();
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
file_writer->Close();
|
2014-12-23 22:24:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup(const std::string& file_name) {
|
|
|
|
Env* env = Env::Default();
|
|
|
|
env->DeleteFile(file_name);
|
|
|
|
std::string outfile_name = file_name.substr(0, file_name.length() - 4);
|
|
|
|
outfile_name.append("_dump.txt");
|
|
|
|
env->DeleteFile(outfile_name);
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test for sst dump tool "raw" mode
|
2015-03-17 22:08:00 +01:00
|
|
|
class SSTDumpToolTest : public testing::Test {
|
2014-12-23 22:24:07 +01:00
|
|
|
public:
|
|
|
|
BlockBasedTableOptions table_options_;
|
|
|
|
|
|
|
|
SSTDumpToolTest() {}
|
|
|
|
|
|
|
|
~SSTDumpToolTest() {}
|
|
|
|
};
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(SSTDumpToolTest, EmptyFilter) {
|
2014-12-23 22:24:07 +01:00
|
|
|
std::string file_name = "rocksdb_sst_test.sst";
|
|
|
|
createSST(file_name, table_options_);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
usage[i] = new char[optLength];
|
|
|
|
}
|
|
|
|
snprintf(usage[0], optLength, "./sst_dump");
|
|
|
|
snprintf(usage[1], optLength, "--command=raw");
|
|
|
|
snprintf(usage[2], optLength, "--file=rocksdb_sst_test.sst");
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage));
|
|
|
|
|
|
|
|
cleanup(file_name);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(SSTDumpToolTest, FilterBlock) {
|
2014-12-23 22:24:07 +01:00
|
|
|
table_options_.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, true));
|
|
|
|
std::string file_name = "rocksdb_sst_test.sst";
|
|
|
|
createSST(file_name, table_options_);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
usage[i] = new char[optLength];
|
|
|
|
}
|
|
|
|
snprintf(usage[0], optLength, "./sst_dump");
|
|
|
|
snprintf(usage[1], optLength, "--command=raw");
|
|
|
|
snprintf(usage[2], optLength, "--file=rocksdb_sst_test.sst");
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage));
|
|
|
|
|
|
|
|
cleanup(file_name);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(SSTDumpToolTest, FullFilterBlock) {
|
2014-12-23 22:24:07 +01:00
|
|
|
table_options_.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
|
|
|
|
std::string file_name = "rocksdb_sst_test.sst";
|
|
|
|
createSST(file_name, table_options_);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
usage[i] = new char[optLength];
|
|
|
|
}
|
|
|
|
snprintf(usage[0], optLength, "./sst_dump");
|
|
|
|
snprintf(usage[1], optLength, "--command=raw");
|
|
|
|
snprintf(usage[2], optLength, "--file=rocksdb_sst_test.sst");
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage));
|
|
|
|
|
|
|
|
cleanup(file_name);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 01:34:26 +01:00
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(SSTDumpToolTest, GetProperties) {
|
2015-02-26 01:34:26 +01:00
|
|
|
table_options_.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
|
|
|
|
std::string file_name = "rocksdb_sst_test.sst";
|
|
|
|
createSST(file_name, table_options_);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
usage[i] = new char[optLength];
|
|
|
|
}
|
|
|
|
snprintf(usage[0], optLength, "./sst_dump");
|
|
|
|
snprintf(usage[1], optLength, "--show_properties");
|
|
|
|
snprintf(usage[2], optLength, "--file=rocksdb_sst_test.sst");
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage));
|
|
|
|
|
|
|
|
cleanup(file_name);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
2015-07-24 02:05:33 +02:00
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, CompressedSizes) {
|
|
|
|
table_options_.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
|
|
|
|
std::string file_name = "rocksdb_sst_test.sst";
|
|
|
|
createSST(file_name, table_options_);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
usage[i] = new char[optLength];
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(usage[0], optLength, "./sst_dump");
|
|
|
|
snprintf(usage[1], optLength, "--show_compression_sizes");
|
|
|
|
snprintf(usage[2], optLength, "--file=rocksdb_sst_test.sst");
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage));
|
|
|
|
|
|
|
|
cleanup(file_name);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
2014-12-23 22:24:07 +01:00
|
|
|
} // namespace rocksdb
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|
2015-07-20 20:24:54 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
fprintf(stderr, "SKIPPED as SSTDumpTool is not supported in ROCKSDB_LITE\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !ROCKSDB_LITE return RUN_ALL_TESTS();
|