#include "rocksdb/memtablerep.h"
#include "rocksdb/perf_context.h"
#include "rocksdb/slice_transform.h"
+#include "rocksdb/system_clock.h"
#include "rocksdb/table.h"
#include "test_util/testharness.h"
#include "util/cast_util.h"
};
// return a slice backed by test_key
-inline Slice TestKeyToSlice(std::string &s, const TestKey& test_key) {
+inline Slice TestKeyToSlice(std::string& s, const TestKey& test_key) {
s.clear();
PutFixed64(&s, test_key.prefix);
PutFixed64(&s, test_key.sorted);
}
inline const TestKey SliceToTestKey(const Slice& slice) {
- return TestKey(DecodeFixed64(slice.data()),
- DecodeFixed64(slice.data() + 8));
+ return TestKey(DecodeFixed64(slice.data()), DecodeFixed64(slice.data() + 8));
}
class TestKeyComparator : public Comparator {
public:
-
// Compare needs to be aware of the possibility of a and/or b is
// prefix only
int Compare(const Slice& a, const Slice& b) const override {
const TestKey kkey_a = SliceToTestKey(a);
const TestKey kkey_b = SliceToTestKey(b);
- const TestKey *key_a = &kkey_a;
- const TestKey *key_b = &kkey_b;
+ const TestKey* key_a = &kkey_a;
+ const TestKey* key_b = &kkey_b;
if (key_a->prefix != key_b->prefix) {
if (key_a->prefix < key_b->prefix) return -1;
if (key_a->prefix > key_b->prefix) return 1;
bool FullLengthEnabled(size_t* /*len*/) const override { return false; }
};
-} // namespace
+} // anonymous namespace
class PrefixTest : public testing::Test {
public:
options.write_buffer_size = FLAGS_write_buffer_size;
options.max_write_buffer_number = FLAGS_max_write_buffer_number;
options.min_write_buffer_number_to_merge =
- FLAGS_min_write_buffer_number_to_merge;
+ FLAGS_min_write_buffer_number_to_merge;
options.memtable_prefix_bloom_size_ratio =
FLAGS_memtable_prefix_bloom_size_ratio;
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
options.allow_concurrent_memtable_write = false;
- Status s = DB::Open(options, kDbName, &db);
+ Status s = DB::Open(options, kDbName, &db);
EXPECT_OK(s);
return std::shared_ptr<DB>(db);
}
- void FirstOption() {
- option_config_ = kBegin;
- }
+ void FirstOption() { option_config_ = kBegin; }
bool NextOptions(int bucket_count) {
// skip some options
option_config_++;
if (option_config_ < kEnd) {
options.prefix_extractor.reset(NewFixedPrefixTransform(8));
- switch(option_config_) {
+ switch (option_config_) {
case kHashSkipList:
options.memtable_factory.reset(
NewHashSkipListRepFactory(bucket_count, FLAGS_skiplist_height));
ASSERT_OK(db->Put(write_options, "HHKB pro2", "Mar 24, 2006"));
ASSERT_OK(db->Put(write_options, "HHKB pro2 Type-S", "June 29, 2011"));
ASSERT_OK(db->Put(write_options, "Realforce 87u", "idk"));
- db->Flush(FlushOptions());
+ ASSERT_OK(db->Flush(FlushOptions()));
std::string result;
auto db_iter = db->NewIterator(ReadOptions());
ASSERT_OK(db->Put(write_options, "pikachu", "1"));
ASSERT_OK(db->Put(write_options, "Meowth", "1"));
ASSERT_OK(db->Put(write_options, "Mewtwo", "idk"));
- db->Flush(FlushOptions());
+ ASSERT_OK(db->Flush(FlushOptions()));
std::string result;
auto db_iter = db->NewIterator(ReadOptions());
FirstOption();
while (NextOptions(num_buckets)) {
std::cout << "*** Mem table: " << options.memtable_factory->Name()
- << " number of buckets: " << num_buckets
- << std::endl;
- DestroyDB(kDbName, Options());
+ << " number of buckets: " << num_buckets << std::endl;
+ ASSERT_OK(DestroyDB(kDbName, Options()));
auto db = OpenDb();
WriteOptions write_options;
ReadOptions read_options;
while (NextOptions(num_buckets)) {
std::cout << "*** Mem table: " << options.memtable_factory->Name()
<< " number of buckets: " << num_buckets << std::endl;
- DestroyDB(kDbName, Options());
+ ASSERT_OK(DestroyDB(kDbName, Options()));
auto db = OpenDb();
WriteOptions write_options;
ReadOptions read_options;
PutKey(db.get(), write_options, 12345, 8, v18);
PutKey(db.get(), write_options, 12345, 9, v19);
PutKey(db.get(), write_options, 12346, 8, v16);
- db->Flush(FlushOptions());
+ ASSERT_OK(db->Flush(FlushOptions()));
TestKey test_key(12346, 8);
std::string s;
ASSERT_OK(db->Delete(write_options, TestKeyToSlice(s, test_key)));
TEST_F(PrefixTest, DynamicPrefixIterator) {
while (NextOptions(FLAGS_bucket_count)) {
std::cout << "*** Mem table: " << options.memtable_factory->Name()
- << std::endl;
- DestroyDB(kDbName, Options());
+ << std::endl;
+ ASSERT_OK(DestroyDB(kDbName, Options()));
auto db = OpenDb();
WriteOptions write_options;
ReadOptions read_options;
HistogramImpl hist_put_time;
HistogramImpl hist_put_comparison;
-
// insert x random prefix, each with y continuous element.
for (auto prefix : prefixes) {
- for (uint64_t sorted = 0; sorted < FLAGS_items_per_prefix; sorted++) {
+ for (uint64_t sorted = 0; sorted < FLAGS_items_per_prefix; sorted++) {
TestKey test_key(prefix, sorted);
std::string s;
std::string value(FLAGS_value_size, 0);
get_perf_context()->Reset();
- StopWatchNano timer(Env::Default(), true);
+ StopWatchNano timer(SystemClock::Default().get(), true);
ASSERT_OK(db->Put(write_options, key, value));
hist_put_time.Add(timer.ElapsedNanos());
hist_put_comparison.Add(get_perf_context()->user_key_comparison_count);
}
}
- std::cout << "Put key comparison: \n" << hist_put_comparison.ToString()
- << "Put time: \n" << hist_put_time.ToString();
+ std::cout << "Put key comparison: \n"
+ << hist_put_comparison.ToString() << "Put time: \n"
+ << hist_put_time.ToString();
// test seek existing keys
HistogramImpl hist_seek_time;
TestKey test_key(prefix, FLAGS_items_per_prefix / 2);
std::string s;
Slice key = TestKeyToSlice(s, test_key);
- std::string value = "v" + ToString(0);
+ std::string value = "v" + std::to_string(0);
get_perf_context()->Reset();
- StopWatchNano timer(Env::Default(), true);
+ StopWatchNano timer(SystemClock::Default().get(), true);
auto key_prefix = options.prefix_extractor->Transform(key);
uint64_t total_keys = 0;
for (iter->Seek(key);
- iter->Valid() && iter->key().starts_with(key_prefix);
- iter->Next()) {
+ iter->Valid() && iter->key().starts_with(key_prefix); iter->Next()) {
if (FLAGS_trigger_deadlock) {
std::cout << "Behold the deadlock!\n";
db->Delete(write_options, iter->key());
}
hist_seek_time.Add(timer.ElapsedNanos());
hist_seek_comparison.Add(get_perf_context()->user_key_comparison_count);
- ASSERT_EQ(total_keys, FLAGS_items_per_prefix - FLAGS_items_per_prefix/2);
+ ASSERT_EQ(total_keys,
+ FLAGS_items_per_prefix - FLAGS_items_per_prefix / 2);
}
std::cout << "Seek key comparison: \n"
- << hist_seek_comparison.ToString()
- << "Seek time: \n"
+ << hist_seek_comparison.ToString() << "Seek time: \n"
<< hist_seek_time.ToString();
// test non-existing keys
HistogramImpl hist_no_seek_comparison;
for (auto prefix = FLAGS_total_prefixes;
- prefix < FLAGS_total_prefixes + 10000;
- prefix++) {
+ prefix < FLAGS_total_prefixes + 10000; prefix++) {
TestKey test_key(prefix, 0);
std::string s;
Slice key = TestKeyToSlice(s, test_key);
get_perf_context()->Reset();
- StopWatchNano timer(Env::Default(), true);
+ StopWatchNano timer(SystemClock::Default().get(), true);
iter->Seek(key);
hist_no_seek_time.Add(timer.ElapsedNanos());
- hist_no_seek_comparison.Add(get_perf_context()->user_key_comparison_count);
+ hist_no_seek_comparison.Add(
+ get_perf_context()->user_key_comparison_count);
ASSERT_TRUE(!iter->Valid());
ASSERT_OK(iter->status());
}
for (size_t m = 1; m < 100; m++) {
std::cout << "[" + std::to_string(m) + "]" + "*** Mem table: "
<< options.memtable_factory->Name() << std::endl;
- DestroyDB(kDbName, Options());
+ ASSERT_OK(DestroyDB(kDbName, Options()));
auto db = OpenDb();
WriteOptions write_options;
ReadOptions read_options;
}
}
if (i < 2) {
- db->Flush(FlushOptions());
+ ASSERT_OK(db->Flush(FlushOptions()));
}
}
} // namespace ROCKSDB_NAMESPACE
int main(int argc, char** argv) {
+ ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
::testing::InitGoogleTest(&argc, argv);
ParseCommandLineFlags(&argc, &argv, true);
return RUN_ALL_TESTS();