// Copyright (c) 2011-present, 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.
+// 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
ReadOptions read_options;
Options opts;
const ImmutableCFOptions imoptions(opts);
+ const MutableCFOptions moptions(opts);
rocksdb::InternalKeyComparator ikc(opts.comparator);
unique_ptr<TableBuilder> tb;
- env->NewWritableFile(file_name, &file, env_options);
+ ASSERT_OK(env->NewWritableFile(file_name, &file, env_options));
+
opts.table_factory = tf;
std::vector<std::unique_ptr<IntTblPropCollectorFactory> >
int_tbl_prop_collector_factories;
- unique_ptr<WritableFileWriter> file_writer(
- new WritableFileWriter(std::move(file), EnvOptions()));
+ std::unique_ptr<WritableFileWriter> file_writer(
+ new WritableFileWriter(std::move(file), file_name, 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,
- unknown_level),
+ TableBuilderOptions(
+ imoptions, moptions, ikc, &int_tbl_prop_collector_factories,
+ CompressionType::kNoCompression, CompressionOptions(),
+ nullptr /* compression_dict */, false /* skip_filters */,
+ column_family_name, unknown_level),
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily,
file_writer.get()));
// Test for sst dump tool "raw" mode
class SSTDumpToolTest : public testing::Test {
+ std::string testDir_;
+
public:
BlockBasedTableOptions table_options_;
- SSTDumpToolTest() {}
+ SSTDumpToolTest() { testDir_ = test::TmpDir(); }
~SSTDumpToolTest() {}
+
+ 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) {
- std::string file_name = "rocksdb_sst_test.sst";
- createSST(file_name, table_options_);
+ std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
+ createSST(file_path, 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");
+ PopulateCommandArgs(file_path, "--command=raw", usage);
rocksdb::SSTDumpTool tool;
ASSERT_TRUE(!tool.Run(3, usage));
- cleanup(file_name);
+ cleanup(file_path);
for (int i = 0; i < 3; i++) {
delete[] usage[i];
}
TEST_F(SSTDumpToolTest, FilterBlock) {
table_options_.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, true));
- std::string file_name = "rocksdb_sst_test.sst";
- createSST(file_name, table_options_);
+ std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
+ createSST(file_path, 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");
+ PopulateCommandArgs(file_path, "--command=raw", usage);
rocksdb::SSTDumpTool tool;
ASSERT_TRUE(!tool.Run(3, usage));
- cleanup(file_name);
+ cleanup(file_path);
for (int i = 0; i < 3; i++) {
delete[] usage[i];
}
TEST_F(SSTDumpToolTest, FullFilterBlock) {
table_options_.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
- std::string file_name = "rocksdb_sst_test.sst";
- createSST(file_name, table_options_);
+ std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
+ createSST(file_path, 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");
+ PopulateCommandArgs(file_path, "--command=raw", usage);
rocksdb::SSTDumpTool tool;
ASSERT_TRUE(!tool.Run(3, usage));
- cleanup(file_name);
+ cleanup(file_path);
for (int i = 0; i < 3; i++) {
delete[] usage[i];
}
TEST_F(SSTDumpToolTest, GetProperties) {
table_options_.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false));
- std::string file_name = "rocksdb_sst_test.sst";
- createSST(file_name, table_options_);
+ std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
+ createSST(file_path, 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");
+ PopulateCommandArgs(file_path, "--show_properties", usage);
rocksdb::SSTDumpTool tool;
ASSERT_TRUE(!tool.Run(3, usage));
- cleanup(file_name);
+ cleanup(file_path);
for (int i = 0; i < 3; i++) {
delete[] usage[i];
}
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_);
+ std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
+ createSST(file_path, table_options_);
char* usage[3];
- for (int i = 0; i < 3; i++) {
- usage[i] = new char[optLength];
- }
+ PopulateCommandArgs(file_path, "--command=recompress", usage);
- 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);
+ cleanup(file_path);
for (int i = 0; i < 3; i++) {
delete[] usage[i];
}
#else
#include <stdio.h>
-int main(int argc, char** argv) {
+int main(int /*argc*/, char** /*argv*/) {
fprintf(stderr, "SKIPPED as SSTDumpTool is not supported in ROCKSDB_LITE\n");
return 0;
}