From d7e68964d815ba9f620830ccc1680e8c8c7f57b5 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Tue, 10 Jan 2023 14:39:31 +0000 Subject: [PATCH] test/crimson: verify the backfill cancellation & resumption Signed-off-by: Radoslaw Zarzynski --- src/test/crimson/test_backfill.cc | 77 ++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/src/test/crimson/test_backfill.cc b/src/test/crimson/test_backfill.cc index bf958cd5ae726..6648719c61c8f 100644 --- a/src/test/crimson/test_backfill.cc +++ b/src/test/crimson/test_backfill.cc @@ -157,7 +157,11 @@ public: template void next_round2() { ceph_assert(events_to_dispatch.size()); - ceph_assert(typeid(*events_to_dispatch.front()) == typeid(EventT)); + // workaround for Clang's `-Wpotentially-evaluated-expression`. See: + // * https://gitlab.cern.ch/gaudi/Gaudi/-/merge_requests/970 + // * https://stackoverflow.com/q/46494928 + const auto& front_event = *events_to_dispatch.front(); + ceph_assert(typeid(front_event) == typeid(EventT)); backfill_state.process_event(std::move(events_to_dispatch.front())); events_to_dispatch.pop_front(); } @@ -179,6 +183,15 @@ public: struct PeeringFacade; struct PGFacade; + + void cancel() { + events_to_dispatch.clear(); + schedule_event(crimson::osd::BackfillState::CancelBackfill{}); + } + + void resume() { + schedule_event(crimson::osd::BackfillState::Triggered{}); + } }; struct BackfillFixture::PeeringFacade @@ -419,6 +432,68 @@ TEST(backfill, two_empty_replicas) EXPECT_TRUE(cluster_fixture.all_stores_look_like(reference_store)); } +TEST(backfill, cancel_resume) +{ + const auto reference_store = FakeStore{ { + { "1:00058bcc:::rbd_data.1018ac3e755.00000000000000d5:head", {10, 234} }, + { "1:00ed7f8e:::rbd_data.1018ac3e755.00000000000000af:head", {10, 196} }, + { "1:01483aea:::rbd_data.1018ac3e755.0000000000000095:head", {10, 169} }, + }}; + auto cluster_fixture = BackfillFixtureBuilder::add_source( + reference_store.objs + ).add_target( + { /* nothing 1 */ } + ).add_target( + { /* nothing 2 */ } + ).get_result(); + + EXPECT_CALL(cluster_fixture, backfilled); + cluster_fixture.next_round2(); + cluster_fixture.cancel(); + cluster_fixture.next_round2(); + cluster_fixture.resume(); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.next_till_done(); + + EXPECT_TRUE(cluster_fixture.all_stores_look_like(reference_store)); +} + +TEST(backfill, cancel_resume_middle_of_scan) +{ + const auto reference_store = FakeStore{ { + { "1:00058bcc:::rbd_data.1018ac3e755.00000000000000d5:head", {10, 234} }, + { "1:00ed7f8e:::rbd_data.1018ac3e755.00000000000000af:head", {10, 196} }, + { "1:01483aea:::rbd_data.1018ac3e755.0000000000000095:head", {10, 169} }, + }}; + auto cluster_fixture = BackfillFixtureBuilder::add_source( + reference_store.objs + ).add_target( + { /* nothing 1 */ } + ).add_target( + { /* nothing 2 */ } + ).get_result(); + + EXPECT_CALL(cluster_fixture, backfilled); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.cancel(); + cluster_fixture.next_round2(); + cluster_fixture.resume(); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.next_round2(); + cluster_fixture.next_till_done(); + + EXPECT_TRUE(cluster_fixture.all_stores_look_like(reference_store)); +} + namespace StoreRandomizer { // FIXME: copied & pasted from test/test_snap_mapper.cc. We need to // find a way to avoid code duplication in test. A static library? -- 2.39.5