From 0d3f47a1685ace855672d3ef76ed6b852d40f5d3 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Tue, 24 Nov 2026 23:27:46 +0300 Subject: [PATCH 1/3] Store v1: Report writes refused because the journal can't be trimmed The old store refuses writes with EAGAIN when its journal is full and nothing in it can be flushed, and only logs it with log_level > 5. Clients retry such writes, so an OSD could refuse writes for hours with nothing in its log. Print a line about it at most once in 10 seconds, with the number of objects with unstable writes and the oldest journal entry still in use. An unstable oldest entry waits for its primary OSD to stabilize or roll it back, a stable one is a lost flush. --- src/blockstore/v1/impl.h | 2 ++ src/blockstore/v1/journal.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/blockstore/v1/impl.h b/src/blockstore/v1/impl.h index 160624b9..6fa7b6d5 100644 --- a/src/blockstore/v1/impl.h +++ b/src/blockstore/v1/impl.h @@ -176,6 +176,7 @@ class blockstore_impl_t: public blockstore_i std::set own_ops; std::vector unsynced_big_writes, unsynced_small_writes; int unsynced_big_write_count = 0, unstable_unsynced = 0; + uint64_t journal_full_reported = 0; // Number of deletions which took over the durability of preceding unsynced writes but // aren't journaled themselves yet, see forget_unstable_before_delete() int unsynced_forgotten = 0; @@ -347,6 +348,7 @@ public: // Print diagnostics to stdout void dump_diagnostics(); + void report_journal_full(); // Get diagnostic string for an operation std::string get_op_diag(blockstore_op_t *op); diff --git a/src/blockstore/v1/journal.cpp b/src/blockstore/v1/journal.cpp index 845376b7..b6935234 100644 --- a/src/blockstore/v1/journal.cpp +++ b/src/blockstore/v1/journal.cpp @@ -129,6 +129,7 @@ int blockstore_journal_check_t::check_available(blockstore_op_t *op, int entries if (!bs->flusher->may_advance()) { give_up = true; + bs->report_journal_full(); } else { @@ -330,6 +331,33 @@ uint64_t journal_t::get_trim_pos() return used_start; } +// Clients retry refused writes, so report it at most once in 10 seconds +void blockstore_impl_t::report_journal_full() +{ + timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + if (journal_full_reported && now.tv_sec < journal_full_reported+10) + return; + journal_full_reported = now.tv_sec; + // The oldest entry still in use is what keeps the journal from being trimmed + auto used_it = journal.used_sectors.lower_bound(journal.used_start); + if (used_it == journal.used_sectors.end()) + used_it = journal.used_sectors.begin(); + auto oldest = dirty_db.end(); + if (used_it != journal.used_sectors.end()) + { + for (oldest = dirty_db.begin(); oldest != dirty_db.end() && oldest->second.journal_sector != used_it->first; oldest++) {} + } + bool found = oldest != dirty_db.end(); + printf( + "Journal is full and nothing in it can be flushed, refusing writes with EAGAIN" + " (used_start=%08jx next_free=%08jx, %zu objects with unstable writes, oldest entry %jx:%jx v%ju %s)\n", + journal.used_start, journal.next_free, unstable_writes.size(), + found ? oldest->first.oid.inode : 0, found ? oldest->first.oid.stripe : 0, found ? oldest->first.version : 0, + !found ? "not found" : (IS_STABLE(oldest->second.state) ? "stable" : "unstable") + ); +} + void journal_t::dump_diagnostics() { auto journal_used_it = used_sectors.lower_bound(used_start); -- 2.47.3 From e8e84fe5560f987d8ed195797f0ff387038dea55 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Tue, 24 Nov 2026 23:27:46 +0300 Subject: [PATCH 2/3] Store v1: Test a write over a deletion which is being flushed Before 4ee30fa7 such a write queued the deletion for flushing once more. The stale queue entry hid the flush of the write itself, the write kept the journal from being trimmed, and once the journal was full every write failed with EAGAIN until a restart. --- src/test/test_blockstore_v1.cpp | 131 ++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/src/test/test_blockstore_v1.cpp b/src/test/test_blockstore_v1.cpp index 8969ed05..6461146b 100644 --- a/src/test/test_blockstore_v1.cpp +++ b/src/test/test_blockstore_v1.cpp @@ -3357,6 +3357,136 @@ static void test_read_error_is_not_edom(const char *csum_block_size) free(read_op.buf); } +// A write over a deletion that the flusher is flushing used to queue the deletion once more. +// That stale queue entry hid the flush of the new write, the write pinned the journal for good, +// and once the journal wrapped every write was refused with EAGAIN until a restart +static void test_write_over_flushing_delete_keeps_journal_free() +{ + printf("\n-- test_write_over_flushing_delete_keeps_journal_free\n"); + + bs_test_t test; + test.default_cfg(); + // 1 MB journal, so that a pinned entry blocks it after a few hundred writes + test.config["journal_offset"] = std::to_string(31*1024*1024); + test.config["log_level"] = "0"; + // One flusher, so that nothing else picks the deletion from the queue while it is busy + test.config["max_flusher_count"] = "1"; + test.init(); + printf("blockstore initialized\n"); + + object_id oid = { .inode = 1, .stripe = 0 }; + const uint32_t bs_size = 128*1024; + uint8_t *buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, bs_size); + memset(buf, 0xAA, bs_size); + + printf("write v1 (big) and flush it, so that the deletion has metadata to clear\n"); + blockstore_op_t op; + op.opcode = BS_OP_WRITE_STABLE; + op.oid = oid; + op.version = 1; + op.offset = 0; + op.len = bs_size; + op.buf = buf; + test.exec_op(&op); + assert(op.retval == (int)op.len); + test.force_compaction(); + assert(!test.find_dirty_entry(oid, 1)); + + printf("delete v2\n"); + op.opcode = BS_OP_DELETE; + op.version = 2; + op.len = 0; + op.buf = NULL; + test.exec_op(&op); + assert(op.retval == 0); + + // Hold the flusher's metadata write of the deletion, so that it stays in the middle of the flush + const uint64_t journal_offset = parse_size(test.config["journal_offset"]); + ring_data_t *held = NULL; + test.sqe_handler = [&](io_uring_sqe *sqe) + { + if (!held && sqe->fd == MOCK_DATA_FD && sqe->off < journal_offset && + (sqe->opcode == IORING_OP_WRITEV || sqe->opcode == IORING_OP_WRITE)) + { + bool ok = test.data_disk->submit(sqe); + assert(ok); + held = (ring_data_t*)sqe->user_data; + return true; + } + return false; + }; + test.flusher()->request_trim(); + for (int i = 0; i < 100 && !held; i++) + test.ringloop->loop(); + assert(held); + + printf("write v1 (small) over the deletion while it is being flushed\n"); + blockstore_op_t wr; + bool wr_done = false; + wr.opcode = BS_OP_WRITE_STABLE; + wr.oid = oid; + wr.version = 1; + wr.offset = 0; + wr.len = 4096; + wr.buf = buf; + wr.callback = [&](blockstore_op_t *op) { wr_done = true; }; + test.bs->enqueue_op(&wr); + for (int i = 0; i < 20 && !wr_done; i++) + test.ringloop->loop(); + assert(!wr_done); + + // Hold the journal trim that follows the flush, so that the write over the deletion + // becomes stable before the flusher looks at its queue again + printf("finish the flush of the deletion, holding the journal trim after it\n"); + ring_data_t *held_trim = NULL; + test.sqe_handler = [&](io_uring_sqe *sqe) + { + if (!held_trim && sqe->fd == MOCK_DATA_FD && sqe->off == journal_offset && + (sqe->opcode == IORING_OP_WRITEV || sqe->opcode == IORING_OP_WRITE)) + { + bool ok = test.data_disk->submit(sqe); + assert(ok); + held_trim = (ring_data_t*)sqe->user_data; + return true; + } + return false; + }; + test.ringloop->mark_completed(held); + for (int i = 0; i < 1000 && !wr_done; i++) + test.ringloop->loop(); + assert(wr_done && wr.retval == (int)wr.len && wr.version == 1); + printf("journal trim %s\n", held_trim ? "was held" : "did not happen"); + test.sqe_handler = NULL; + if (held_trim) + test.ringloop->mark_completed(held_trim); + while (test.flusher()->is_active()) + test.ringloop->loop(); + test.flusher()->release_trim(); + + printf("write other objects until the journal wraps several times\n"); + int refused = 0; + for (int i = 0; i < 2000; i++) + { + op.opcode = BS_OP_WRITE_STABLE; + op.oid = { .inode = 2, .stripe = (uint64_t)(i % 16) * bs_size }; + op.version = 1 + i / 16; + op.offset = 0; + op.len = 4096; + op.buf = buf; + test.exec_op(&op); + if (op.retval == -EAGAIN) + refused++; + else + assert(op.retval == (int)op.len); + } + printf("%d writes refused with EAGAIN, v1 over the deletion is %s\n", refused, + test.find_dirty_entry(oid, 1) ? "still not flushed" : "flushed"); + assert(!refused); + assert(!test.find_dirty_entry(oid, 1)); + + free(buf); +} + int main(int narg, char *args[]) { test_preserve_corruption(); @@ -3400,5 +3530,6 @@ int main(int narg, char *args[]) test_small_write_waits_for_its_own_big_write_imm(); test_writes_over_delete_released_imm(); test_tombstone_unsupported(); + test_write_over_flushing_delete_keeps_journal_free(); return 0; } -- 2.47.3 From 0089da9e19c891007419fb32464d13167810e15d Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Wed, 25 Nov 2026 05:56:26 +0300 Subject: [PATCH 3/3] Store v1: Fail the test of a write over a flushing deletion if its race isn't set up Without the journal trim held after the flush of the deletion, the flusher drops the stale queue entry before the write over the deletion becomes stable, and the test passes without testing anything. --- src/test/test_blockstore_v1.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/test_blockstore_v1.cpp b/src/test/test_blockstore_v1.cpp index 6461146b..751303a4 100644 --- a/src/test/test_blockstore_v1.cpp +++ b/src/test/test_blockstore_v1.cpp @@ -3455,10 +3455,10 @@ static void test_write_over_flushing_delete_keeps_journal_free() for (int i = 0; i < 1000 && !wr_done; i++) test.ringloop->loop(); assert(wr_done && wr.retval == (int)wr.len && wr.version == 1); - printf("journal trim %s\n", held_trim ? "was held" : "did not happen"); + // Without it the flusher drops the stale entry before the write is stable, and nothing is tested + assert(held_trim); test.sqe_handler = NULL; - if (held_trim) - test.ringloop->mark_completed(held_trim); + test.ringloop->mark_completed(held_trim); while (test.flusher()->is_active()) test.ringloop->loop(); test.flusher()->release_trim(); -- 2.47.3