d9f4875e52
Summary: BlockBasedTable pre-fetches the filter and index blocks on Open call. This is an optimistic optimization targeted for runtime scenario. The optimization is unnecessary for sst_dump_tool - Added a provision to disable pre-fetching of index and filter blocks in BlockBasedTable - Disabled pre-fetching for the sst_dump tool Stack for reference : #01 0x00000000005ed944 in snappy::InternalUncompress<snappy::SnappyArrayWriter> () from /home/engshare/third-party2/snappy/1.0.3/src/snappy-1.0.3/snappy.cc:148 #02 0x00000000005edeee in snappy::RawUncompress () from /home/engshare/third-party2/snappy/1.0.3/src/snappy-1.0.3/snappy.cc:947 #03 0x00000000004e0b4d in rocksdb::UncompressBlockContents () from /data/users/paultuckfield/rocksdb/./util/compression.h:69 #04 0x00000000004e145c in rocksdb::ReadBlockContents () from /data/users/paultuckfield/rocksdb/table/format.cc:334 #05 0x00000000004ca424 in rocksdb::(anonymous namespace)::ReadBlockFromFile () from /data/users/paultuckfield/rocksdb/table/block_based_table_reader.cc:70 #06 0x00000000004cccad in rocksdb::BlockBasedTable::CreateIndexReader () from /data/users/paultuckfield/rocksdb/table/block_based_table_reader.cc:173 #07 0x00000000004d17e5 in rocksdb::BlockBasedTable::Open () from /data/users/paultuckfield/rocksdb/table/block_based_table_reader.cc:553 #08 0x00000000004c8184 in rocksdb::BlockBasedTableFactory::NewTableReader () from /data/users/paultuckfield/rocksdb/table/block_based_table_factory.cc:51 #09 0x0000000000598463 in rocksdb::SstFileReader::NewTableReader () from /data/users/paultuckfield/rocksdb/util/sst_dump_tool.cc:69 #10 0x00000000005986c2 in rocksdb::SstFileReader::SstFileReader () from /data/users/paultuckfield/rocksdb/util/sst_dump_tool.cc:26 #11 0x0000000000599047 in rocksdb::SSTDumpTool::Run () from /data/users/paultuckfield/rocksdb/util/sst_dump_tool.cc:332 #12 0x0000000000409b06 in main () from /data/users/paultuckfield/rocksdb/tools/sst_dump.cc:12 Test Plan: - Added a unit test to trigger the code. - Also did some manual verification. - Passed all unit tests task #6296048 Reviewers: igor, rven, sdong Reviewed By: sdong Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D34041
175 lines
5.0 KiB
C++
175 lines
5.0 KiB
C++
// 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.
|
|
|
|
#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"
|
|
#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);
|
|
unique_ptr<TableBuilder> tb;
|
|
|
|
env->NewWritableFile(file_name, &file, env_options);
|
|
opts.table_factory = tf;
|
|
tb.reset(opts.table_factory->NewTableBuilder(imoptions, ikc, file.get(),
|
|
CompressionType::kNoCompression,
|
|
CompressionOptions()));
|
|
|
|
// 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();
|
|
file->Close();
|
|
}
|
|
|
|
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
|
|
class SSTDumpToolTest {
|
|
public:
|
|
BlockBasedTableOptions table_options_;
|
|
|
|
SSTDumpToolTest() {}
|
|
|
|
~SSTDumpToolTest() {}
|
|
};
|
|
|
|
TEST(SSTDumpToolTest, EmptyFilter) {
|
|
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];
|
|
}
|
|
}
|
|
|
|
TEST(SSTDumpToolTest, FilterBlock) {
|
|
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];
|
|
}
|
|
}
|
|
|
|
TEST(SSTDumpToolTest, FullFilterBlock) {
|
|
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];
|
|
}
|
|
}
|
|
|
|
TEST(SSTDumpToolTest, GetProperties) {
|
|
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];
|
|
}
|
|
}
|
|
} // namespace rocksdb
|
|
|
|
int main(int argc, char** argv) { return rocksdb::test::RunAllTests(); }
|