diff --git a/src/osd/osd_primary_chain.cpp b/src/osd/osd_primary_chain.cpp index 3ab44e72..f6fe5fa8 100644 --- a/src/osd/osd_primary_chain.cpp +++ b/src/osd/osd_primary_chain.cpp @@ -441,10 +441,12 @@ int osd_t::submit_chained_read_requests(pg_t *pg, osd_op_t *cur_op) stripes[role].read_start = stripes[role].req_start; stripes[role].read_end = stripes[role].req_end; } - osd_num_t *cur_set = pg ? pg->cur_set.data() : &this->osd_num; + // Take the state on every attempt: check_corrupted_chained() compares it with the current one + osd_num_t *cur_set = pg + ? get_object_osd_set(*pg, cur_oid, &op_data->chain_states[chain_reads[cri].chain_pos]) + : &this->osd_num; if (pg && pg->state != PG_ACTIVE) { - cur_set = get_object_osd_set(*pg, cur_oid, &op_data->chain_states[chain_reads[cri].chain_pos]); if (pg->scheme != POOL_SCHEME_REPLICATED) { if (extend_missing_stripes(stripes, cur_set, pg->pg_data_size, pg->pg_size) < 0) diff --git a/src/test/osd_test.cpp b/src/test/osd_test.cpp index e0db38fa..3b5f5c17 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -1309,6 +1309,142 @@ void test_chained_read_large_chain_info() } +// The parent object's recovery finishes while a chained read of it is in flight, so the PG +// becomes PG_ACTIVE, and then the local copy keeps answering -EIO. The read must mark that +// copy corrupted and read the good one, not retry the same copy forever +void test_chained_read_eio_after_recovery_finishes() +{ + printf("test_chained_read_eio_after_recovery_finishes\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); + inode_t parent_inode = INODE_WITH_POOL(1, 3); + object_id parent_oid = { .inode = parent_inode, .stripe = 0 }; + // The parent object is only on OSD 1: degraded. 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); + + const int NOT_DONE = 1; + int read_retval = NOT_DONE; + auto *read = new osd_op_t(); + read->op_type = OSD_OP_IN; + read->client_id = 0; + read->req.rw.header.magic = SECONDARY_OSD_OP_MAGIC; + read->req.rw.header.id = 2; + read->req.rw.header.opcode = OSD_OP_READ; + read->req.rw.inode = child_inode; + read->req.rw.offset = 0; + read->req.rw.len = 4096; + // The inode revision the client saw: that makes it a chained read + read->req.rw.meta_revision = 1; + read->callback = [&](osd_op_t *op) { read_retval = op->reply.hdr.retval; }; + f.exec(read); + + // Bitmaps are local (synchronous); the data comes from the parent, from the local copy + auto *parent_read = f.bs->take(BS_OP_READ); + assert(parent_read->oid == parent_oid && parent_read->len == 4096); + assert(f.bs->queued.empty()); + + // Recovery of the parent object finishes while that read is in flight: the same + // zero-length write submit_recovery_op() sends + int rec_retval = NOT_DONE; + auto *rec = new osd_op_t(); + rec->op_type = OSD_OP_OUT; + rec->client_id = 0; // SELF_CLIENT + rec->req.rw.header.magic = SECONDARY_OSD_OP_MAGIC; + rec->req.rw.header.id = 1; + rec->req.rw.header.opcode = OSD_OP_WRITE; + rec->req.rw.inode = parent_inode; + rec->req.rw.offset = 0; + rec->req.rw.len = 0; + rec->callback = [&](osd_op_t *op) { rec_retval = op->reply.hdr.retval; }; + f.exec(rec); + auto *rec_read = f.bs->take(BS_OP_READ); + assert(rec_read->oid == parent_oid && rec_read->len == 131072); + memset(rec_read->buf, 0xab, rec_read->len); + if (rec_read->bitmap) + memset(rec_read->bitmap, 0xff, 4); + rec_read->version = 1; + rec_read->retval = rec_read->len; + rec_read->callback(rec_read); + f.pump(); + f.bs_write_ok(BS_OP_WRITE_STABLE, 2); + f.peer_write_ok(2, OSD_OP_SEC_WRITE_STABLE, 2); + f.pump(); + assert(rec_retval == 0); + assert(f.pg(1, 1).state == PG_ACTIVE); + + // The local copy keeps answering -EIO; OSD 2 has the good copy recovery just wrote. + // Bounded, because the bug is an endless retry + const int max_eio = 10; + int eio_answers = 0; + while (read_retval == NOT_DONE && eio_answers < max_eio) + { + if (auto *rd = (eio_answers ? f.bs->take(BS_OP_READ, false) : parent_read)) + { + assert(rd->oid == parent_oid); + rd->retval = -EIO; + rd->callback(rd); + eio_answers++; + } + else if (auto *bmp = f.peer_take_opt(2, OSD_OP_SEC_READ_BMP)) + { + int n = bmp->req.sec_read_bmp.len / sizeof(obj_ver_id); + auto *ov = (obj_ver_id*)bmp->buf; + uint8_t *reply = (uint8_t*)calloc(n, 8 + 4); + for (int i = 0; i < n; i++) + { + *(uint64_t*)(reply + i*12) = 2; + if (ov[i].oid == parent_oid) + memset(reply + i*12 + 8, 0xff, 4); + } + free(bmp->buf); + bmp->buf = reply; + f.peer_complete(bmp, n * (8 + 4)); + } + else if (auto *rd2 = f.peer_take_opt(2, OSD_OP_SEC_READ)) + { + assert(rd2->req.sec_rw.oid == parent_oid); + if (rd2->bitmap) + memset(rd2->bitmap, 0xff, 4); + rd2->reply.sec_rw.attr_len = 4; + rd2->reply.sec_rw.version = 2; + f.peer_complete(rd2, rd2->req.sec_rw.len); + } + else + break; + f.pump(); + } + // Served from OSD 2 after the local copy was marked + assert(read_retval == (int)read->req.rw.len); + + delete rec; + delete read; + printf("test_chained_read_eio_after_recovery_finishes passed\n"); +} + // A degraded EC read may leave its parity read ranges behind when the object state // changes under the operation (recovery brings a chunk back while subops are in flight) // and a failed subop retries the whole read. The retry then takes the fast path, which @@ -4693,6 +4829,7 @@ int main(int narg, char *args[]) test_pg_epoch_base_is_reported_epoch(); test_pg_epoch_bump_above_reported_epoch(); test_chained_read_large_chain_info(); + test_chained_read_eio_after_recovery_finishes(); test_peering_partial_unstable_ec_rolls_back(); test_peering_flush_primary_lost({ 2, 1, 2 }, 2); test_peering_flush_primary_lost({ 2, 1, 2 }, 3); 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.