osd: don't let a timed-out PG state report overwrite a newer one #183

Open
koolkhel wants to merge 2 commits from koolkhel/vitastor:pg-state-stale-txn into master
Contributor

Description

A PG state report that timed out on the client may still be applied by etcd after the newer report sent by the retry. The HTTP client closes the connection on timeout and the retry goes to the next etcd address, so the old txn can reach the raft log after the new one. Its only compare for an existing key, LEASE == ours, holds for every write of this OSD process. The old txn then put back an old state (peering) or deleted the key of an active PG (an offline report). The OSD never wrote the key again: nothing marks the PG dirty, and apply_pg_config() skips an unchanged PG. So the PG stayed offline (no key) or peering in etcd, and the pool stayed inactive until the OSD restarted.

The fix adds MOD < max(etcd_watch_revision_pg, revision of our last successful report) + 1 next to the LEASE compare, like the /pg/history put already does. A txn built before a newer write now fails if etcd applies it later. The revision of our own last write comes from the txn response, so back-to-back reports (peering -> active) don't wait for the watcher. After a timeout whose txn was applied, the next report fails until the watcher delivers that revision, the same as the VERSION 0 case does today.

On a failed compare, the OSD now also prints the state keys that failed it: the value, lease and mod_revision found, and what was expected. Before this, the error line carried an empty message and said nothing about which compare failed.

Not covered: a timed-out VERSION 0 create (the first report of a PG that has no key yet) that lands after the OSD has stopped the PG, reported offline (deleting nothing) and forgotten it. The key then names this OSD as primary of a PG it doesn't hold, and the new primary won't take it until this OSD's lease ends. A compare on the key alone can't reject that create. It would need the OSD to delete state keys that name it for PGs it doesn't hold.

Found: the symptom was seen on a 16-node test stand with 3840 OSDs at cold start with etcd overloaded: in 1 run of 2, 4 PGs had no /pg/state key, or a stale "peering" one, for more than 9 minutes. The cause is inferred from the code; it was not confirmed on that stand.

Tested: osd_test. The new test_stale_pg_state_report fails without the fix (the old txn succeeds and puts peering back). With the fix all 80 tests pass, and the other tests show the same report errors as before. The race wasn't reproduced against a real etcd; the test reproduces it with the etcd mock.

Contributor Name

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

CLA

### Description A PG state report that timed out on the client may still be applied by etcd after the newer report sent by the retry. The HTTP client closes the connection on timeout and the retry goes to the next etcd address, so the old txn can reach the raft log after the new one. Its only compare for an existing key, `LEASE == ours`, holds for every write of this OSD process. The old txn then put back an old state (`peering`) or deleted the key of an active PG (an `offline` report). The OSD never wrote the key again: nothing marks the PG dirty, and `apply_pg_config()` skips an unchanged PG. So the PG stayed `offline` (no key) or `peering` in etcd, and the pool stayed inactive until the OSD restarted. The fix adds `MOD < max(etcd_watch_revision_pg, revision of our last successful report) + 1` next to the `LEASE` compare, like the `/pg/history` put already does. A txn built before a newer write now fails if etcd applies it later. The revision of our own last write comes from the txn response, so back-to-back reports (peering -> active) don't wait for the watcher. After a timeout whose txn *was* applied, the next report fails until the watcher delivers that revision, the same as the `VERSION 0` case does today. On a failed compare, the OSD now also prints the state keys that failed it: the value, lease and mod_revision found, and what was expected. Before this, the error line carried an empty message and said nothing about which compare failed. Not covered: a timed-out `VERSION 0` create (the first report of a PG that has no key yet) that lands after the OSD has stopped the PG, reported `offline` (deleting nothing) and forgotten it. The key then names this OSD as primary of a PG it doesn't hold, and the new primary won't take it until this OSD's lease ends. A compare on the key alone can't reject that create. It would need the OSD to delete state keys that name it for PGs it doesn't hold. Found: the symptom was seen on a 16-node test stand with 3840 OSDs at cold start with etcd overloaded: in 1 run of 2, 4 PGs had no /pg/state key, or a stale "peering" one, for more than 9 minutes. The cause is inferred from the code; it was not confirmed on that stand. Tested: `osd_test`. The new `test_stale_pg_state_report` fails without the fix (the old txn succeeds and puts `peering` back). With the fix all 80 tests pass, and the other tests show the same report errors as before. The race wasn't reproduced against a real etcd; the test reproduces it with the etcd mock. ### 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-25 03:04:52 +03:00
A PG state report that timed out on the client may still be applied by
etcd after the newer report sent by the retry, which goes to the next
etcd address. Its only compare, LEASE == ours, holds for every write of
this OSD, so the old txn put back an old state ("peering") or deleted
the key of an active PG, and the OSD never wrote it again: the PG stayed
"offline" or "peering" in etcd until the OSD was restarted.

Also require the state key to be unchanged since our last successful
write, like the /pg/history put already does, and print the state keys
that failed a compare.
koolkhel added 1 commit 2026-11-25 06:07:56 +03:00
The mock's range results had no lease, so the failed-report diagnostic
blamed the lease for every compare failure in tests. Return it as etcd
does, and read both PG keys in the tests through one helper.
This pull request has changes conflicting with the target branch.
  • src/test/osd_test.cpp
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u pg-state-stale-txn:koolkhel-pg-state-stale-txn
git checkout koolkhel-pg-state-stale-txn
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#183
No description provided.