From: Varada Kari Date: Fri, 22 Jul 2016 11:12:38 +0000 (+0530) Subject: os/bluestore/BlueFS: unit tests for log compaction X-Git-Tag: ses5-milestone5~93^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b8349af7e7cde497e17c64d8eb255f1664df00fd;p=ceph.git os/bluestore/BlueFS: unit tests for log compaction Signed-off-by: Varada Kari --- diff --git a/src/test/objectstore/test_bluefs.cc b/src/test/objectstore/test_bluefs.cc index 7ffdfb8dee94..6ceb6fef5cc0 100644 --- a/src/test/objectstore/test_bluefs.cc +++ b/src/test/objectstore/test_bluefs.cc @@ -167,7 +167,6 @@ void write_data(BlueFS &fs, uint64_t rationed_bytes) h->append(bl); r = fs.fsync(h); if (r < 0) { - std::cout << " rationed_bytes: " << rationed_bytes << " written_bytes: " << written_bytes << std::endl; fs.close_writer(h); break; } @@ -175,7 +174,6 @@ void write_data(BlueFS &fs, uint64_t rationed_bytes) fs.close_writer(h); j++; if ((rationed_bytes - written_bytes) <= g_conf->bluefs_alloc_size) { - std::cout << " rationed_bytes: " << rationed_bytes << " written_bytes: " << written_bytes << std::endl; break; } } @@ -216,7 +214,6 @@ void write_single_file(BlueFS &fs, uint64_t rationed_bytes) h->append(bl); r = fs.fsync(h); if (r < 0) { - std::cout << " rationed_bytes: " << rationed_bytes << " written_bytes: " << written_bytes << std::endl; fs.close_writer(h); break; } @@ -224,7 +221,6 @@ void write_single_file(BlueFS &fs, uint64_t rationed_bytes) fs.close_writer(h); j++; if ((rationed_bytes - written_bytes) <= g_conf->bluefs_alloc_size) { - std::cout << " rationed_bytes: " << rationed_bytes << " written_bytes: " << written_bytes << std::endl; break; } } @@ -357,6 +353,228 @@ TEST(BlueFS, test_flush_3) { rm_temp_bdev(fn); } +TEST(BlueFS, test_simple_compaction_sync) { + g_ceph_context->_conf->set_val( + "bluefs_compact_log_sync", + "true"); + uint64_t size = 1048476 * 128; + string fn = get_temp_bdev(size); + + BlueFS fs; + ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn)); + fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576); + uuid_d fsid; + ASSERT_EQ(0, fs.mkfs(fsid)); + ASSERT_EQ(0, fs.mount()); + { + BlueFS::FileWriter *h; + for (int i=0; i<10; i++) { + string dir = "dir."; + dir.append(to_string(i)); + ASSERT_EQ(0, fs.mkdir(dir)); + for (int j=0; j<10; j++) { + string file = "file."; + file.append(to_string(j)); + ASSERT_EQ(0, fs.open_for_write(dir, file, &h, false)); + bufferlist bl; + char *buf = gen_buffer(4096); + bufferptr bp = buffer::claim_char(4096, buf); + bl.push_back(bp); + h->append(bl); + fs.fsync(h); + fs.close_writer(h); + } + } + } + // Don't remove all + { + for (int i=0; i<10; i+=2) { + string dir = "dir."; + dir.append(to_string(i)); + for (int j=0; j<10; j+=2) { + string file = "file."; + file.append(to_string(j)); + fs.unlink(dir, file); + fs.flush_log(); + } + fs.rmdir(dir); + fs.flush_log(); + } + } + fs.compact_log(); + fs.umount(); + rm_temp_bdev(fn); +} + +TEST(BlueFS, test_simple_compaction_async) { + g_ceph_context->_conf->set_val( + "bluefs_compact_log_sync", + "false"); + uint64_t size = 1048476 * 128; + string fn = get_temp_bdev(size); + + BlueFS fs; + ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn)); + fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576); + uuid_d fsid; + ASSERT_EQ(0, fs.mkfs(fsid)); + ASSERT_EQ(0, fs.mount()); + { + BlueFS::FileWriter *h; + for (int i=0; i<10; i++) { + string dir = "dir."; + dir.append(to_string(i)); + ASSERT_EQ(0, fs.mkdir(dir)); + for (int j=0; j<10; j++) { + string file = "file."; + file.append(to_string(j)); + ASSERT_EQ(0, fs.open_for_write(dir, file, &h, false)); + bufferlist bl; + char *buf = gen_buffer(4096); + bufferptr bp = buffer::claim_char(4096, buf); + bl.push_back(bp); + h->append(bl); + fs.fsync(h); + fs.close_writer(h); + } + } + } + // Don't remove all + { + for (int i=0; i<10; i+=2) { + string dir = "dir."; + dir.append(to_string(i)); + for (int j=0; j<10; j+=2) { + string file = "file."; + file.append(to_string(j)); + fs.unlink(dir, file); + fs.flush_log(); + } + fs.rmdir(dir); + fs.flush_log(); + } + } + fs.compact_log(); + fs.umount(); + rm_temp_bdev(fn); +} + +TEST(BlueFS, test_compaction_sync) { + uint64_t size = 1048476 * 128; + string fn = get_temp_bdev(size); + g_ceph_context->_conf->set_val( + "bluefs_alloc_size", + "65536"); + g_ceph_context->_conf->set_val( + "bluefs_compact_log_sync", + "true"); + + BlueFS fs; + ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn)); + fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576); + uuid_d fsid; + ASSERT_EQ(0, fs.mkfs(fsid)); + ASSERT_EQ(0, fs.mount()); + { + std::vector write_threads; + uint64_t effective_size = size - (32 * 1048576); // leaving the last 32 MB for log compaction + uint64_t per_thread_bytes = (effective_size/(NUM_WRITERS)); + for (int i=0; i sync_threads; + for (int i=0; i_conf->set_val( + "bluefs_alloc_size", + "65536"); + g_ceph_context->_conf->set_val( + "bluefs_compact_log_sync", + "false"); + + BlueFS fs; + ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn)); + fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576); + uuid_d fsid; + ASSERT_EQ(0, fs.mkfs(fsid)); + ASSERT_EQ(0, fs.mount()); + { + std::vector write_threads; + uint64_t effective_size = size - (32 * 1048576); // leaving the last 32 MB for log compaction + uint64_t per_thread_bytes = (effective_size/(NUM_WRITERS)); + for (int i=0; i sync_threads; + for (int i=0; i_conf->set_val( + "bluefs_alloc_size", + "65536"); + g_ceph_context->_conf->set_val( + "bluefs_compact_log_sync", + "false"); + + BlueFS fs; + ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn)); + fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576); + uuid_d fsid; + ASSERT_EQ(0, fs.mkfs(fsid)); + ASSERT_EQ(0, fs.mount()); + { + std::vector write_threads; + uint64_t effective_size = size - (32 * 1048576); // leaving the last 32 MB for log compaction + uint64_t per_thread_bytes = (effective_size/(NUM_WRITERS)); + for (int i=0; i sync_threads; + for (int i=0; i args;