From a5509f93a7b02e31950d1aba0625dd9996c9608e Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Tue, 25 Jul 2023 17:27:14 +0200 Subject: [PATCH] os/bluestore: test log runway expansion error Signed-off-by: Pere Diaz Bou --- src/test/objectstore/test_bluefs.cc | 153 ++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/src/test/objectstore/test_bluefs.cc b/src/test/objectstore/test_bluefs.cc index 4f77d8597ae1d..75496a89d2c39 100644 --- a/src/test/objectstore/test_bluefs.cc +++ b/src/test/objectstore/test_bluefs.cc @@ -1401,6 +1401,159 @@ TEST(BlueFS, test_concurrent_dir_link_and_compact_log_56210) { } } +TEST(BlueFS, test_log_runway) { + uint64_t max_log_runway = 65536; + ConfSaver conf(g_ceph_context->_conf); + conf.SetVal("bluefs_compact_log_sync", "false"); + conf.SetVal("bluefs_min_log_runway", "32768"); + conf.SetVal("bluefs_max_log_runway", std::to_string(max_log_runway).c_str()); + conf.ApplyChanges(); + + uint64_t size = 1048576 * 128; + TempBdev bdev{size}; + BlueFS fs(g_ceph_context); + ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576)); + uuid_d fsid; + ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false })); + ASSERT_EQ(0, fs.mount()); + ASSERT_EQ(0, fs.maybe_verify_layout({ BlueFS::BDEV_DB, false, false })); + // longer transaction than current runway + std::string longdir(max_log_runway, 'a'); + fs.mkdir(longdir); + { + BlueFS::FileWriter *h; + ASSERT_EQ(0, fs.mkdir("dir")); + ASSERT_EQ(0, fs.open_for_write("dir", "file", &h, false)); + h->append("foo", 3); + h->append("bar", 3); + h->append("baz", 3); + fs.fsync(h); + fs.close_writer(h); + } + fs.umount(true); + fs.mount(); + + std::vector ls; + fs.readdir("dir", &ls); + ASSERT_EQ(ls.front(), "file"); + uint64_t file_size = 0; + utime_t mtime; + fs.stat("dir", "file", &file_size, &mtime); + ASSERT_EQ(file_size, 9); +} + +TEST(BlueFS, test_log_runway_2) { + uint64_t max_log_runway = 65536; + ConfSaver conf(g_ceph_context->_conf); + conf.SetVal("bluefs_compact_log_sync", "false"); + conf.SetVal("bluefs_min_log_runway", "32768"); + conf.SetVal("bluefs_max_log_runway", std::to_string(max_log_runway).c_str()); + conf.ApplyChanges(); + + uint64_t size = 1048576 * 128; + TempBdev bdev{size}; + BlueFS fs(g_ceph_context); + ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576)); + uuid_d fsid; + ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false })); + ASSERT_EQ(0, fs.mount()); + ASSERT_EQ(0, fs.maybe_verify_layout({ BlueFS::BDEV_DB, false, false })); + // longer transaction than current runway + std::string longdir(max_log_runway * 2, 'a'); + std::string longfile(max_log_runway * 2, 'b'); + { + BlueFS::FileWriter *h; + ASSERT_EQ(0, fs.mkdir(longdir)); + ASSERT_EQ(0, fs.open_for_write(longdir, longfile, &h, false)); + h->append("canary", 6); + fs.fsync(h); + fs.close_writer(h); + fs.sync_metadata(true); + } + { + BlueFS::FileWriter *h; + ASSERT_EQ(0, fs.mkdir("dir")); + ASSERT_EQ(0, fs.open_for_write("dir", "file", &h, false)); + h->append("foo", 3); + h->append("bar", 3); + h->append("baz", 3); + fs.fsync(h); + fs.close_writer(h); + } + fs.umount(true); + fs.mount(); + + std::vector ls; + fs.readdir("dir", &ls); + ASSERT_EQ(ls.front(), "file"); + uint64_t file_size = 0; + utime_t mtime; + fs.stat("dir", "file", &file_size, &mtime); + ASSERT_EQ(file_size, 9); + fs.stat(longdir, longfile, &file_size, &mtime); + ASSERT_EQ(file_size, 6); +} + +TEST(BlueFS, test_log_runway_3) { + uint64_t max_log_runway = 65536; + ConfSaver conf(g_ceph_context->_conf); + conf.SetVal("bluefs_alloc_size", "4096"); + conf.SetVal("bluefs_shared_alloc_size", "4096"); + conf.SetVal("bluefs_compact_log_sync", "false"); + conf.SetVal("bluefs_min_log_runway", "32768"); + conf.SetVal("bluefs_max_log_runway", std::to_string(max_log_runway).c_str()); + conf.ApplyChanges(); + + uint64_t size = 1048576 * 128; + TempBdev bdev{size}; + BlueFS fs(g_ceph_context); + ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576)); + uuid_d fsid; + ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false })); + ASSERT_EQ(0, fs.mount()); + ASSERT_EQ(0, fs.maybe_verify_layout({ BlueFS::BDEV_DB, false, false })); + // longer transaction than current runway + for (size_t m = 0; m < 40; m++) { + std::string longdir(max_log_runway + m, 'A' + m); + std::string longfile(max_log_runway + m, 'A' + m); + BlueFS::FileWriter *h; + ASSERT_EQ(0, fs.mkdir(longdir)); + ASSERT_EQ(0, fs.open_for_write(longdir, longfile, &h, false)); + h->append("canary", 6); + fs.fsync(h); + fs.close_writer(h); + fs.sync_metadata(true); + } + { + BlueFS::FileWriter *h; + ASSERT_EQ(0, fs.mkdir("dir")); + ASSERT_EQ(0, fs.open_for_write("dir", "file", &h, false)); + h->append("foo", 3); + h->append("bar", 3); + h->append("baz", 3); + fs.fsync(h); + fs.close_writer(h); + } + fs.umount(true); + fs.mount(); + + std::vector ls; + fs.readdir("dir", &ls); + ASSERT_EQ(ls.front(), "file"); + uint64_t file_size = 0; + utime_t mtime; + fs.stat("dir", "file", &file_size, &mtime); + ASSERT_EQ(file_size, 9); + for (size_t m = 0; m < 40; m++) { + uint64_t file_size = 0; + utime_t mtime; + std::string longdir(max_log_runway + m, 'A' + m); + std::string longfile(max_log_runway + m, 'A' + m); + fs.stat(longdir, longfile, &file_size, &mtime); + ASSERT_EQ(file_size, 6); + } +} + int main(int argc, char **argv) { auto args = argv_to_vec(argc, argv); map defaults = { -- 2.39.5