osd: Let the event loop run between PG peering calculations #197
@@ -112,6 +112,11 @@ osd_t::~osd_t()
|
||||
tfd->clear_timer(recovery_retry_timer_id);
|
||||
recovery_retry_timer_id = -1;
|
||||
}
|
||||
if (peering_yield_timer_id >= 0)
|
||||
{
|
||||
tfd->clear_timer(peering_yield_timer_id);
|
||||
peering_yield_timer_id = -1;
|
||||
}
|
||||
ringloop->unregister_consumer(&consumer);
|
||||
ringloop->unregister_consumer(&init_consumer);
|
||||
// Tear down clients first: destroying a client cancels its operations and the
|
||||
|
||||
@@ -213,6 +213,8 @@ class osd_t
|
||||
uint64_t misplaced_objects = 0, degraded_objects = 0, incomplete_objects = 0, inconsistent_objects = 0, corrupted_objects = 0;
|
||||
uint64_t tombstone_objects = 0;
|
||||
int peering_state = 0;
|
||||
// Armed after a PG calc; the next calc waits for it
|
||||
int peering_yield_timer_id = -1;
|
||||
std::map<object_id, osd_recovery_op_t> recovery_ops;
|
||||
// OSD-owned in-flight ops (flush batches, peering LIST subops): their only
|
||||
// owners are completion callbacks, so the destructor needs a handle on them
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// Peering loop
|
||||
void osd_t::handle_peers()
|
||||
{
|
||||
if (peering_state & OSD_PEERING_PGS)
|
||||
if ((peering_state & OSD_PEERING_PGS) && peering_yield_timer_id < 0)
|
||||
{
|
||||
bool still = false;
|
||||
for (auto & p: pgs)
|
||||
@@ -21,7 +21,13 @@ void osd_t::handle_peers()
|
||||
{
|
||||
if (continue_pg_peering(p.second))
|
||||
{
|
||||
ringloop->wakeup();
|
||||
// Not wakeup(): it runs the next calc in the same ring loop pass, before
|
||||
// any completion is read, and back-to-back calcs of large PGs starve pings
|
||||
peering_yield_timer_id = tfd->set_timer(1, false, [this](int)
|
||||
{
|
||||
peering_yield_timer_id = -1;
|
||||
ringloop->wakeup();
|
||||
});
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -2517,6 +2517,38 @@ void test_sync_interference()
|
||||
printf("test_sync_interference passed\n");
|
||||
}
|
||||
|
||||
// Completions (pings, timers, etcd lease replies) are read only at the start of a ring loop
|
||||
// pass, so two PG calcs must never run in one pass: back-to-back calcs of large PGs leave
|
||||
// the OSD deaf for seconds, and peers and etcd take it for dead
|
||||
void test_peering_yields_between_pgs()
|
||||
{
|
||||
printf("test_peering_yields_between_pgs\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));
|
||||
// The next calc waits for the timer, not just for the next pass
|
||||
f.ringloop->wakeup();
|
||||
f.ringloop->loop();
|
||||
assert((f.pg(1, 1).state == PG_PEERING) != (f.pg(1, 2).state == PG_PEERING));
|
||||
f.pump();
|
||||
assert(f.pg(1, 1).state == PG_ACTIVE);
|
||||
assert(f.pg(1, 2).state == PG_ACTIVE);
|
||||
printf("test_peering_yields_between_pgs passed\n");
|
||||
}
|
||||
|
||||
// Invariant (3) via stop_pg
|
||||
void test_pg_stop_drops_dirty_client()
|
||||
{
|
||||
@@ -5594,5 +5626,6 @@ int main(int narg, char *args[])
|
||||
test_tombstone_replicated_roles();
|
||||
test_tombstone_inline_misplaced();
|
||||
test_tombstone_forget_counters();
|
||||
test_peering_yields_between_pgs();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,9 @@ struct osd_test_fixture_t
|
||||
|
||||
osd_test_fixture_t()
|
||||
{
|
||||
tfd = new timerfd_manager_t([](int, bool, std::function<void(int, int)>) {});
|
||||
// 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 *) {});
|
||||
st_cli = new etcd_state_client_mock_t(etcd_store);
|
||||
}
|
||||
@@ -269,7 +271,8 @@ struct osd_test_fixture_t
|
||||
// Complete every outstanding peering LIST op (local BS_OP_LIST + peer
|
||||
// OSD_OP_SEC_LIST) with "no objects" so PGs transition to PG_ACTIVE
|
||||
// without us having to invent object lists.
|
||||
void complete_peering_empty()
|
||||
// drive=false leaves the calcs to the caller's ring loop passes
|
||||
void complete_peering_empty(bool drive = true)
|
||||
{
|
||||
for (auto it = bs->queued.begin(); it != bs->queued.end(); )
|
||||
{
|
||||
@@ -305,8 +308,8 @@ struct osd_test_fixture_t
|
||||
}
|
||||
}
|
||||
// Drive handle_peers so PGs see lists_done and finalize calc_object_states.
|
||||
ringloop->wakeup();
|
||||
ringloop->loop();
|
||||
if (drive)
|
||||
pump();
|
||||
}
|
||||
|
||||
// Inline list response builder. `objects` are pairs (oid, version);
|
||||
@@ -434,6 +437,12 @@ struct osd_test_fixture_t
|
||||
{
|
||||
ringloop->wakeup();
|
||||
ringloop->loop();
|
||||
// handle_peers runs one PG calc, then waits for a 1 ms timer
|
||||
while (osd && osd->peering_yield_timer_id >= 0)
|
||||
{
|
||||
tfd->tick((timespec){ .tv_sec = 0, .tv_nsec = 1000000 });
|
||||
ringloop->loop();
|
||||
}
|
||||
}
|
||||
|
||||
// Submit an op to the OSD's primary state machine. Wrapper because
|
||||
|
||||
Reference in New Issue
Block a user