|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root 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.
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
|
|
|
#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
9 years ago
|
|
|
#include "util/file_reader_writer.h"
|
|
|
|
#include "test_util/testharness.h"
|
|
|
|
#include "test_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 Options& opts, const std::string& file_name) {
|
|
|
|
Env* env = opts.env;
|
|
|
|
EnvOptions env_options(opts);
|
|
|
|
ReadOptions read_options;
|
|
|
|
const ImmutableCFOptions imoptions(opts);
|
|
|
|
const MutableCFOptions moptions(opts);
|
|
|
|
rocksdb::InternalKeyComparator ikc(opts.comparator);
|
|
|
|
std::unique_ptr<TableBuilder> tb;
|
|
|
|
|
|
|
|
std::unique_ptr<WritableFile> file;
|
|
|
|
ASSERT_OK(env->NewWritableFile(file_name, &file, env_options));
|
|
|
|
|
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
10 years ago
|
|
|
std::vector<std::unique_ptr<IntTblPropCollectorFactory> >
|
|
|
|
int_tbl_prop_collector_factories;
|
|
|
|
std::unique_ptr<WritableFileWriter> file_writer(
|
|
|
|
new WritableFileWriter(std::move(file), file_name, EnvOptions()));
|
|
|
|
std::string column_family_name;
|
|
|
|
int unknown_level = -1;
|
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
10 years ago
|
|
|
tb.reset(opts.table_factory->NewTableBuilder(
|
|
|
|
TableBuilderOptions(
|
|
|
|
imoptions, moptions, ikc, &int_tbl_prop_collector_factories,
|
|
|
|
CompressionType::kNoCompression, 0 /* sample_for_compression */,
|
|
|
|
CompressionOptions(), false /* skip_filters */, column_family_name,
|
|
|
|
unknown_level),
|
|
|
|
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
9 years ago
|
|
|
file_writer.get()));
|
|
|
|
|
|
|
|
// 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
9 years ago
|
|
|
file_writer->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup(const Options& opts, const std::string& file_name) {
|
|
|
|
Env* env = opts.env;
|
|
|
|
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
|
|
|
|
class SSTDumpToolTest : public testing::Test {
|
|
|
|
std::string testDir_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SSTDumpToolTest() { testDir_ = test::TmpDir(); }
|
|
|
|
|
|
|
|
~SSTDumpToolTest() override {}
|
|
|
|
|
|
|
|
std::string MakeFilePath(const std::string& file_name) const {
|
|
|
|
std::string path(testDir_);
|
|
|
|
path.append("/").append(file_name);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <std::size_t N>
|
|
|
|
void PopulateCommandArgs(const std::string& file_path, const char* command,
|
|
|
|
char* (&usage)[N]) const {
|
|
|
|
for (int i = 0; i < static_cast<int>(N); ++i) {
|
|
|
|
usage[i] = new char[optLength];
|
|
|
|
}
|
|
|
|
snprintf(usage[0], optLength, "./sst_dump");
|
|
|
|
snprintf(usage[1], optLength, "%s", command);
|
|
|
|
snprintf(usage[2], optLength, "--file=%s", file_path.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, EmptyFilter) {
|
|
|
|
Options opts;
|
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, file_path);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs(file_path, "--command=raw", usage);
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
cleanup(opts, file_path);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, FilterBlock) {
|
|
|
|
Options opts;
|
|
|
|
BlockBasedTableOptions table_opts;
|
|
|
|
table_opts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, true));
|
|
|
|
opts.table_factory.reset(new BlockBasedTableFactory(table_opts));
|
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, file_path);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs(file_path, "--command=raw", usage);
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
cleanup(opts, file_path);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, FullFilterBlock) {
|
|
|
|
Options opts;
|
|
|
|
BlockBasedTableOptions table_opts;
|
|
|
|
table_opts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
|
|
|
|
opts.table_factory.reset(new BlockBasedTableFactory(table_opts));
|
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, file_path);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs(file_path, "--command=raw", usage);
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
cleanup(opts, file_path);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, GetProperties) {
|
|
|
|
Options opts;
|
|
|
|
BlockBasedTableOptions table_opts;
|
|
|
|
table_opts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
|
|
|
|
opts.table_factory.reset(new BlockBasedTableFactory(table_opts));
|
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, file_path);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs(file_path, "--show_properties", usage);
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
cleanup(opts, file_path);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, CompressedSizes) {
|
|
|
|
Options opts;
|
|
|
|
BlockBasedTableOptions table_opts;
|
|
|
|
table_opts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
|
|
|
|
opts.table_factory.reset(new BlockBasedTableFactory(table_opts));
|
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, file_path);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs(file_path, "--command=recompress", usage);
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
cleanup(opts, file_path);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, MemEnv) {
|
|
|
|
std::unique_ptr<Env> env(NewMemEnv(Env::Default()));
|
|
|
|
Options opts;
|
|
|
|
opts.env = env.get();
|
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, file_path);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs(file_path, "--command=verify_checksum", usage);
|
|
|
|
|
|
|
|
rocksdb::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
cleanup(opts, file_path);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
#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();
|