}
}
+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<std::string> 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<std::string> 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<std::string> 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<string,string> defaults = {