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/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 e0db38fa..7dbdc399 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -3453,6 +3453,107 @@ 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 +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); + + delete read; + 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 @@ -4689,6 +4790,8 @@ 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_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..bb50695c 100644 --- a/src/test/osd_test_fixture.h +++ b/src/test/osd_test_fixture.h @@ -45,10 +45,19 @@ 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; + if (bitmap) + 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.