]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/db/prefix_test.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / db / prefix_test.cc
index d1ec6a2c8a37579c4348b822b85fc78511643b2b..8592b8f313c070187011ea8f1991a38782653e9b 100644 (file)
@@ -25,6 +25,7 @@ int main() {
 #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"
@@ -68,7 +69,7 @@ struct TestKey {
 };
 
 // return a slice backed by test_key
-inline Slice TestKeyToSlice(std::string &s, const TestKey& test_key) {
+inline Slice TestKeyToSlice(std::strings, const TestKey& test_key) {
   s.clear();
   PutFixed64(&s, test_key.prefix);
   PutFixed64(&s, test_key.sorted);
@@ -76,20 +77,18 @@ inline Slice TestKeyToSlice(std::string &s, const TestKey& test_key) {
 }
 
 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 TestKeykey_a = &kkey_a;
+    const TestKeykey_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;
@@ -214,7 +213,7 @@ class SamePrefixTransform : public SliceTransform {
   bool FullLengthEnabled(size_t* /*len*/) const override { return false; }
 };
 
-}  // namespace
+}  // anonymous namespace
 
 class PrefixTest : public testing::Test {
  public:
@@ -225,7 +224,7 @@ class PrefixTest : public testing::Test {
     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;
@@ -238,21 +237,19 @@ class PrefixTest : public testing::Test {
     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));
@@ -311,7 +308,7 @@ TEST(SamePrefixTest, InDomainTest) {
     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());
 
@@ -331,7 +328,7 @@ TEST(SamePrefixTest, InDomainTest) {
     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());
 
@@ -349,9 +346,8 @@ TEST_F(PrefixTest, TestResult) {
     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;
@@ -528,7 +524,7 @@ TEST_F(PrefixTest, PrefixValid) {
     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;
@@ -543,7 +539,7 @@ TEST_F(PrefixTest, PrefixValid) {
       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)));
@@ -580,8 +576,8 @@ TEST_F(PrefixTest, PrefixValid) {
 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;
@@ -597,10 +593,9 @@ TEST_F(PrefixTest, DynamicPrefixIterator) {
 
     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;
@@ -608,15 +603,16 @@ TEST_F(PrefixTest, DynamicPrefixIterator) {
         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;
@@ -628,15 +624,14 @@ TEST_F(PrefixTest, DynamicPrefixIterator) {
       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());
@@ -645,12 +640,12 @@ TEST_F(PrefixTest, DynamicPrefixIterator) {
       }
       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
@@ -658,17 +653,17 @@ TEST_F(PrefixTest, DynamicPrefixIterator) {
     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());
     }
@@ -689,7 +684,7 @@ TEST_F(PrefixTest, PrefixSeekModePrev) {
   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;
@@ -714,7 +709,7 @@ TEST_F(PrefixTest, PrefixSeekModePrev) {
         }
       }
       if (i < 2) {
-        db->Flush(FlushOptions());
+        ASSERT_OK(db->Flush(FlushOptions()));
       }
     }
 
@@ -890,6 +885,7 @@ TEST_F(PrefixTest, PrefixSeekModePrev3) {
 }  // 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();