From 042b83d6e11f4ca7673956033701072576a00e67 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sun, 29 Nov 2026 12:32:50 +0300 Subject: [PATCH 1/2] Fix rm-data waiting forever when PGs go inactive during deletion An operation with OSD_OP_WAIT_UP_TIMEOUT that finds its PG inactive gets a deadline, but the retry timer is armed only for parts retried after a failure. An operation that first found its PG already inactive was left without a timer and waited for an unrelated event instead of failing after client_wait_up_timeout. rm-data hit this when OSDs died during deletion: the deletes in flight timed out, and the following deletes of the same PG waited forever. Arm the timer for such operations too. Also stop sending deletes to a PG after one of them times out, and report the PG as not deleted, so that rm-data doesn't wait client_wait_up_timeout again for each of its remaining objects. --- src/client/cluster_client.cpp | 3 ++- src/cmd/cli_rm_data.cpp | 6 +++++ src/test/test_cluster_client.cpp | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/client/cluster_client.cpp b/src/client/cluster_client.cpp index 38e4e7ba..e670f288 100644 --- a/src/client/cluster_client.cpp +++ b/src/client/cluster_client.cpp @@ -1241,7 +1241,8 @@ resume_1: } } } - if (op->parts[i].flags & PART_RETRY) + // An operation waiting for its PG to come up needs the timer to see wait_up_until expire + if ((op->parts[i].flags & PART_RETRY) || op->wait_up_until.tv_sec) { op->retry_after = client_retry_interval; reset_retry_timer(client_retry_interval); diff --git a/src/cmd/cli_rm_data.cpp b/src/cmd/cli_rm_data.cpp index 77d31ae6..8f4068d2 100644 --- a/src/cmd/cli_rm_data.cpp +++ b/src/cmd/cli_rm_data.cpp @@ -109,6 +109,12 @@ struct rm_inode_t fprintf(stderr, "Failed to remove object %jx:%jx from PG %u (retval=%d)\n", op->inode, op->offset, cur_list->pg_num, op->retval); error_count++; + if (op->retval == -ETIMEDOUT) + { + // The PG did not come up in time: don't wait for it again for each of its objects + inactive_pgs.insert(cur_list->pg_num); + cur_list->obj_pos = cur_list->objects.end(); + } } else { diff --git a/src/test/test_cluster_client.cpp b/src/test/test_cluster_client.cpp index 8b10f347..f32e5b9e 100644 --- a/src/test/test_cluster_client.cpp +++ b/src/test/test_cluster_client.cpp @@ -1345,6 +1345,51 @@ void test_sync_fail_dirty_state_loss() // CAS write/delete over two objects must fail with -EINVAL before anything is // sent: the OSD checks the version of one object only +// The deadline of an operation with OSD_OP_WAIT_UP_TIMEOUT is in real time, so the test sleeps. +// An operation that first found its PG inactive had no timer to see the deadline expire, +// and waited for an unrelated event instead of failing after client_wait_up_timeout +void test_wait_up_timeout_inactive_pg() +{ + timerfd_manager_t *tfd = new timerfd_manager_t(nullptr); + tfd->set_fd_handler = [](int, bool, std::function) {}; + etcd_mock_t etcd_store; + etcd_state_client_mock_t *mock = new etcd_state_client_mock_t(etcd_store); + mock->pause(); + cluster_client_t *cli = new cluster_client_t(NULL, tfd, json11::Json::object { + { "client_wait_up_timeout", 1 }, + }, std::unique_ptr(mock)); + configure_single_pg_pool(mock, "all"); + mock->set("/vitastor/pg/state/1/1", json11::Json::object { + { "peers", json11::Json::array { 1 } }, + { "primary", 1 }, + { "state", json11::Json::array { "incomplete" } }, + }); + mock->resume(); + + int r = 1; + cluster_op_t *op = new cluster_op_t; + op->opcode = OSD_OP_DELETE; + op->inode = 0x1000000000001; + op->offset = 0; + op->len = 0; + op->flags = OSD_OP_WAIT_UP_TIMEOUT; + op->callback = [&r](cluster_op_t *op) + { + r = op->retval; + delete op; + }; + cli->execute(op); + assert(r == 1); + + usleep(1100000); + tfd->tick((timespec){ .tv_sec = 1, .tv_nsec = 100000000 }); + assert(r == -ETIMEDOUT); + + delete cli; + delete tfd; + printf("[ok] test_wait_up_timeout_inactive_pg\n"); +} + void test_cas_cross_object() { json11::Json config; @@ -1417,6 +1462,7 @@ int main(int narg, char *args[]) test_primary_change_flush_loss(); test_sync_fail_dirty_state_loss(); test_cas_cross_object(); + test_wait_up_timeout_inactive_pg(); cluster_client_test_t::test_vault(); test_pg_config_disappears(); test_sync_released_during_continue_ops(); -- 2.47.3 From 0219f6f68b5e8e35e8525ba188aa394f25130ee2 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sun, 29 Nov 2026 14:53:15 +0300 Subject: [PATCH 2/2] Arm the retry timer when an operation starts waiting for its PG Instead of polling an operation that waits for its PG to come up every client_retry_interval, arm the retry timer for client_wait_up_timeout when its deadline is set. Re-arm it for the remaining time while the operation still waits: reset_retry_timer() keeps a shorter timer that is already set, and when that one fires for another operation, nothing would wake this one up again before its deadline. --- src/client/cluster_client.cpp | 7 +++-- src/test/test_cluster_client.cpp | 52 +++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/client/cluster_client.cpp b/src/client/cluster_client.cpp index e670f288..5ea374db 100644 --- a/src/client/cluster_client.cpp +++ b/src/client/cluster_client.cpp @@ -1223,6 +1223,7 @@ resume_1: // Set "wait_up" timer clock_gettime(CLOCK_REALTIME, &op->wait_up_until); op->wait_up_until.tv_sec += client_wait_up_timeout; + reset_retry_timer(client_wait_up_timeout*1000); } else { @@ -1239,10 +1240,12 @@ resume_1: op->retval = -ETIMEDOUT; break; } + // reset_retry_timer() keeps a shorter timer, which may have fired for another operation + reset_retry_timer(std::max(1l, (op->wait_up_until.tv_sec - tv.tv_sec)*1000 + + (op->wait_up_until.tv_nsec - tv.tv_nsec + 999999)/1000000)); } } - // An operation waiting for its PG to come up needs the timer to see wait_up_until expire - if ((op->parts[i].flags & PART_RETRY) || op->wait_up_until.tv_sec) + if (op->parts[i].flags & PART_RETRY) { op->retry_after = client_retry_interval; reset_retry_timer(client_retry_interval); diff --git a/src/test/test_cluster_client.cpp b/src/test/test_cluster_client.cpp index f32e5b9e..a853b7d5 100644 --- a/src/test/test_cluster_client.cpp +++ b/src/test/test_cluster_client.cpp @@ -1347,7 +1347,9 @@ void test_sync_fail_dirty_state_loss() // sent: the OSD checks the version of one object only // The deadline of an operation with OSD_OP_WAIT_UP_TIMEOUT is in real time, so the test sleeps. // An operation that first found its PG inactive had no timer to see the deadline expire, -// and waited for an unrelated event instead of failing after client_wait_up_timeout +// and waited for an unrelated event instead of failing after client_wait_up_timeout. +// The second delete starts waiting 0.5 s later, so it needs the timer again after it +// fires for the first one void test_wait_up_timeout_inactive_pg() { timerfd_manager_t *tfd = new timerfd_manager_t(nullptr); @@ -1366,24 +1368,40 @@ void test_wait_up_timeout_inactive_pg() }); mock->resume(); - int r = 1; - cluster_op_t *op = new cluster_op_t; - op->opcode = OSD_OP_DELETE; - op->inode = 0x1000000000001; - op->offset = 0; - op->len = 0; - op->flags = OSD_OP_WAIT_UP_TIMEOUT; - op->callback = [&r](cluster_op_t *op) + int r[2] = { 1, 1 }; + timespec start; + clock_gettime(CLOCK_REALTIME, &start); + for (int i = 0; i < 2; i++) { - r = op->retval; - delete op; - }; - cli->execute(op); - assert(r == 1); + if (i > 0) + usleep(500000); + cluster_op_t *op = new cluster_op_t; + op->opcode = OSD_OP_DELETE; + op->inode = 0x1000000000001; + op->offset = i*0x20000; + op->len = 0; + op->flags = OSD_OP_WAIT_UP_TIMEOUT; + op->callback = [&r, i](cluster_op_t *op) + { + r[i] = op->retval; + delete op; + }; + cli->execute(op); + } - usleep(1100000); - tfd->tick((timespec){ .tv_sec = 1, .tv_nsec = 100000000 }); - assert(r == -ETIMEDOUT); + // Only the retry timer moves the deletes on from here. It follows the real time + // that passed, so a stall of the test can't fail it + timespec prev = start; + for (int i = 0; i < 50 && (r[0] == 1 || r[1] == 1); i++) + { + usleep(100000); + timespec now; + clock_gettime(CLOCK_REALTIME, &now); + long ns = (now.tv_sec - prev.tv_sec)*1000000000l + now.tv_nsec - prev.tv_nsec; + tfd->tick((timespec){ .tv_sec = ns / 1000000000, .tv_nsec = ns % 1000000000 }); + prev = now; + } + assert(r[0] == -ETIMEDOUT && r[1] == -ETIMEDOUT); delete cli; delete tfd; -- 2.47.3