Client: Keep the listing timer armed while PGs wait to become active #201

Merged
vitalif merged 1 commits from koolkhel/vitastor:list-wait-up-timer into master 2026-11-29 14:15:56 +03:00
2 changed files with 104 additions and 0 deletions

View File

@@ -226,6 +226,12 @@ void cluster_client_t::retry_start_pg_listing(inode_list_pg_t *pg)
pg->objects.clear();
finish_list_pg(pg, false);
}
else
{
// Ensure that the retry timer is set: it may have fired for another PG
set_list_retry_timeout(pg->wait_until.tv_sec*1000 - tv.tv_sec*1000 +
(pg->wait_until.tv_nsec - tv.tv_nsec)/1000000, pg->wait_until);
}
}
void cluster_client_t::set_list_retry_timeout(int ms, timespec new_time)

View File

@@ -1182,6 +1182,103 @@ void test_snapshot_over_nonexistent_pool()
printf("[ok] test_snapshot_over_nonexistent_pool\n");
}
static void sleep_until(const timespec & start, long ms)
{
timespec t = { .tv_sec = start.tv_sec + ms/1000, .tv_nsec = start.tv_nsec + (ms%1000)*1000000 };
if (t.tv_nsec >= 1000000000)
{
t.tv_sec++;
t.tv_nsec -= 1000000000;
}
while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &t, NULL) == EINTR) {}
}
// Listing deadlines are in real time, so the test sleeps. PG 3 is first seen inactive after
// the listing of PG 2, so its deadline is later than PG 1's. When the timer fired for PG 1,
// PG 3 was left without a timer and its listing waited for an unrelated etcd event
void test_list_wait_active_timeout()
{
timerfd_manager_t *tfd = new timerfd_manager_t(nullptr);
tfd->set_fd_handler = [](int, bool, std::function<void(int, int)>) {};
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<etcd_state_client_t>(mock));
mock->set("/vitastor/config/pools", json11::Json::object {
{ "1", json11::Json::object {
{ "name", "hddpool" },
{ "scheme", "replicated" },
{ "pg_size", 2 },
{ "pg_minsize", 1 },
{ "pg_count", 3 },
{ "failure_domain", "osd" },
{ "immediate_commit", "all" },
} }
});
json11::Json::object pgs;
for (int i = 1; i <= 3; i++)
{
pgs[std::to_string(i)] = json11::Json::object {
{ "osd_set", json11::Json::array { 1, 2 } },
{ "primary", 1 },
};
}
mock->set("/vitastor/pg/config", json11::Json::object {
{ "items", json11::Json::object { { "1", pgs } } }
});
// Only PG 2 is active
mock->set("/vitastor/pg/state/1/2", json11::Json::object {
{ "peers", json11::Json::array { 1, 2 } },
{ "primary", 1 },
{ "state", json11::Json::array { "active" } },
});
mock->resume();
pretend_connected(cli, 1);
std::map<pg_num_t, int> listed;
timespec start;
clock_gettime(CLOCK_REALTIME, &start);
cli->list_inode(INODE_WITH_POOL(1, 1), 0, 0, 1, [&](int status, int pgs_left, pg_num_t pg_num, std::set<object_id>&& objects)
{
printf("PG %u listed: status %d, %d PGs left\n", pg_num, status, pgs_left);
listed[pg_num] = status;
});
osd_op_t *list_op = NULL;
for (auto & op_p: cli->msgr->osd_peers.at(1)->sent_ops)
{
if (op_p.second->req.hdr.opcode == OSD_OP_SEC_LIST)
list_op = op_p.second;
}
assert(list_op && list_op->req.sec_list.list_pg == 2);
// PG 2 replies after 0.5 s, then PG 3 is seen inactive
sleep_until(start, 500);
cli->msgr->clients[list_op->client_id]->sent_ops.erase(list_op->req.hdr.id);
list_op->reply.hdr.magic = SECONDARY_OSD_REPLY_MAGIC;
list_op->reply.hdr.id = list_op->req.hdr.id;
list_op->reply.hdr.opcode = OSD_OP_SEC_LIST;
list_op->reply.hdr.retval = 0;
list_op->reply.sec_list.flags = OSD_LIST_PRIMARY;
std::function<void(osd_op_t*)>(list_op->callback)(list_op);
assert(listed.size() == 1 && listed.at(2) == 0);
// PG 1 times out
sleep_until(start, 1200);
tfd->tick((timespec){ .tv_sec = 1, .tv_nsec = 200000000 });
assert(listed.size() == 2 && listed.at(1) == -EPIPE);
// PG 3 times out too
sleep_until(start, 2000);
tfd->tick((timespec){ .tv_sec = 0, .tv_nsec = 800000000 });
assert(listed.size() == 3 && listed.at(3) == -EPIPE);
delete cli;
delete tfd;
printf("[ok] test_list_wait_active_timeout\n");
}
// Data loss reproduction: dirty buffer re-flush after PG primary change.
//
// A write buffer is acknowledged by OSD 2 while OSD 2 is the PG primary.
@@ -1421,5 +1518,6 @@ int main(int narg, char *args[])
test_pg_config_disappears();
test_sync_released_during_continue_ops();
test_snapshot_over_nonexistent_pool();
test_list_wait_active_timeout();
return 0;
}