osd: Finish a read with -EPIPE when its PG stops instead of marking copies corrupted #164

Merged
vitalif merged 4 commits from koolkhel/vitastor:read-epipe-stopped-pg into master 2026-11-24 03:50:47 +03:00
4 changed files with 122 additions and 1 deletions

View File

@@ -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

View File

@@ -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...

View File

@@ -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<uint8_t>(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();

View File

@@ -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<object_id> read_bitmap_calls;
// What read_bitmap() returns for an object; others are absent
std::map<object_id, std::vector<uint8_t>> 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.