diff --git a/src/client/cluster_client.cpp b/src/client/cluster_client.cpp index 38e4e7ba..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,6 +1240,9 @@ 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)); } } if (op->parts[i].flags & PART_RETRY) 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..a853b7d5 100644 --- a/src/test/test_cluster_client.cpp +++ b/src/test/test_cluster_client.cpp @@ -1345,6 +1345,69 @@ 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. +// 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); + 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[2] = { 1, 1 }; + timespec start; + clock_gettime(CLOCK_REALTIME, &start); + for (int i = 0; i < 2; i++) + { + 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); + } + + // 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; + printf("[ok] test_wait_up_timeout_inactive_pg\n"); +} + void test_cas_cross_object() { json11::Json config; @@ -1417,6 +1480,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();