osd: Don't mark a copy of a chained read's layer object lost on ENOENT from a racing delete #168

Merged
vitalif merged 1 commits from koolkhel/vitastor:chain-read-enoent-race into master 2026-11-24 03:53:40 +03:00
Contributor

Description

A chained read (a clone or a snapshot child) can read a parent layer object's bitmap before a delete of that object and its data after it. The data read answers ENOENT. Chained reads never set OP_DATA_ENOENT_OK and have no racing-op check like continue_primary_read(), so check_corrupted_chained() marked that copy as missing:

  1. The parent object becomes degraded: its healthy copy is dropped from its OSD set, although the read itself is then served from the other copy.
  2. The delete had seen no object state when it started, so on completion it only decrements clean_count and leaves the new degraded state behind: the deleted object stays degraded.
  3. Recovery of that (deleted) object then gets ENOENT from the other copy too and turns it incomplete, and the next chained read of it hits assert(read_target != 0) in collect_bitmap_requests(), aborting the OSD (reproduced on a downstream tree; the same assert is on master).

Fix: treat ENOENT the way plain reads do. While a write or delete runs on the object (it is in pg->write_queue), or when the object is clean and every part read answered ENOENT (the OP_DATA_ENOENT_OK rule for clean objects), the object was deleted under the read, so the copy is not marked. The existing retry reads the bitmaps again; a store zeroes the bitmap of a deleted object, so the retry no longer reads that layer.

  • An EC part that returned data, or failed with a real EIO, still counts against "every part answered ENOENT", so a clean EC object with one missing chunk is still marked, as before.
  • The window is small: the delete has to be queued in the store between the read's bitmap read and its data read (one event loop iteration for the local copy, a round trip for a remote one), and something has to delete a layer object that a chained read still goes through (a lagging client or OSD across a layer removal, or a manual delete). Found by code review, then reproduced in osd_test.
  • Like #167, the test touches capturing_bs_t::read_bitmap() in the fixture with exactly the same hunk, so the two don't conflict with each other; #158 changes the same function, and whichever goes in later I'll rebase.

Tested: new test_chained_read_enoent_races_parent_delete(false/true) in osd_test (legacy delete and tombstones): replicated pool, child and parent layers, the parent object clean on both OSDs, the delete applied locally and in flight to the peer when the chained read gets ENOENT. Without the fix the parent object is degraded right after the ENOENT and stays degraded after the delete; with it the PG stays active and clean and the read returns. The whole osd_test passes.

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description A chained read (a clone or a snapshot child) can read a parent layer object's bitmap before a delete of that object and its data after it. The data read answers ENOENT. Chained reads never set `OP_DATA_ENOENT_OK` and have no racing-op check like `continue_primary_read()`, so `check_corrupted_chained()` marked that copy as missing: 1. The parent object becomes degraded: its healthy copy is dropped from its OSD set, although the read itself is then served from the other copy. 2. The delete had seen no object state when it started, so on completion it only decrements `clean_count` and leaves the new degraded state behind: the deleted object stays degraded. 3. Recovery of that (deleted) object then gets ENOENT from the other copy too and turns it incomplete, and the next chained read of it hits `assert(read_target != 0)` in `collect_bitmap_requests()`, aborting the OSD (reproduced on a downstream tree; the same assert is on master). Fix: treat ENOENT the way plain reads do. While a write or delete runs on the object (it is in `pg->write_queue`), or when the object is clean and every part read answered ENOENT (the `OP_DATA_ENOENT_OK` rule for clean objects), the object was deleted under the read, so the copy is not marked. The existing retry reads the bitmaps again; a store zeroes the bitmap of a deleted object, so the retry no longer reads that layer. - An EC part that returned data, or failed with a real EIO, still counts against "every part answered ENOENT", so a clean EC object with one missing chunk is still marked, as before. - The window is small: the delete has to be queued in the store between the read's bitmap read and its data read (one event loop iteration for the local copy, a round trip for a remote one), and something has to delete a layer object that a chained read still goes through (a lagging client or OSD across a layer removal, or a manual delete). Found by code review, then reproduced in `osd_test`. - Like #167, the test touches `capturing_bs_t::read_bitmap()` in the fixture with exactly the same hunk, so the two don't conflict with each other; #158 changes the same function, and whichever goes in later I'll rebase. Tested: new `test_chained_read_enoent_races_parent_delete(false/true)` in `osd_test` (legacy delete and tombstones): replicated pool, child and parent layers, the parent object clean on both OSDs, the delete applied locally and in flight to the peer when the chained read gets ENOENT. Without the fix the parent object is degraded right after the ENOENT and stays degraded after the delete; with it the PG stays active and clean and the read returns. The whole `osd_test` passes. ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-24 02:54:16 +03:00
Chained reads never set OP_DATA_ENOENT_OK and have no racing-op check,
so a chained read that read a parent layer object's bitmap before a
delete of that object and its data after it marked the copy as missing.
The object became degraded, and the delete, which had seen no object
state when it started, left it degraded after the object was gone.
Recovery then turned it incomplete, and the next chained read of it
hit assert(read_target != 0).

Treat ENOENT as continue_primary_read() does: while a write or delete
runs on the object, or when the object is clean and every part read
answered ENOENT, it was deleted under the read. Don't mark it; the
retry reads the bitmaps again.
vitalif merged commit 2df2a50b2f into master 2026-11-24 03:53:40 +03:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#168
No description provided.