osd: Send queued replies before a peering calculation #199

Merged
vitalif merged 3 commits from koolkhel/vitastor:osd-reply-before-peering into master 2026-11-29 14:13:14 +03:00
4 changed files with 89 additions and 1 deletions

View File

@@ -364,6 +364,9 @@ bool osd_t::continue_pg_peering(pg_t & pg)
if (pg.peering_state->lists_done)
{
auto history_size = pg.target_history.size();
// The calc blocks the loop, and continue_pg() runs it from a completion: send the queued replies first
msgr.send_replies();
ringloop->submit();
pg.calc_object_states(log_level);
// Two-phase delete needs tombstone support in stores of all PG members
pg.enable_tombstones = (pg.state & PG_ACTIVE) && bs->supports_tombstones();

View File

@@ -57,8 +57,13 @@ void osd_messenger_t::read_requests()
{
}
// Set by osd_test: runs where the real messenger puts the queued replies into send SQEs
std::function<void()> mock_send_replies_hook;
void osd_messenger_t::send_replies()
{
if (mock_send_replies_hook)
mock_send_replies_hook();
}
json11::Json::object osd_messenger_t::read_config(const json11::Json & config)

View File

@@ -2549,6 +2549,79 @@ void test_peering_yields_between_pgs()
printf("test_peering_yields_between_pgs passed\n");
}
extern std::function<void()> mock_send_replies_hook;
// A reply queued in the pass where the yield timer fires must reach the ring before the next
// calc starts: otherwise a ping answered in that pass waits for that calc too
void test_peering_sends_replies_before_calc()
{
printf("test_peering_sends_replies_before_calc\n");
osd_test_fixture_t f;
f.configure_replicated_pool(1, 2, 1, 2, { { 1, 2 }, { 1, 2 } });
f.start(json11::Json::object {
{ "osd_num", 1 },
{ "etcd_address", "127.0.0.1:2379" },
{ "immediate_commit", "none" },
{ "block_size", 131072 },
{ "bitmap_granularity", 4096 },
});
f.connect_peer(2);
f.complete_peering_empty(false);
f.ringloop->wakeup();
f.ringloop->loop();
assert((f.pg(1, 1).state == PG_PEERING) != (f.pg(1, 2).state == PG_PEERING));
pg_t *first = f.pg(1, 1).state == PG_PEERING ? &f.pg(1, 2) : &f.pg(1, 1);
pg_t *second = first == &f.pg(1, 1) ? &f.pg(1, 2) : &f.pg(1, 1);
// Like the real messenger, the first send_replies() of the pass puts the queued replies
// into a send SQE
pg_t *calc_pg = second;
bool queued = false, sent_before_calc = false;
auto queue_reply = [&]()
{
if (queued)
return;
queued = true;
io_uring_sqe *sqe = f.ringloop->get_sqe();
io_uring_prep_nop(sqe);
((ring_data_t*)sqe->user_data)->callback = [](ring_data_t *) {};
};
auto check_submit = [&](io_uring_sqe *sqe)
{
if (calc_pg->state == PG_PEERING)
sent_before_calc = true;
f.ringloop->mark_completed((ring_data_t*)sqe->user_data);
};
// A re-peer keeps the lists of the peers that stay, so continue_pg() calculates the
// waiting PG at once, outside handle_peers()
f.tfd->tick((timespec){ .tv_sec = 0, .tv_nsec = 1000000 });
mock_send_replies_hook = queue_reply;
f.on_submit = check_submit;
f.repeer_pgs(2);
mock_send_replies_hook = NULL;
f.on_submit = NULL;
assert(sent_before_calc);
assert(second->state == PG_ACTIVE);
// handle_peers() calculates the other PG when its lists arrive
f.complete_peering_empty(false);
calc_pg = first;
queued = sent_before_calc = false;
mock_send_replies_hook = queue_reply;
f.on_submit = check_submit;
f.tfd->tick((timespec){ .tv_sec = 0, .tv_nsec = 1000000 });
f.ringloop->loop();
mock_send_replies_hook = NULL;
f.on_submit = NULL;
assert(sent_before_calc);
assert(f.pg(1, 1).state == PG_ACTIVE);
assert(f.pg(1, 2).state == PG_ACTIVE);
printf("test_peering_sends_replies_before_calc passed\n");
}
// Invariant (3) via stop_pg
void test_pg_stop_drops_dirty_client()
{
@@ -5627,5 +5700,6 @@ int main(int narg, char *args[])
test_tombstone_inline_misplaced();
test_tombstone_forget_counters();
test_peering_yields_between_pgs();
test_peering_sends_replies_before_calc();
return 0;
}

View File

@@ -113,13 +113,19 @@ struct osd_test_fixture_t
capturing_bs_t *bs = nullptr;
// Simulated peers advertise tombstone support unless tests disable it
bool peer_tombstones = true;
// Sees every SQE submitted to the mock ring
std::function<void(io_uring_sqe *)> on_submit;
osd_test_fixture_t()
{
// Created without a handler: no timerfd, timers fire on tick() (pump)
tfd = new timerfd_manager_t(NULL);
tfd->set_fd_handler = [](int, bool, std::function<void(int, int)>) {};
ringloop = new ring_loop_mock_t(RINGLOOP_DEFAULT_SIZE, [](io_uring_sqe *) {});
ringloop = new ring_loop_mock_t(RINGLOOP_DEFAULT_SIZE, [this](io_uring_sqe *sqe)
{
if (on_submit)
on_submit(sqe);
});
st_cli = new etcd_state_client_mock_t(etcd_store);
}