2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// 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).
|
2014-12-23 22:24:07 +01:00
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2019-09-16 19:31:27 +02:00
|
|
|
#include "file/random_access_file_reader.h"
|
2019-10-09 04:17:39 +02:00
|
|
|
#include "port/stack_trace.h"
|
2014-12-23 22:24:07 +01:00
|
|
|
#include "rocksdb/filter_policy.h"
|
2019-05-30 23:47:29 +02:00
|
|
|
#include "table/block_based/block_based_table_factory.h"
|
2014-12-23 22:24:07 +01:00
|
|
|
#include "table/table_builder.h"
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/testharness.h"
|
|
|
|
#include "test_util/testutil.h"
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2020-05-19 18:20:21 +02:00
|
|
|
const uint32_t kOptLength = 1024;
|
2014-12-23 22:24:07 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-01-03 20:11:09 +01:00
|
|
|
void cleanup(const Options& opts, const std::string& file_name) {
|
|
|
|
Env* env = opts.env;
|
2020-09-05 04:25:20 +02:00
|
|
|
ASSERT_OK(env->DeleteFile(file_name));
|
2014-12-23 22:24:07 +01:00
|
|
|
std::string outfile_name = file_name.substr(0, file_name.length() - 4);
|
|
|
|
outfile_name.append("_dump.txt");
|
2020-09-05 04:25:20 +02:00
|
|
|
env->DeleteFile(outfile_name).PermitUncheckedError();
|
2014-12-23 22:24:07 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test for sst dump tool "raw" mode
|
2015-03-17 22:08:00 +01:00
|
|
|
class SSTDumpToolTest : public testing::Test {
|
2019-10-09 04:17:39 +02:00
|
|
|
std::string test_dir_;
|
|
|
|
Env* env_;
|
|
|
|
std::shared_ptr<Env> env_guard_;
|
2018-08-23 19:04:10 +02:00
|
|
|
|
|
|
|
public:
|
2019-10-09 04:17:39 +02:00
|
|
|
SSTDumpToolTest() : env_(Env::Default()) {
|
|
|
|
const char* test_env_uri = getenv("TEST_ENV_URI");
|
|
|
|
if (test_env_uri) {
|
|
|
|
Env::LoadEnv(test_env_uri, &env_, &env_guard_);
|
|
|
|
}
|
|
|
|
test_dir_ = test::PerThreadDBPath(env_, "sst_dump_test_db");
|
|
|
|
Status s = env_->CreateDirIfMissing(test_dir_);
|
|
|
|
EXPECT_OK(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
~SSTDumpToolTest() override {
|
|
|
|
if (getenv("KEEP_DB")) {
|
|
|
|
fprintf(stdout, "Data is still at %s\n", test_dir_.c_str());
|
|
|
|
} else {
|
|
|
|
EXPECT_OK(env_->DeleteDir(test_dir_));
|
|
|
|
}
|
|
|
|
}
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2019-10-09 04:17:39 +02:00
|
|
|
Env* env() { return env_; }
|
2018-08-09 23:21:35 +02:00
|
|
|
|
|
|
|
std::string MakeFilePath(const std::string& file_name) const {
|
2019-10-09 04:17:39 +02:00
|
|
|
std::string path(test_dir_);
|
2018-08-09 23:21:35 +02:00
|
|
|
path.append("/").append(file_name);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2018-08-23 19:04:10 +02:00
|
|
|
template <std::size_t N>
|
2018-08-09 23:21:35 +02:00
|
|
|
void PopulateCommandArgs(const std::string& file_path, const char* command,
|
2018-08-23 19:04:10 +02:00
|
|
|
char* (&usage)[N]) const {
|
2018-08-10 04:37:47 +02:00
|
|
|
for (int i = 0; i < static_cast<int>(N); ++i) {
|
2020-05-13 03:21:32 +02:00
|
|
|
usage[i] = new char[kOptLength];
|
2018-08-09 23:21:35 +02:00
|
|
|
}
|
2020-05-13 03:21:32 +02:00
|
|
|
snprintf(usage[0], kOptLength, "./sst_dump");
|
|
|
|
snprintf(usage[1], kOptLength, "%s", command);
|
|
|
|
snprintf(usage[2], kOptLength, "--file=%s", file_path.c_str());
|
2018-08-09 23:21:35 +02:00
|
|
|
}
|
2020-09-05 04:25:20 +02:00
|
|
|
|
|
|
|
void createSST(const Options& opts, const std::string& file_name) {
|
2020-09-08 21:08:05 +02:00
|
|
|
Env* test_env = opts.env;
|
2021-01-29 07:08:46 +01:00
|
|
|
FileOptions file_options(opts);
|
2020-09-05 04:25:20 +02:00
|
|
|
ReadOptions read_options;
|
2021-05-05 22:59:21 +02:00
|
|
|
const ImmutableOptions imoptions(opts);
|
2020-09-05 04:25:20 +02:00
|
|
|
const MutableCFOptions moptions(opts);
|
|
|
|
ROCKSDB_NAMESPACE::InternalKeyComparator ikc(opts.comparator);
|
|
|
|
std::unique_ptr<TableBuilder> tb;
|
|
|
|
|
2021-05-18 03:27:42 +02:00
|
|
|
IntTblPropCollectorFactories int_tbl_prop_collector_factories;
|
2021-01-29 07:08:46 +01:00
|
|
|
std::unique_ptr<WritableFileWriter> file_writer;
|
|
|
|
ASSERT_OK(WritableFileWriter::Create(test_env->GetFileSystem(), file_name,
|
|
|
|
file_options, &file_writer, nullptr));
|
|
|
|
|
2020-09-05 04:25:20 +02:00
|
|
|
std::string column_family_name;
|
|
|
|
int unknown_level = -1;
|
|
|
|
tb.reset(opts.table_factory->NewTableBuilder(
|
|
|
|
TableBuilderOptions(
|
|
|
|
imoptions, moptions, ikc, &int_tbl_prop_collector_factories,
|
2021-03-25 22:58:23 +01:00
|
|
|
CompressionType::kNoCompression, CompressionOptions(),
|
2021-04-29 15:59:53 +02:00
|
|
|
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily,
|
|
|
|
column_family_name, unknown_level),
|
2020-09-05 04:25:20 +02:00
|
|
|
file_writer.get()));
|
|
|
|
|
|
|
|
// Populate slightly more than 1K keys
|
|
|
|
uint32_t num_keys = kNumKey;
|
|
|
|
for (uint32_t i = 0; i < num_keys; i++) {
|
|
|
|
tb->Add(MakeKey(i), MakeValue(i));
|
|
|
|
}
|
|
|
|
ASSERT_OK(tb->Finish());
|
2020-12-24 01:54:05 +01:00
|
|
|
ASSERT_OK(file_writer->Close());
|
2020-09-05 04:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
constexpr static int kNumKey = 1024;
|
2014-12-23 22:24:07 +01:00
|
|
|
};
|
|
|
|
|
2020-09-05 04:25:20 +02:00
|
|
|
constexpr int SSTDumpToolTest::kNumKey;
|
|
|
|
|
2020-06-09 19:01:12 +02:00
|
|
|
TEST_F(SSTDumpToolTest, HelpAndVersion) {
|
|
|
|
Options opts;
|
|
|
|
opts.env = env();
|
|
|
|
|
|
|
|
ROCKSDB_NAMESPACE::SSTDumpTool tool;
|
|
|
|
|
|
|
|
static const char* help[] = {"./sst_dump", "--help"};
|
|
|
|
ASSERT_TRUE(!tool.Run(2, help, opts));
|
|
|
|
static const char* version[] = {"./sst_dump", "--version"};
|
|
|
|
ASSERT_TRUE(!tool.Run(2, version, opts));
|
|
|
|
static const char* bad[] = {"./sst_dump", "--not_an_option"};
|
|
|
|
ASSERT_TRUE(tool.Run(2, bad, opts));
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(SSTDumpToolTest, EmptyFilter) {
|
2019-01-03 20:11:09 +01:00
|
|
|
Options opts;
|
2019-10-09 04:17:39 +02:00
|
|
|
opts.env = env();
|
2018-08-09 23:21:35 +02:00
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
2019-01-03 20:11:09 +01:00
|
|
|
createSST(opts, file_path);
|
2014-12-23 22:24:07 +01:00
|
|
|
|
|
|
|
char* usage[3];
|
2018-08-09 23:21:35 +02:00
|
|
|
PopulateCommandArgs(file_path, "--command=raw", usage);
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SSTDumpTool tool;
|
2019-01-03 20:11:09 +01:00
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2019-01-03 20:11:09 +01:00
|
|
|
cleanup(opts, file_path);
|
2014-12-23 22:24:07 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(SSTDumpToolTest, FilterBlock) {
|
2019-01-03 20:11:09 +01:00
|
|
|
Options opts;
|
2019-10-09 04:17:39 +02:00
|
|
|
opts.env = env();
|
2019-01-03 20:11:09 +01:00
|
|
|
BlockBasedTableOptions table_opts;
|
2020-02-20 21:07:53 +01:00
|
|
|
table_opts.filter_policy.reset(
|
|
|
|
ROCKSDB_NAMESPACE::NewBloomFilterPolicy(10, true));
|
2019-01-03 20:11:09 +01:00
|
|
|
opts.table_factory.reset(new BlockBasedTableFactory(table_opts));
|
2018-08-09 23:21:35 +02:00
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
2019-01-03 20:11:09 +01:00
|
|
|
createSST(opts, file_path);
|
2014-12-23 22:24:07 +01:00
|
|
|
|
|
|
|
char* usage[3];
|
2018-08-09 23:21:35 +02:00
|
|
|
PopulateCommandArgs(file_path, "--command=raw", usage);
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SSTDumpTool tool;
|
2019-01-03 20:11:09 +01:00
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2019-01-03 20:11:09 +01:00
|
|
|
cleanup(opts, file_path);
|
2014-12-23 22:24:07 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(SSTDumpToolTest, FullFilterBlock) {
|
2019-01-03 20:11:09 +01:00
|
|
|
Options opts;
|
2019-10-09 04:17:39 +02:00
|
|
|
opts.env = env();
|
2019-01-03 20:11:09 +01:00
|
|
|
BlockBasedTableOptions table_opts;
|
2020-02-20 21:07:53 +01:00
|
|
|
table_opts.filter_policy.reset(
|
|
|
|
ROCKSDB_NAMESPACE::NewBloomFilterPolicy(10, false));
|
2019-01-03 20:11:09 +01:00
|
|
|
opts.table_factory.reset(new BlockBasedTableFactory(table_opts));
|
2018-08-09 23:21:35 +02:00
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
2019-01-03 20:11:09 +01:00
|
|
|
createSST(opts, file_path);
|
2014-12-23 22:24:07 +01:00
|
|
|
|
|
|
|
char* usage[3];
|
2018-08-09 23:21:35 +02:00
|
|
|
PopulateCommandArgs(file_path, "--command=raw", usage);
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SSTDumpTool tool;
|
2019-01-03 20:11:09 +01:00
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2019-01-03 20:11:09 +01:00
|
|
|
cleanup(opts, file_path);
|
2014-12-23 22:24:07 +01:00
|
|
|
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) {
|
2019-01-03 20:11:09 +01:00
|
|
|
Options opts;
|
2019-10-09 04:17:39 +02:00
|
|
|
opts.env = env();
|
2019-01-03 20:11:09 +01:00
|
|
|
BlockBasedTableOptions table_opts;
|
2020-02-20 21:07:53 +01:00
|
|
|
table_opts.filter_policy.reset(
|
|
|
|
ROCKSDB_NAMESPACE::NewBloomFilterPolicy(10, false));
|
2019-01-03 20:11:09 +01:00
|
|
|
opts.table_factory.reset(new BlockBasedTableFactory(table_opts));
|
2018-08-09 23:21:35 +02:00
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
2019-01-03 20:11:09 +01:00
|
|
|
createSST(opts, file_path);
|
2015-02-26 01:34:26 +01:00
|
|
|
|
|
|
|
char* usage[3];
|
2018-08-09 23:21:35 +02:00
|
|
|
PopulateCommandArgs(file_path, "--show_properties", usage);
|
2015-02-26 01:34:26 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SSTDumpTool tool;
|
2019-01-03 20:11:09 +01:00
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
2015-02-26 01:34:26 +01:00
|
|
|
|
2019-01-03 20:11:09 +01:00
|
|
|
cleanup(opts, file_path);
|
2015-02-26 01:34:26 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
2015-07-24 02:05:33 +02:00
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, CompressedSizes) {
|
2019-01-03 20:11:09 +01:00
|
|
|
Options opts;
|
2019-10-09 04:17:39 +02:00
|
|
|
opts.env = env();
|
2019-01-03 20:11:09 +01:00
|
|
|
BlockBasedTableOptions table_opts;
|
2020-02-20 21:07:53 +01:00
|
|
|
table_opts.filter_policy.reset(
|
|
|
|
ROCKSDB_NAMESPACE::NewBloomFilterPolicy(10, false));
|
2019-01-03 20:11:09 +01:00
|
|
|
opts.table_factory.reset(new BlockBasedTableFactory(table_opts));
|
2018-08-09 23:21:35 +02:00
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
2019-01-03 20:11:09 +01:00
|
|
|
createSST(opts, file_path);
|
2015-07-24 02:05:33 +02:00
|
|
|
|
|
|
|
char* usage[3];
|
2018-08-09 23:21:35 +02:00
|
|
|
PopulateCommandArgs(file_path, "--command=recompress", usage);
|
2015-07-24 02:05:33 +02:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SSTDumpTool tool;
|
2019-01-03 20:11:09 +01:00
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
2015-07-24 02:05:33 +02:00
|
|
|
|
2019-01-03 20:11:09 +01:00
|
|
|
cleanup(opts, file_path);
|
2015-07-24 02:05:33 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 20:11:09 +01:00
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, MemEnv) {
|
2019-10-09 04:17:39 +02:00
|
|
|
std::unique_ptr<Env> mem_env(NewMemEnv(env()));
|
2019-01-03 20:11:09 +01:00
|
|
|
Options opts;
|
2019-10-09 04:17:39 +02:00
|
|
|
opts.env = mem_env.get();
|
2019-01-03 20:11:09 +01:00
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, file_path);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs(file_path, "--command=verify_checksum", usage);
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::SSTDumpTool tool;
|
2019-01-03 20:11:09 +01:00
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
cleanup(opts, file_path);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 03:21:32 +02:00
|
|
|
TEST_F(SSTDumpToolTest, ReadaheadSize) {
|
|
|
|
Options opts;
|
|
|
|
opts.env = env();
|
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, file_path);
|
|
|
|
|
|
|
|
char* usage[4];
|
|
|
|
PopulateCommandArgs(file_path, "--command=verify", usage);
|
|
|
|
snprintf(usage[3], kOptLength, "--readahead_size=4000000");
|
|
|
|
|
|
|
|
int num_reads = 0;
|
|
|
|
SyncPoint::GetInstance()->SetCallBack("RandomAccessFileReader::Read",
|
|
|
|
[&](void*) { num_reads++; });
|
|
|
|
SyncPoint::GetInstance()->EnableProcessing();
|
|
|
|
|
|
|
|
SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(4, usage, opts));
|
|
|
|
|
|
|
|
// The file is approximately 10MB. Readahead is 4MB.
|
|
|
|
// We usually need 3 reads + one metadata read.
|
|
|
|
// One extra read is needed before opening the file for metadata.
|
|
|
|
ASSERT_EQ(5, num_reads);
|
|
|
|
|
|
|
|
SyncPoint::GetInstance()->ClearAllCallBacks();
|
|
|
|
SyncPoint::GetInstance()->DisableProcessing();
|
|
|
|
|
|
|
|
cleanup(opts, file_path);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 20:38:34 +02:00
|
|
|
TEST_F(SSTDumpToolTest, NoSstFile) {
|
|
|
|
Options opts;
|
|
|
|
opts.env = env();
|
|
|
|
std::string file_path = MakeFilePath("no_such_file.sst");
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs(file_path, "", usage);
|
|
|
|
ROCKSDB_NAMESPACE::SSTDumpTool tool;
|
|
|
|
for (const auto& command :
|
|
|
|
{"--command=check", "--command=dump", "--command=raw",
|
|
|
|
"--command=verify", "--command=recompress", "--command=verify_checksum",
|
|
|
|
"--show_properties"}) {
|
|
|
|
snprintf(usage[1], kOptLength, "%s", command);
|
2020-06-08 22:56:22 +02:00
|
|
|
ASSERT_TRUE(tool.Run(3, usage, opts));
|
2020-06-04 20:38:34 +02:00
|
|
|
}
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-08 22:56:22 +02:00
|
|
|
TEST_F(SSTDumpToolTest, ValidSSTPath) {
|
|
|
|
Options opts;
|
|
|
|
opts.env = env();
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs("", "", usage);
|
|
|
|
SSTDumpTool tool;
|
|
|
|
std::string file_not_exists = MakeFilePath("file_not_exists.sst");
|
|
|
|
std::string sst_file = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, sst_file);
|
|
|
|
std::string text_file = MakeFilePath("text_file");
|
|
|
|
ASSERT_OK(WriteStringToFile(opts.env, "Hello World!", text_file));
|
|
|
|
std::string fake_sst = MakeFilePath("fake_sst.sst");
|
|
|
|
ASSERT_OK(WriteStringToFile(opts.env, "Not an SST file!", fake_sst));
|
|
|
|
|
|
|
|
for (const auto& command_arg : {"--command=verify", "--command=identify"}) {
|
|
|
|
snprintf(usage[1], kOptLength, "%s", command_arg);
|
|
|
|
|
|
|
|
snprintf(usage[2], kOptLength, "--file=%s", file_not_exists.c_str());
|
|
|
|
ASSERT_TRUE(tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
snprintf(usage[2], kOptLength, "--file=%s", sst_file.c_str());
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
snprintf(usage[2], kOptLength, "--file=%s", text_file.c_str());
|
|
|
|
ASSERT_TRUE(tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
snprintf(usage[2], kOptLength, "--file=%s", fake_sst.c_str());
|
|
|
|
ASSERT_TRUE(tool.Run(3, usage, opts));
|
|
|
|
}
|
|
|
|
ASSERT_OK(opts.env->DeleteFile(sst_file));
|
|
|
|
ASSERT_OK(opts.env->DeleteFile(text_file));
|
|
|
|
ASSERT_OK(opts.env->DeleteFile(fake_sst));
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
2020-09-05 04:25:20 +02:00
|
|
|
|
|
|
|
TEST_F(SSTDumpToolTest, RawOutput) {
|
|
|
|
Options opts;
|
|
|
|
opts.env = env();
|
|
|
|
std::string file_path = MakeFilePath("rocksdb_sst_test.sst");
|
|
|
|
createSST(opts, file_path);
|
|
|
|
|
|
|
|
char* usage[3];
|
|
|
|
PopulateCommandArgs(file_path, "--command=raw", usage);
|
|
|
|
|
|
|
|
ROCKSDB_NAMESPACE::SSTDumpTool tool;
|
|
|
|
ASSERT_TRUE(!tool.Run(3, usage, opts));
|
|
|
|
|
|
|
|
const std::string raw_path = MakeFilePath("rocksdb_sst_test_dump.txt");
|
|
|
|
std::ifstream raw_file(raw_path);
|
|
|
|
|
|
|
|
std::string tp;
|
|
|
|
bool is_data_block = false;
|
|
|
|
int key_count = 0;
|
|
|
|
while (getline(raw_file, tp)) {
|
|
|
|
if (tp.find("Data Block #") != std::string::npos) {
|
|
|
|
is_data_block = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_data_block && tp.find("HEX") != std::string::npos) {
|
|
|
|
key_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_EQ(kNumKey, key_count);
|
|
|
|
|
Fix testcase failures on windows (#7992)
Summary:
Fixed 5 test case failures found on Windows 10/Windows Server 2016
1. In `flush_job_test`, the DestroyDir function fails in deconstructor because some file handles are still being held by VersionSet. This happens on Windows Server 2016, so need to manually reset versions_ pointer to release all file handles.
2. In `StatsHistoryTest.InMemoryStatsHistoryPurging` test, the capping memory cost of stats_history_size on Windows becomes 14000 bytes with latest changes, not just 13000 bytes.
3. In `SSTDumpToolTest.RawOutput` test, the output file handle is not closed at the end.
4. In `FullBloomTest.OptimizeForMemory` test, ROCKSDB_MALLOC_USABLE_SIZE is undefined on windows so `total_mem` is always equal to `total_size`. The internal memory fragmentation assertion does not apply in this case.
5. In `BlockFetcherTest.FetchAndUncompressCompressedDataBlock` test, XPRESS cannot reach 87.5% compression ratio with original CreateTable method, so I append extra zeros to the string value to enhance compression ratio. Beside, since XPRESS allocates memory internally, thus does not support for custom allocator verification, we will skip the allocator verification for XPRESS
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7992
Reviewed By: jay-zhuang
Differential Revision: D26615283
Pulled By: ajkr
fbshipit-source-id: 3632612f84b99e2b9c77c403b112b6bedf3b125d
2021-02-23 23:31:50 +01:00
|
|
|
raw_file.close();
|
|
|
|
|
2020-09-05 04:25:20 +02:00
|
|
|
cleanup(opts, file_path);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
delete[] usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2014-12-23 22:24:07 +01:00
|
|
|
|
2019-10-09 04:17:39 +02:00
|
|
|
#ifdef ROCKSDB_UNITTESTS_WITH_CUSTOM_OBJECTS_FROM_STATIC_LIBS
|
|
|
|
extern "C" {
|
|
|
|
void RegisterCustomObjects(int argc, char** argv);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void RegisterCustomObjects(int /*argc*/, char** /*argv*/) {}
|
|
|
|
#endif // !ROCKSDB_UNITTESTS_WITH_CUSTOM_OBJECTS_FROM_STATIC_LIBS
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
int main(int argc, char** argv) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
|
2015-03-17 22:08:00 +01:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
2019-10-09 04:17:39 +02:00
|
|
|
RegisterCustomObjects(argc, argv);
|
2015-03-17 22:08:00 +01:00
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|
2015-07-20 20:24:54 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-04-16 02:19:57 +02:00
|
|
|
int main(int /*argc*/, char** /*argv*/) {
|
2015-07-20 20:24:54 +02:00
|
|
|
fprintf(stderr, "SKIPPED as SSTDumpTool is not supported in ROCKSDB_LITE\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !ROCKSDB_LITE return RUN_ALL_TESTS();
|