]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/bluefs: Improve unittest for compaction 45600/head
authorAdam Kupczyk <akupczyk@redhat.com>
Thu, 3 Mar 2022 14:36:58 +0000 (15:36 +0100)
committerAdam Kupczyk <akupczyk@redhat.com>
Wed, 23 Mar 2022 18:03:28 +0000 (19:03 +0100)
Improved unittest for compaction to add some files after compacting.
It is used to prove that there is a problem with sync compaction.

Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
(cherry picked from commit 40160365f344ebfb43173a5366015ac4cdb7a3fe)

src/test/objectstore/test_bluefs.cc

index 5738143b43912e78e5d166a07d50d1a6cce195bc..2a84b27c9992e22c59e1e6a182e0099860f33b2c 100644 (file)
@@ -618,6 +618,9 @@ TEST(BlueFS, test_compaction_sync) {
   g_ceph_context->_conf.set_val(
     "bluefs_compact_log_sync",
     "true");
+  const char* canary_dir = "dir.after_compact_test";
+  const char* canary_file = "file.after_compact_test";
+  const char* canary_data = "some random data";
 
   BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
@@ -642,6 +645,30 @@ TEST(BlueFS, test_compaction_sync) {
     writes_done = true;
     join_all(sync_threads);
     fs.compact_log();
+
+    {
+      ASSERT_EQ(0, fs.mkdir(canary_dir));
+      BlueFS::FileWriter *h;
+      ASSERT_EQ(0, fs.open_for_write(canary_dir, canary_file, &h, false));
+      ASSERT_NE(nullptr, h);
+      auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); });
+      h->append(canary_data, strlen(canary_data));
+      int r = fs.fsync(h);
+      ASSERT_EQ(r, 0);
+    }
+  }
+  fs.umount();
+
+  fs.mount();
+  {
+    BlueFS::FileReader *h;
+    ASSERT_EQ(0, fs.open_for_read(canary_dir, canary_file, &h));
+    ASSERT_NE(nullptr, h);
+    bufferlist bl;
+    ASSERT_EQ(strlen(canary_data), fs.read(h, 0, 1024, &bl, NULL));
+    std::cout << bl.c_str() << std::endl;
+    ASSERT_EQ(0, strncmp(canary_data, bl.c_str(), strlen(canary_data)));
+    delete h;
   }
   fs.umount();
 }
@@ -655,6 +682,9 @@ TEST(BlueFS, test_compaction_async) {
   g_ceph_context->_conf.set_val(
     "bluefs_compact_log_sync",
     "false");
+  const char* canary_dir = "dir.after_compact_test";
+  const char* canary_file = "file.after_compact_test";
+  const char* canary_data = "some random data";
 
   BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
@@ -679,6 +709,30 @@ TEST(BlueFS, test_compaction_async) {
     writes_done = true;
     join_all(sync_threads);
     fs.compact_log();
+
+    {
+      ASSERT_EQ(0, fs.mkdir(canary_dir));
+      BlueFS::FileWriter *h;
+      ASSERT_EQ(0, fs.open_for_write(canary_dir, canary_file, &h, false));
+      ASSERT_NE(nullptr, h);
+      auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); });
+      h->append(canary_data, strlen(canary_data));
+      int r = fs.fsync(h);
+      ASSERT_EQ(r, 0);
+    }
+  }
+  fs.umount();
+
+  fs.mount();
+  {
+    BlueFS::FileReader *h;
+    ASSERT_EQ(0, fs.open_for_read(canary_dir, canary_file, &h));
+    ASSERT_NE(nullptr, h);
+    bufferlist bl;
+    ASSERT_EQ(strlen(canary_data), fs.read(h, 0, 1024, &bl, NULL));
+    std::cout << bl.c_str() << std::endl;
+    ASSERT_EQ(0, strncmp(canary_data, bl.c_str(), strlen(canary_data)));
+    delete h;
   }
   fs.umount();
 }