From b847e6337b4ee79e81174b457f87f6b409d6061a Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Mon, 23 Nov 2026 13:09:42 +0300 Subject: [PATCH 1/4] osd: Finish a read with -EPIPE when its PG stops instead of marking copies corrupted A read whose PG stopped while a subop was in flight still judged the copies by the object state when a subop failed. A copy that a repeat delete had just removed answers -ENOENT, the delete itself was cancelled by the stop before the state was updated, and no operation is queued on the object any more, so the -ENOENT was taken for corruption: the object was marked INCOMPLETE and the read failed with -EIO. Peering rebuilds the object states anyway, so finish such a read with -EPIPE like any other operation of a stopped PG; the client repeats it after peering. --- src/osd/osd_primary.cpp | 7 ++++++ src/test/osd_test.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/osd/osd_primary.cpp b/src/osd/osd_primary.cpp index be1b3bee..22136c22 100644 --- a/src/osd/osd_primary.cpp +++ b/src/osd/osd_primary.cpp @@ -409,6 +409,13 @@ resume_1: resume_2: if (op_data->errors > 0) { + if (pg && !(pg->state & PG_ACTIVE)) + { + // The PG stopped under the read: peering rebuilds the object states, so + // don't judge the copies by the stale ones. The client repeats the read + finish_read_op(cur_op, -EPIPE); + return; + } if (pg && (op_data->errcode == -EIO || op_data->errcode == -EDOM)) { // A raw -ENOENT behind the -EIO means a copy was removed while the read diff --git a/src/test/osd_test.cpp b/src/test/osd_test.cpp index e0db38fa..5d18962d 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -3453,6 +3453,53 @@ void test_read_enoent_without_racing_op_marks_corrupted() printf("test_read_enoent_without_racing_op_marks_corrupted passed\n"); } +// The same -ENOENT, but the PG stops while the read is in flight. The object +// state may be stale then (a repeat delete reached the copy and the stop +// cancelled it), and peering rebuilds it anyway: the read ends with -EPIPE like +// any other operation of a stopped PG, and no copy is marked corrupted +void test_read_enoent_in_stopped_pg_returns_epipe() +{ + printf("test_read_enoent_in_stopped_pg_returns_epipe\n"); + + osd_test_fixture_t f; + f.configure_replicated_pool(/*pool_id*/ 1, /*pg_size*/ 2, /*pg_minsize*/ 1, /*pg_count*/ 1, + { { 1, 2 } }); + f.start(json11::Json::object { + { "osd_num", 1 }, + { "etcd_address", "127.0.0.1:2379" }, + { "immediate_commit", "all" }, + { "block_size", 131072 }, + { "bitmap_granularity", 4096 }, + { "no_recovery", true }, + }); + + f.connect_peer(2); + + inode_t inode = INODE_WITH_POOL(1, 1); + object_id oid = { .inode = inode, .stripe = 0 }; + f.reply_local_list({ { oid, 1 } }, 1); + f.reply_peer_list(2, {}, 0); + f.pump(); + assert(f.pg(1, 1).state == (PG_ACTIVE|PG_HAS_DEGRADED)); + + int read_retval = 0; + auto *read = make_self_rw(OSD_OP_READ, inode, 0, 4096); + read->callback = [&read_retval](osd_op_t *op) { read_retval = op->reply.hdr.retval; }; + f.exec(read); + auto *local_read = f.bs->take(BS_OP_READ); + + f.repeer_pgs(2); + assert(!(f.pg(1, 1).state & PG_ACTIVE)); + local_read->retval = -ENOENT; + local_read->callback(local_read); + + assert(read_retval == -EPIPE); + assert(!(f.pg(1, 1).state & PG_HAS_INCOMPLETE)); + + delete read; + printf("test_read_enoent_in_stopped_pg_returns_epipe passed\n"); +} + // Peering must not forget an outdated copy just because its OSD already holds // the object at another role. A stale piece kept by a set member after a set // change looks, by OSD number alone, like a copy that the target set already @@ -4689,6 +4736,7 @@ int main(int narg, char *args[]) test_repeated_delete_is_noop(); test_read_enoent_waits_behind_running_delete(); test_read_enoent_without_racing_op_marks_corrupted(); + test_read_enoent_in_stopped_pg_returns_epipe(); test_peering_outdated_copy_other_role(); test_pg_epoch_base_is_reported_epoch(); test_pg_epoch_bump_above_reported_epoch(); -- 2.47.3 From 4819817d029488d68033b7a678b9c5bdd05ef40a Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Mon, 23 Nov 2026 22:22:28 +0300 Subject: [PATCH 2/4] osd_test: Drop the PG_HAS_INCOMPLETE assert that peering always clears Once the read finishes, the PG restarts peering and resets its state, so the assert held even without the fix. The -EPIPE assert is what catches a read that judged the copies. --- src/test/osd_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/osd_test.cpp b/src/test/osd_test.cpp index 5d18962d..8ac067bf 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -3456,7 +3456,7 @@ void test_read_enoent_without_racing_op_marks_corrupted() // The same -ENOENT, but the PG stops while the read is in flight. The object // state may be stale then (a repeat delete reached the copy and the stop // cancelled it), and peering rebuilds it anyway: the read ends with -EPIPE like -// any other operation of a stopped PG, and no copy is marked corrupted +// any other operation of a stopped PG void test_read_enoent_in_stopped_pg_returns_epipe() { printf("test_read_enoent_in_stopped_pg_returns_epipe\n"); @@ -3494,7 +3494,6 @@ void test_read_enoent_in_stopped_pg_returns_epipe() local_read->callback(local_read); assert(read_retval == -EPIPE); - assert(!(f.pg(1, 1).state & PG_HAS_INCOMPLETE)); delete read; printf("test_read_enoent_in_stopped_pg_returns_epipe passed\n"); -- 2.47.3 From 9a5dd54f99c0693a9c342ca867a2f5ac81ad85b0 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Mon, 23 Nov 2026 22:25:00 +0300 Subject: [PATCH 3/4] osd: Finish a chained read with -EPIPE when its PG stops A read through a snapshot chain still ran check_corrupted_chained() and retried when a subop failed after its PG stopped. A copy removed by a repeat delete that the stop cancelled answered -ENOENT, the copy was marked corrupted with the stale object state, and the retry aborted the OSD on assert(read_target != 0) in collect_bitmap_requests(), since the object had no copy left. End such a read with -EPIPE, like a plain read. --- src/osd/osd_primary_chain.cpp | 2 ++ src/test/osd_test.cpp | 56 +++++++++++++++++++++++++++++++++++ src/test/osd_test_fixture.h | 10 ++++++- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/osd/osd_primary_chain.cpp b/src/osd/osd_primary_chain.cpp index 3ab44e72..4131c0bf 100644 --- a/src/osd/osd_primary_chain.cpp +++ b/src/osd/osd_primary_chain.cpp @@ -53,6 +53,8 @@ resume_4: // FIXME: Check fact_ver mismatch here too if (op_data->errors > 0) { + if (pg && !(pg->state & PG_ACTIVE)) + op_data->errcode = -EPIPE; // the PG stopped: don't judge the copies, as in continue_primary_read() if (pg && (op_data->errcode == -EIO || op_data->errcode == -EDOM)) { // Handle corrupted reads and retry... diff --git a/src/test/osd_test.cpp b/src/test/osd_test.cpp index 8ac067bf..7dbdc399 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -3499,6 +3499,61 @@ void test_read_enoent_in_stopped_pg_returns_epipe() printf("test_read_enoent_in_stopped_pg_returns_epipe passed\n"); } +// The same for a read through a snapshot chain: the parent layer's copy answers +// -ENOENT after the PG stopped, and the read ends with -EPIPE +void test_chained_read_in_stopped_pg_returns_epipe() +{ + printf("test_chained_read_in_stopped_pg_returns_epipe\n"); + + osd_test_fixture_t f; + f.configure_replicated_pool(/*pool_id*/ 1, /*pg_size*/ 2, /*pg_minsize*/ 1, /*pg_count*/ 1, + { { 1, 2 } }); + f.st_cli->set("/vitastor/config/inode/1/2", json11::Json::object { + { "name", "child" }, + { "parent_id", 3 }, + }, 1); + f.st_cli->set("/vitastor/config/inode/1/3", json11::Json::object { + { "name", "parent" }, + }, 1); + f.start(json11::Json::object { + { "osd_num", 1 }, + { "etcd_address", "127.0.0.1:2379" }, + { "immediate_commit", "all" }, + { "block_size", 131072 }, + { "bitmap_granularity", 4096 }, + { "no_recovery", true }, + }); + f.connect_peer(2); + + inode_t child_inode = INODE_WITH_POOL(1, 2); + object_id parent_oid = { .inode = INODE_WITH_POOL(1, 3), .stripe = 0 }; + // The parent object is only on OSD 1; the child has no data of its own + f.reply_local_list({ { parent_oid, 1 } }, 1); + f.reply_peer_list(2, {}, 0); + f.pump(); + assert(f.pg(1, 1).state == (PG_ACTIVE|PG_HAS_DEGRADED)); + f.bs->bitmaps[parent_oid] = std::vector(4, 0xff); + + int read_retval = 0; + auto *read = make_self_rw(OSD_OP_READ, child_inode, 0, 4096); + // The inode revision the client saw: that makes it a chained read + read->req.rw.meta_revision = 1; + read->callback = [&read_retval](osd_op_t *op) { read_retval = op->reply.hdr.retval; }; + f.exec(read); + auto *parent_read = f.bs->take(BS_OP_READ); + assert(parent_read->oid == parent_oid); + + f.repeer_pgs(2); + assert(!(f.pg(1, 1).state & PG_ACTIVE)); + parent_read->retval = -ENOENT; + parent_read->callback(parent_read); + + assert(read_retval == -EPIPE); + + delete read; + printf("test_chained_read_in_stopped_pg_returns_epipe passed\n"); +} + // Peering must not forget an outdated copy just because its OSD already holds // the object at another role. A stale piece kept by a set member after a set // change looks, by OSD number alone, like a copy that the target set already @@ -4736,6 +4791,7 @@ int main(int narg, char *args[]) test_read_enoent_waits_behind_running_delete(); test_read_enoent_without_racing_op_marks_corrupted(); test_read_enoent_in_stopped_pg_returns_epipe(); + test_chained_read_in_stopped_pg_returns_epipe(); test_peering_outdated_copy_other_role(); test_pg_epoch_base_is_reported_epoch(); test_pg_epoch_bump_above_reported_epoch(); diff --git a/src/test/osd_test_fixture.h b/src/test/osd_test_fixture.h index 39778383..11e4888e 100644 --- a/src/test/osd_test_fixture.h +++ b/src/test/osd_test_fixture.h @@ -45,10 +45,18 @@ public: // Local bitmap reads go through read_bitmap() synchronously; record them // so tests can assert which chain elements were asked std::vector read_bitmap_calls; + // What read_bitmap() returns for an object; others are absent + std::map> bitmaps; int read_bitmap(object_id oid, uint64_t target_version, void *bitmap, uint64_t *result_version) override { read_bitmap_calls.push_back(oid); - return -ENOENT; + auto it = bitmaps.find(oid); + if (it == bitmaps.end()) + return -ENOENT; + memcpy(bitmap, it->second.data(), it->second.size()); + if (result_version) + *result_version = 1; + return 0; } // Pop the first queued op with the given opcode. Aborts if none. -- 2.47.3 From 4891aa2564f841321efd57f0184e3b75890f2e79 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Tue, 24 Nov 2026 00:00:45 +0300 Subject: [PATCH 4/4] osd: Don't copy into a NULL bitmap in the test fixture's read_bitmap() Scrub asks read_bitmap() only for the version and passes no bitmap. --- src/test/osd_test_fixture.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/osd_test_fixture.h b/src/test/osd_test_fixture.h index 11e4888e..bb50695c 100644 --- a/src/test/osd_test_fixture.h +++ b/src/test/osd_test_fixture.h @@ -53,7 +53,8 @@ public: auto it = bitmaps.find(oid); if (it == bitmaps.end()) return -ENOENT; - memcpy(bitmap, it->second.data(), it->second.size()); + if (bitmap) + memcpy(bitmap, it->second.data(), it->second.size()); if (result_version) *result_version = 1; return 0; -- 2.47.3