From fa9af50082b9ed4fe76c249c3f4762aa5cb10593 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Tue, 1 Dec 2026 21:55:50 +0300 Subject: [PATCH] osd: Put the current OSD set into the PG history when a peering flush reports the epoch Since the peering flush reports a new epoch itself, to get the holders of the versions it stabilizes into the history first, the first degraded write of that epoch finds the epoch already reported and no longer adds the current OSD set to the history. If the primary then stabilizes its own part of that write and is lost before the others stabilize theirs, the PG can activate without it and roll the other parts back. The primary comes back with a lone stable part, and the object stays incomplete. Report the epoch from the flush with report_epoch(), as writes do, so a degraded PG's current OSD set goes into the history with it. This is reachable in EC pools whose pg_minsize equals the number of data chunks, e.g. N+1 with the default pg_minsize. --- src/osd/osd_flush.cpp | 8 ++------ src/test/osd_test.cpp | 36 +++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/osd/osd_flush.cpp b/src/osd/osd_flush.cpp index 917b5e05..2c22ccdd 100644 --- a/src/osd/osd_flush.cpp +++ b/src/osd/osd_flush.cpp @@ -56,12 +56,8 @@ void osd_t::submit_pg_flush_ops(pg_t & pg) if (pg.epoch > pg.reported_epoch) { // Flushes wait until the history with the holders of their versions is reported - if (pg.epoch > pg.reporting_epoch) - { - this->pg_state_dirty.insert({ .pool_id = pg.pool_id, .pg_num = pg.pg_num }); - pg.history_changed = true; - report_pg_states(); - } + // Report it like a write does, with the current OSD set: the first write of this epoch won't + report_epoch(pg); return; } submit_flush_batch(pg); diff --git a/src/test/osd_test.cpp b/src/test/osd_test.cpp index 3921c6ab..5b13f919 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -4817,8 +4817,8 @@ void test_peering_flush_misplaced_primary_lost(bool on_osd2) } // Version 2 of object A is unstable on OSDs 1 and 2 of an EC 2+1 PG, so the peering flush batch waits until -// the history with its holders is reported. OSD 3 drops out before the report lands: the batch must be -// dropped without sending anything, and the PG must peer again +// the history with its holders and the current OSD set is reported. OSD 3 drops out before the report lands: +// the batch must be dropped without sending anything, and the PG must peer again void test_peering_flush_waiting_batch_repeer() { printf("test_peering_flush_waiting_batch_repeer\n"); @@ -4837,7 +4837,7 @@ void test_peering_flush_waiting_batch_repeer() f.pump(); assert(pg.state == (PG_ACTIVE|PG_HAS_DEGRADED|PG_HAS_UNCLEAN)); assert(pg.flush_batch && !pg.flush_batch->flush_ops); - assert(pg.target_history == std::vector>({ { 1, 2 } })); + assert(pg.target_history == std::vector>({ { 1, 2 }, { 1, 2, 3 } })); assert(f.st_cli->queue.size() == 1); f.repeer_pgs(3); @@ -4891,10 +4891,12 @@ void test_peering_flush_replicated_history() // The same for a client write to a degraded PG of pg_minsize OSDs: OSD 1 writes version 2 of object A to them // all, stabilizes its own part and loses its peers before the others stabilize theirs. The degraded OSD set is -// in the PG history before the write -void test_degraded_write_primary_lost(ec_scheme_t ec) +// in the PG history before the write. With , the peering first rolls back version 2 of object B on OSD 1 +// alone, and that flush reports the epoch of the write +void test_degraded_write_primary_lost(ec_scheme_t ec, bool flush) { - printf("test_degraded_write_primary_lost[EC %d+%d, pg_minsize %d]\n", ec.data, ec.parity, ec.pg_minsize); + const char *desc = flush ? ", after a peering flush" : ""; + printf("test_degraded_write_primary_lost[EC %d+%d, pg_minsize %d%s]\n", ec.data, ec.parity, ec.pg_minsize, desc); inode_t ino = INODE_WITH_POOL(1, 1); int pg_size = ec.data+ec.parity; @@ -4910,11 +4912,21 @@ void test_degraded_write_primary_lost(ec_scheme_t ec) peers.push_back(osd); for (auto p: peers) f.connect_peer(p); + uint64_t b = 131072*ec.data; for (auto p: peers) - f.reply_peer_list(p, { { { ino, p-1 }, 1 } }, 1); - f.reply_local_list({ { { ino, 0 }, 1 } }, 1); + f.reply_peer_list(p, { { { ino, p-1 }, 1 }, { { ino, b+p-1 }, 1 } }, 2); + std::vector local = { { { ino, 0 }, 1 }, { { ino, b }, 1 } }; + if (flush) + local.push_back({ { ino, b }, 2 }); + f.reply_local_list(local, 2); f.pump(); assert((f.pg(1, 1).state & (PG_ACTIVE|PG_DEGRADED)) == (PG_ACTIVE|PG_DEGRADED)); + if (flush) + { + bs_complete(f.bs->take(BS_OP_ROLLBACK), 0); + f.pump(); + assert(f.pg(1, 1).reported_epoch == f.pg(1, 1).epoch); + } auto *wr = make_write_op(ino, 0, 131072*ec.data, 0xab); int retval = 0; wr->callback = [&](osd_op_t *op) { retval = op->reply.hdr.retval; }; @@ -4949,7 +4961,7 @@ void test_degraded_write_primary_lost(ec_scheme_t ec) assert(complete); assert(active_without || ec.pg_minsize == ec.data); - printf("test_degraded_write_primary_lost[EC %d+%d, pg_minsize %d] passed\n", ec.data, ec.parity, ec.pg_minsize); + printf("test_degraded_write_primary_lost[EC %d+%d, pg_minsize %d%s] passed\n", ec.data, ec.parity, ec.pg_minsize, desc); } // A dispatched SYNC holds its stabilize snapshot; a delete of a covered object must @@ -5709,8 +5721,10 @@ int main(int narg, char *args[]) test_peering_flush_primary_lost({ 3, 2, 4 }, 3); test_peering_flush_primary_lost({ 3, 2, 4 }, 4); test_peering_flush_primary_lost({ 3, 2, 4 }, 5); - test_degraded_write_primary_lost({ 2, 1, 2 }); - test_degraded_write_primary_lost({ 3, 2, 4 }); + test_degraded_write_primary_lost({ 2, 1, 2 }, false); + test_degraded_write_primary_lost({ 3, 2, 4 }, false); + test_degraded_write_primary_lost({ 2, 1, 2 }, true); + test_degraded_write_primary_lost({ 3, 1, 3 }, true); test_peering_flush_then_holder_lost({ 2, 1, 2 }, 2, 2); test_peering_flush_then_holder_lost({ 2, 1, 2 }, 3, 2); test_peering_flush_then_holder_lost({ 3, 2, 4 }, 4, 3); -- 2.47.3