Skip to content

test/osd: overhaul OSD/EC unit test framework with CRUSH-based placement, ObjectTracker and Multi Zone - #71844

Merged
aainscow merged 28 commits into
ceph:mainfrom
aainscow:stretchy-C-tests-only
Oct 2, 2026
Merged

aainscow merged 28 commits into
ceph:mainfrom
aainscow:stretchy-C-tests-only

Conversation

@aainscow

@aainscow aainscow commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This series refactors and significantly extends the OSD backend unit test
infrastructure to support realistic CRUSH-based placement, multi-zone EC
configurations, and systematic object-state verification.

depends-on: #71931
Fixes: https://tracker.ceph.com/issues/80680

Changes

Fixture decoupling and dynamic CRUSH mapping

Previously, OSD test fixtures conflated OSD instances with PG shard instances
via static 1:1 upmap mappings. Fixtures now own per-OSD ObjectStore and LRU
cache instances, with TestPG instances created lazily on OSDMap epoch
advancement. This enables tests to evaluate real CRUSH placement rules and
multi-PG scenarios natively.

MockStore factory method and .cc split

A static MockStore::create() factory method now encapsulates construction,
mkfs, and mount in one place, returning a shared_ptr. The implementation
is moved to MockStore.cc to keep the header lean.

ObjectTracker for expected-state verification

New ObjectTracker class records object modifications (data writes, creates,
xattr writes, and omap operations) across transaction commits and reconstructs
expected state for verification in recovery and peering test scenarios.

Multi-zone EC support and fixture iteration fix

BackendConfig gains a num_zones field (default 1, preserving existing
behaviour). simulate_multiple_osd_failures now accepts std::set<int> and
iterates the osd_fixtures/pgs hierarchy correctly for pools where
pool_size = num_zones * (k + m). New MultiZoneWriteThenRead and
MultiZoneFailover tests exercise write, read, and degraded-read paths for
multi-zone configurations.

NOTE: The product code is not added here and no test uses num_zones > 1
This will come in a future PR.

PGLogTest pool initialisation

PGLogTest now initialises a replicated pool (size 3) in its fixture
constructor, fixing failures in pool-property-dependent test scenarios.

Expanded pgtemp_primaryfirst tests

A comprehensive pgtemp_primaryfirst_comprehensive suite exercises multiple
(k, m, num_zones) combinations and OSD layout patterns (large IDs,
overlapping OSDs, all-same OSDs) to validate roundtrip consistency between
pgtemp_primaryfirst and pgtemp_undo_primaryfirst.

Contribution Guidelines

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@aainscow
aainscow force-pushed the stretchy-C-tests-only branch from 1ad664b to d47c1bd Compare September 18, 2026 13:48
@aainscow
aainscow force-pushed the stretchy-C-tests-only branch from d47c1bd to 1902559 Compare September 21, 2026 06:55
@aainscow aainscow changed the title test/osd: overhaul OSD/EC unit test framework with fixture decoupling, ObjectTracker, and multi-zone support test/osd: overhaul OSD/EC unit test framework with CRUSH-based placement, ObjectTracker and Multi Zone Sep 21, 2026
@aainscow

Copy link
Copy Markdown
Contributor Author

Latest rebase on top of the memstore changes, which required small merge conflict resolution.

…mpare attrs across shards

TearDown() now runs scrub_all_objects() on optimised EC pools when the
test has not already failed: it lists the primary's collection and
scrubs each object (skipping ones the ObjectTracker says were deleted),
so any inconsistency left behind by a test fails it.

scrub_object() gains a skip_verify flag.  Unless it is set, after the
scrub-map comparison it also reads every shard's attributes directly
from the store and compares them with the primary's (ignoring
nonprimary shards, which legitimately lag), reporting count, value and
extra-attribute mismatches as corruption, and finally runs
verify_object() against the tracker.  Tests that deliberately corrupt a
shard pass skip_verify=true.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
…y from the OSDMap

Move the peering fixture onto OsdTestFixture/TestPG.  The four spg_t-keyed
maps (pg_states, pg_ctxs, pg_listeners, pg_dpps) go away; each TestPG now
owns its ShardDpp, MockPeeringListener, PeeringState and PeeringCtx.

Instead of creating k+m peering states up front in SetUp(), the fixture
returns false from should_create_test_pgs_upfront() and builds them as
the OSDMap is published:

- event_advance_map() first ensures an OsdTestFixture exists for every
  OSD in the map (ensure_osd_fixture_exists(): store + LRU), then
  schedules advance_map_impl() on each OSD.
- advance_map_impl() runs as that OSD: for every shard position the OSD
  holds in the up set it calls ensure_test_pg_exists(), which creates
  the TestPG, its collection, ShardDpp, backend listener, ECSwitch and
  MockPeeringListener, constructs the PeeringState via
  create_peering_state_common(), runs init_peering() for that PG and
  queues the Initialize event.  It then schedules advance_map() for each
  parent-PG TestPG on the OSD.
- create_child_peering_state() (used by split_pg()) goes through the
  same OsdTestFixture/TestPG path and create_peering_state_common().

Because a TestPG is created for whatever (osd, shard) the OSDMap
reports, shard N no longer has to live on OSD N; this is what the
CRUSH-driven fixture in a later commit relies on.

Lookups: get_peering_state/ctx/listener(shard) go through
find_test_pg_for_shard() (acting-set lookup, falling back to a scan of
all fixtures so a down OSD's PG can still be found); no-arg overloads
use the EventLoop's current TestPG.  get_primary_listener()/backend(),
get_child_peering_state(), all_shards_active(), all_shards_clean(),
get_state_name(), inject_read_error_for_shard(), apply_new_epoch(),
split_pg() and queue_transaction_helper() (now taking a TestPG*) all
resolve their store/collection/state through TestPG.

update_osdmap_with_peering() no longer calls the base update_osdmap()
(whose on_change() scheduling is now done by MockPeeringListener); it
sets the new map on the fixture, bumps every listener's current_epoch,
updates each backend listener's osdmap/PGPool, and runs
new_epoch_loop().  event_initialize(), run_first_peering() and the
dne parameter of init_peering() are gone with the upfront creation.

The recovery helpers only get the mechanical store/collection lookup
change here; they are reworked in a later commit.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
…) extension points

Two virtual hooks so a derived fixture can drive placement through a
real CRUSH map instead of the shard == osd pg_upmap:

- use_upmap() (default true) guards installation of the pg_upmap in
  SetUp(); the upmap loop now runs over get_instance_count() rather
  than k + m so it also covers multi-zone pools.
- pre_peering_hook() (default no-op) is called after the messenger and
  idle callback are wired but before the first new_epoch_loop(), which
  is the point at which an OSDMap rewrite must happen to affect the
  initial peering cycle.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
Snapshot g_ceph_context's config values at the start of SetUp() and put
them back in TearDown(), so set_config() calls made by a test cannot
leak into the next parameterisation.

RollbackAfterMixedBlockedWritesWithOSDFailure3 no longer needs to undo
its osd_async_recovery_min_cost change by hand.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
Wrapper around OSDMapTestHelpers::set_pool_min_size() that copies the
current map, applies the change and runs a peering cycle, matching
mark_osd_down()/mark_osd_up()/advance_epoch().

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
…is_clean()

The function only ever checked the primary (in EC pools only the
primary tracks PG_STATE_CLEAN), so name it for what it does and update
the callers and their assertion messages.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
…r_primary

run_recovery_and_verify_callbacks(obj, removed_osd, data) and its
parallel variant took the OSD that had been down and derived the target
shard as pg_shard_t(osd, osd).  That only works while shard == osd.
Replace them with run_recovery(obj, recover_primary, data) and
run_parallel_recovery(objs, recover_primary, datas):

- recover_primary == true checks the primary's own missing set;
  otherwise the helper walks the primary's peer_missing map, checks each
  entry against that peer's actual missing set, and uses the first
  peer that is missing the object.  The peer's OI is no longer re-read
  from the primary's store.
- Callback/data verification moves out of the impl (which runs inside a
  scheduled TRANSACTION event) into run_parallel_recovery() after the
  event loop has drained, because read_object() drains the loop itself
  and doing that re-entrantly could interleave with in-flight recovery
  messages and duplicate an EC read tid.
- The impl is scheduled from inside EventLoop::run_in_pg() so
  schedule_transaction() captures the primary's TestPG context rather
  than whatever the previous event left behind.
- After recovery, check_recovery_completion_impl() runs on every acting
  OSD and, if the PG is RECOVERING with nothing left to recover, clears
  the state and queues RequestBackfill or AllReplicasRecovered, as
  PrimaryLogPG::start_recovery_ops() does.

Callers in TestECFailoverWithPeering pass recover_primary as
(removed_osd == 0) where the loop variable can be the primary, and
true/false where it is fixed.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
…he rollback tests

Pure move, no change to the test body.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
- Look up peering state, listeners and backends via get_primary_test_pg(),
  get_test_pg_by_shard(), get_first_test_pg_for_osd() and
  get_test_pg(osd, shard) instead of the shard-indexed accessors, and
  read a recovered attribute through the OSD fixture's store and the
  TestPG's collection handle.
- Use the tracker-backed verify_object(obj_name) where the expected
  contents were the last thing written, and read_object() where the
  test measures the read itself.
- Pass num_zones from BackendConfig (every config here uses 1) and
  skip MultipleOSDFailuresWithPeering unless num_zones == 1;
  ECRecoveryTest, ECSequentialOSDFailoverTest and the new-OSD id are
  sized by num_zones.
- ScrubDetectsCorruption passes skip_verify=true to scrub_object() and
  deletes the object it corrupted so the TearDown scrub does not report
  it.
- Many EXPECT_* become ASSERT_* so a failed precondition stops the test
  instead of cascading.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
…TrackerDetectsCorruption and OSD0DownAddNewOSDRecovery

- RollbackBlockedWrite: for each pair of (blocked, failed) shards drawn
  from shards 0, 1 and k in every zone, blocks a full-stripe write and
  an attribute write to one shard, fails another, releases both, and
  verifies the object rolled back to its original contents and that a
  scrub finds the attributes consistent across shards.
- ObjectTrackerDetectsCorruption: corrupts the primary shard and checks
  that verify_object() reports a data mismatch (via
  EXPECT_FATAL_FAILURE) and that scrub_object() detects it when the
  plugin stores per-shard CRCs (ISA) and does not for jerasure.
- OSD0DownAddNewOSDRecovery: fails OSD 0, adds a brand-new OSD at shard
  0 with OSDMapTestHelpers::new_osd_up(), re-peers, and recovers to it.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
ECCrushTestFixture derives from ECPeeringTestFixture, returns false
from use_upmap() and uses pre_peering_hook() to replace the minimal
CRUSH map from setup_ec_pool() with build_simple_crush_map() plus an
indep erasure rule ("ec_rule", failure domain osd), point the pool at
that rule, and remove the pg_temp, so the initial peering cycle is
placed by CRUSH.  num_zones > 1 aborts; the intended stretch topology is
documented in the header for the follow-up that implements it.

TestECWithCRUSH is parameterised over the same ISA/jerasure k+m/stripe
configurations as the failover tests and has one sanity test,
BasicWriteVerify, that peers, writes a full stripe and verifies it.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
Standalone gtest for osdc/SplitOp.h that needs no OSDMap, peering or
IO path: ECStripeIterator/ECStripeView geometry over several (offset,
length, k, chunk_size) combinations, the reference-sub-read abs_shard
formula for multi-zone pools, and the replica LOCALIZE_READS zone
filtering ranges.  Unrelated to the fixture rework in the preceding
commits.

The test lives in src/test/osdc/test_splitop.cc rather than under
src/test/osd, so that it mirrors the location of the code it covers
(src/osdc/SplitOp.{h,cc}).  It also needs no OSD library: SplitOp.cc is
compiled into libcommon rather than into the osdc library (see
src/CMakeLists.txt), and libcommon comes in via global, so the target
links against global alone.

Assisted-by: IBM Bob v2.1.0
Assisted-by: Claude Code:Claude Opus 5/Claude Opus 4.8/Claude Sonnet 5
Signed-off-by: Alex Ainscow <[email protected]>
@aainscow
aainscow force-pushed the stretchy-C-tests-only branch from e6300ae to 9570fa8 Compare October 2, 2026 11:51

@bill-scales bill-scales left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - one misalignment nit still

// TestPG, not in OsdTestFixture. CRUSH may place shard N on any OSD, so
// shard_id != osd_id in general.
TestPG* test_pg = osd_fixture->create_pg(shard_spgid, pg_whoami);
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: still misaligned

@aainscow
aainscow merged commit c5f516a into ceph:main Oct 2, 2026
14 checks passed
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I have resolved the following tracker ticket due to the merge of this PR:

No backports are pending for the ticket. If this is incorrect, please update the tracker
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/37019960555

MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 7, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
@MaxKellermann MaxKellermann mentioned this pull request Oct 7, 2026
4 of 14 tasks
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 8, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 9, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 9, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
@aainscow aainscow added the no-backport-required Label that can be optionally added to show that we do not need to backport. label Oct 12, 2026
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 12, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 12, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 13, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 13, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 13, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 13, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
MaxKellermann added a commit to MaxKellermann/ceph that referenced this pull request Oct 14, 2026
Bug introduced by commit c9d0c5e
("test/osd: OSDMapTestHelpers: add pool min_size and OSD add/upmap
helpers") from PR ceph#71844 (@aainscow).

Signed-off-by: Max Kellermann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build/ops core no-backport-required Label that can be optionally added to show that we do not need to backport. tests

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants