Skip to content

Commit

Permalink
os/bluestore/bluefs: Fix sync compaction
Browse files Browse the repository at this point in the history
Fixes problem with sync compaction (_rewrite_log_and_layout_sync).
There was a problem with not updating log_seq after compacting log.

It cause to stop _replay log right after first transaction.

... 20 bluefs _replay 0x0:  op_dir_create sharding
... 20 bluefs _replay 0x0:  op_dir_link  sharding/def to 21
... 20 bluefs _replay 0x0:  op_jump_seq 1025
... 10 bluefs _read h 0x555557c46400 0x1000~1000 from file(ino 1 size 0x1000 mtime 0.000000 allocated 410000 alloc_commit 410000 extents [1:0x1540000~410000])
... 20 bluefs _read left 0xff000 len 0x1000
... 20 bluefs _read got 4096
... 10 bluefs _replay 0x1000: stop: seq 1025 != expected 1026

This is a product of bluefs fine grain locks refactor.

Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
  • Loading branch information
aclamk committed Mar 6, 2022
1 parent f435d5d commit 2f8e370
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/os/bluestore/BlueFS.cc
Expand Up @@ -2507,6 +2507,9 @@ void BlueFS::_rewrite_log_and_layout_sync_LNF_LD(bool allocate_with_fallback,
}
#endif
_flush_bdev();
++log.seq_live;
dirty.seq_live = log.seq_live;
log.t.seq = log.seq_live;

super.memorized_layout = layout;
super.log_fnode = log_file->fnode;
Expand Down
34 changes: 18 additions & 16 deletions src/test/objectstore/test_bluefs.cc
Expand Up @@ -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));
Expand All @@ -644,14 +647,12 @@ TEST(BlueFS, test_compaction_sync) {
fs.compact_log();

{
string dir = "dir.after_compact_test";
ASSERT_EQ(0, fs.mkdir(dir));
string file = "file.after_compact_test";
ASSERT_EQ(0, fs.mkdir(canary_dir));
BlueFS::FileWriter *h;
ASSERT_EQ(0, fs.open_for_write(dir, file, &h, false));
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("some data", 9);
h->append(canary_data, strlen(canary_data));
int r = fs.fsync(h);
ASSERT_EQ(r, 0);
}
Expand All @@ -661,12 +662,12 @@ TEST(BlueFS, test_compaction_sync) {
fs.mount();
{
BlueFS::FileReader *h;
ASSERT_EQ(0, fs.open_for_read("dir.after_compact_test", "file.after_compact_test", &h));
ASSERT_EQ(0, fs.open_for_read(canary_dir, canary_file, &h));
ASSERT_NE(nullptr, h);
bufferlist bl;
ASSERT_EQ(9, fs.read(h, 0, 1024, &bl, NULL));
ASSERT_EQ(strlen(canary_data), fs.read(h, 0, 1024, &bl, NULL));
std::cout << bl.c_str() << std::endl;
ASSERT_EQ(0, strncmp("some data", bl.c_str(), 9));
ASSERT_EQ(0, strncmp(canary_data, bl.c_str(), strlen(canary_data)));
delete h;
}
fs.umount();
Expand All @@ -681,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));
Expand All @@ -707,14 +711,12 @@ TEST(BlueFS, test_compaction_async) {
fs.compact_log();

{
string dir = "dir.after_compact_test";
ASSERT_EQ(0, fs.mkdir(dir));
string file = "file.after_compact_test";
ASSERT_EQ(0, fs.mkdir(canary_dir));
BlueFS::FileWriter *h;
ASSERT_EQ(0, fs.open_for_write(dir, file, &h, false));
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("some data", 9);
h->append(canary_data, strlen(canary_data));
int r = fs.fsync(h);
ASSERT_EQ(r, 0);
}
Expand All @@ -724,12 +726,12 @@ TEST(BlueFS, test_compaction_async) {
fs.mount();
{
BlueFS::FileReader *h;
ASSERT_EQ(0, fs.open_for_read("dir.after_compact_test", "file.after_compact_test", &h));
ASSERT_EQ(0, fs.open_for_read(canary_dir, canary_file, &h));
ASSERT_NE(nullptr, h);
bufferlist bl;
ASSERT_EQ(9, fs.read(h, 0, 1024, &bl, NULL));
ASSERT_EQ(strlen(canary_data), fs.read(h, 0, 1024, &bl, NULL));
std::cout << bl.c_str() << std::endl;
ASSERT_EQ(0, strncmp("some data", bl.c_str(), 9));
ASSERT_EQ(0, strncmp(canary_data, bl.c_str(), strlen(canary_data)));
delete h;
}
fs.umount();
Expand Down

0 comments on commit 2f8e370

Please sign in to comment.