Store v1: Fix two flusher hangs with deletions #114

Open
koolkhel wants to merge 3 commits from koolkhel/vitastor:v1-lost-flush into master
Contributor

Description

This is v2 of the patches sent to you on 2026-10-21. Following your review, the flush check of patch 1 runs only with the new --hardened option of test_blockstore_chaos, because it scans all of dirty_db; patch 2's subject names the option. Patches 2 and 3 are unchanged otherwise.

Under sustained load, an OSD on store v1 can stop accepting writes for good: its journal fills up, every write fails with EAGAIN, and the client retries forever, so all I/O touching that OSD hangs until the OSD restarts. We hit it with an NFS server that reuses inode numbers, so the data objects of deleted files are deleted and rewritten from version 1 all the time. The gateway stalled after 4-8 minutes of S3 load. gdb on the stuck OSD showed the full journal pinned by one stable BIG_WRITE entry at used_start, which was not in the flush queue.

1. Check that stable versions get flushed in test_blockstore_chaos --hardened

  • A lost flush shows only as writes refused with EAGAIN, which the test accepts as journal pressure. With the new --hardened option, the test checks after every drain that the newest stable version of every object is being flushed, or queued under a version that is still in dirty_db and not older than it.
  • The check scans all of dirty_db, so it is off by default.
  • With it, --p-delete 30 finds lost flushes on master: --seed 285 --config 21, --seed 112 --config 21, --seed 118 --config 21, --seed 439 --config 18 and 19, all with --hardened --steps 30000 --p-delete 30.

2. Store v1: Do not queue a deletion for flushing again while it is being flushed (reworked after your review, 2026-11-02)

  • A write over a deletion asks for the deletion to be flushed first. If the flusher is already flushing it, that queues the deletion a second time, and the queued entry outlives the deletion.
  • Versions restart from 1 after a deletion. Once the write is renumbered and becomes stable, queueing it is ignored because the stale queued version is higher; the flusher skips the deletion it can't find, and the write is never flushed.
  • Fix: if the object is being flushed right now (it is in sync_to_repeat), the write doesn't queue the deletion again but raises the repeat version, so the flush in progress requeues the object when it finishes, as it already does for versions that come up during a flush. The earlier is_gone() check is gone.

3. Store v1: Wake up the flusher when journal sectors are written

  • The flusher puts back entries whose journal sector isn't written yet and stops when nothing else is flushable. Writing the sector moves dirty_start, but nothing woke the flusher, so writes waiting for journal space or for a deletion hung with a full queue of flushable entries.
  • It happens with immediate_commit=all too: --seed 5 --config 12 --steps 30000 --p-delete 30 deadlocks on master.
  • Note: with the reworked commit 2, --seed 5 --config 12 passes without this commit too (the flush order changes and the seed no longer reaches the hang), and it passes on master with this commit alone. A sweep of seeds 1-200 on every v1 configuration (2,400 runs, --hardened --steps 30000 --p-delete 30) without it found no hang. The missing wakeup is still in the code, so the commit stays; drop it if you want a seed for it first.

3cf04530 ("Fix exotic hang on an unflushable deletion") does not cure either case: all the seeds above fail on master, which includes it.

Testing (Ubuntu 24.04, RelWithDebInfo; the reworked series on a7a6d5f3):

  • The seeds above fail with commit 1 alone when run with --hardened, pass without it, and pass with the whole series either way.
  • --hardened changes nothing measurable in the test itself: 48 seeds with default weights take 37.85 s without it and 37.87 s with it, because the check runs only at clean restarts and at the end.
  • On a7a6d5f3 with the reworked series: test_blockstore_v1 passes, all six seeds above pass, and so does a default 200-seed run of test_blockstore_chaos --hardened.
  • With the earlier version of commit 2 (on 3e803e07): make build_tests test, as in .gitea/workflows/test.yml: 15 of 15 tests pass, including test_blockstore_chaos (default run, 200 seeds) and test_pg_chaos.
  • With the earlier version of commit 2: the same three changes (modulo names) run in our product. With them, the S3 load that stalled ran three times on a 5-VM, 25-OSD cluster without a stall and with no EAGAIN in the OSD logs. A sweep of 1,500 seeds on each of the 12 v1 configurations (--steps 30000 --p-delete 30, 18,000 runs) found no lost flush and no deadlock.

Not included: with --p-delete 30 the chaos test also fails on master in other ways that this series doesn't change. A deleted object comes back after a clean restart (--seed 1064 --config 12). There is "BUG: Unexpected dirty_entry ... unstable state during flush" with fsync=1 (--seed 60 --config 21). "big_write journal_entry was allocated over another object" (--seed 144 --config 15). And unexpected content after a power outage (--seed 841 --config 20). A follow-up series fixes them. It builds on this one, so it will come as a separate PR once this one is merged.

Contributor Name

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

CLA

### Description This is v2 of the patches sent to you on 2026-10-21. Following your review, the flush check of patch 1 runs only with the new `--hardened` option of test_blockstore_chaos, because it scans all of dirty_db; patch 2's subject names the option. Patches 2 and 3 are unchanged otherwise. Under sustained load, an OSD on store v1 can stop accepting writes for good: its journal fills up, every write fails with EAGAIN, and the client retries forever, so all I/O touching that OSD hangs until the OSD restarts. We hit it with an NFS server that reuses inode numbers, so the data objects of deleted files are deleted and rewritten from version 1 all the time. The gateway stalled after 4-8 minutes of S3 load. gdb on the stuck OSD showed the full journal pinned by one stable BIG_WRITE entry at used_start, which was not in the flush queue. **1. Check that stable versions get flushed in test_blockstore_chaos --hardened** - A lost flush shows only as writes refused with EAGAIN, which the test accepts as journal pressure. With the new `--hardened` option, the test checks after every drain that the newest stable version of every object is being flushed, or queued under a version that is still in dirty_db and not older than it. - The check scans all of dirty_db, so it is off by default. - With it, `--p-delete 30` finds lost flushes on master: `--seed 285 --config 21`, `--seed 112 --config 21`, `--seed 118 --config 21`, `--seed 439 --config 18` and `19`, all with `--hardened --steps 30000 --p-delete 30`. **2. Store v1: Do not queue a deletion for flushing again while it is being flushed** (reworked after your review, 2026-11-02) - A write over a deletion asks for the deletion to be flushed first. If the flusher is already flushing it, that queues the deletion a second time, and the queued entry outlives the deletion. - Versions restart from 1 after a deletion. Once the write is renumbered and becomes stable, queueing it is ignored because the stale queued version is higher; the flusher skips the deletion it can't find, and the write is never flushed. - Fix: if the object is being flushed right now (it is in `sync_to_repeat`), the write doesn't queue the deletion again but raises the repeat version, so the flush in progress requeues the object when it finishes, as it already does for versions that come up during a flush. The earlier `is_gone()` check is gone. **3. Store v1: Wake up the flusher when journal sectors are written** - The flusher puts back entries whose journal sector isn't written yet and stops when nothing else is flushable. Writing the sector moves dirty_start, but nothing woke the flusher, so writes waiting for journal space or for a deletion hung with a full queue of flushable entries. - It happens with immediate_commit=all too: `--seed 5 --config 12 --steps 30000 --p-delete 30` deadlocks on master. - Note: with the reworked commit 2, `--seed 5 --config 12` passes without this commit too (the flush order changes and the seed no longer reaches the hang), and it passes on master with this commit alone. A sweep of seeds 1-200 on every v1 configuration (2,400 runs, `--hardened --steps 30000 --p-delete 30`) without it found no hang. The missing wakeup is still in the code, so the commit stays; drop it if you want a seed for it first. 3cf04530 ("Fix exotic hang on an unflushable deletion") does not cure either case: all the seeds above fail on master, which includes it. **Testing** (Ubuntu 24.04, RelWithDebInfo; the reworked series on a7a6d5f3): - The seeds above fail with commit 1 alone when run with `--hardened`, pass without it, and pass with the whole series either way. - `--hardened` changes nothing measurable in the test itself: 48 seeds with default weights take 37.85 s without it and 37.87 s with it, because the check runs only at clean restarts and at the end. - On a7a6d5f3 with the reworked series: `test_blockstore_v1` passes, all six seeds above pass, and so does a default 200-seed run of `test_blockstore_chaos --hardened`. - With the earlier version of commit 2 (on 3e803e07): `make build_tests test`, as in `.gitea/workflows/test.yml`: 15 of 15 tests pass, including `test_blockstore_chaos` (default run, 200 seeds) and `test_pg_chaos`. - With the earlier version of commit 2: the same three changes (modulo names) run in our product. With them, the S3 load that stalled ran three times on a 5-VM, 25-OSD cluster without a stall and with no EAGAIN in the OSD logs. A sweep of 1,500 seeds on each of the 12 v1 configurations (`--steps 30000 --p-delete 30`, 18,000 runs) found no lost flush and no deadlock. **Not included:** with `--p-delete 30` the chaos test also fails on master in other ways that this series doesn't change. A deleted object comes back after a clean restart (`--seed 1064 --config 12`). There is "BUG: Unexpected dirty_entry ... unstable state during flush" with fsync=1 (`--seed 60 --config 21`). "big_write journal_entry was allocated over another object" (`--seed 144 --config 15`). And unexpected content after a power outage (`--seed 841 --config 20`). A follow-up series fixes them. It builds on this one, so it will come as a separate PR once this one is merged. ### 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 3 commits 2026-10-27 10:26:39 +03:00
A store v1 stable version that no flush reaches pins the journal for
good, and the store only shows it as writes refused with EAGAIN, which
the test takes for journal pressure. With --hardened, check after every
drain that the newest stable version of every object is being flushed,
or queued under a version that is still in dirty_db and not older than
it. The check scans all of dirty_db, so it is off by default.
The flush queue keeps one version per object, the highest one queued.
A write over a deletion asks for the deletion to be flushed, and if the
flusher is already flushing it, that queues the deletion again. Once the
deletion is gone, the write is renumbered from version 1, and queueing it
is ignored because the queued deletion version is higher. The flusher
then skips the deletion it can't find, the write is never flushed, and
the journal can't be trimmed past it: it fills up and every write fails
with EAGAIN until a restart.

Replace a queued version that is no longer in dirty_db with the one
being queued. Objects that are deleted and rewritten over and over run
into this regularly; ours were the data of an NFS server that reuses
inode numbers.
The flusher puts back the entries whose journal sector isn't written yet
and stops when it finds nothing else to flush. Writing the sector moves
dirty_start and makes them flushable, but nothing woke the flusher then:
when the writes waiting for journal space or for a deletion were the only
thing left, they hung forever, with the queue full of flushable entries
and a trim requested. Happens with immediate_commit=all too.
Owner

Мне тут не нравится вот этот фикс

  1. Store v1: Do not lose the flush of a write over a deletion

The write is renumbered from version 1 once the deletion is gone, and queueing it is ignored because the queued deletion version is higher. The flusher skips the deletion it can't find, so the write is never flushed and the journal can't be trimmed past it.

Сфигали в очередь flush добавляется write одновременно с уже находящимся там delete, если write произошёл ПОВЕРХ этого самого delete, и должен его дождаться? Вот это выглядит как баг и выглядит что именно это править надо, а не просто накрывать проверкой if is_gone.

Мне тут не нравится вот этот фикс >2. Store v1: Do not lose the flush of a write over a deletion >The write is renumbered from version 1 once the deletion is gone, and queueing it is ignored because the queued deletion version is higher. The flusher skips the deletion it can't find, so the write is never flushed and the journal can't be trimmed past it. Сфигали в очередь flush добавляется write одновременно с уже находящимся там delete, если write произошёл ПОВЕРХ этого самого delete, и должен его дождаться? Вот это выглядит как баг и выглядит что именно это править надо, а не просто накрывать проверкой if is_gone.
Owner

Проверил все указанные сиды - они не падают.

Проверил все указанные сиды - они не падают.
Author
Contributor

Опции --hardened на master нет, она добавляется первым коммитом этого PR: 80ef5486 «Check that stable versions get flushed in test_blockstore_chaos --hardened». Без неё сиды ниже ничего не проверяют. Чтобы повторить, нужен этот коммит поверх master (ставится чисто) или просто ветка PR:

git fetch https://git.yourcmc.ru/koolkhel/vitastor.git v1-lost-flush
git cherry-pick 80ef5486

Пять из шести сидов (285, 112, 118 на --config 21, 439 на --config 18 и 19) завязаны на --hardened из первого коммита. Без неё они на master и не должны падать: потерянный flush тогда виден только как EAGAIN, а за 30000 шагов до него не доходит. На master этой опции нет (Unknown option --hardened), а на master + первый коммит они падают так:

test_blockstore_chaos --hardened --seed 285 --config 21 --steps 30000 --p-delete 30
step 2502: 1 stable version(s) will never be flushed: 1:40000 v1

(112 — step 19404, 118 — step 27050, 439 — step 26602). То есть это сиды на то, что ловит проверка: stable-версия, которую flusher уже никогда не сбросит. Считать ли это настоящим багом — решать тебе. У нас из-за этого вставала запись на OSD под нагрузкой, это и было поводом для PR.

Шестой, --seed 5 --config 12 --steps 30000 --p-delete 30, от --hardened не зависит и на текущем master (a7a6d5f3) виснет: stuck: write 1:60000 v4 16384+77824, stuck: write 1:40000 v2 4096+16384. Нужны оба параметра: без --steps 30000 или без --p-delete 30 он проходит.

Опции `--hardened` на master нет, она добавляется первым коммитом этого PR: 80ef5486 «Check that stable versions get flushed in test_blockstore_chaos --hardened». Без неё сиды ниже ничего не проверяют. Чтобы повторить, нужен этот коммит поверх master (ставится чисто) или просто ветка PR: ``` git fetch https://git.yourcmc.ru/koolkhel/vitastor.git v1-lost-flush git cherry-pick 80ef5486 ``` Пять из шести сидов (285, 112, 118 на `--config 21`, 439 на `--config 18` и `19`) завязаны на `--hardened` из первого коммита. Без неё они на master и не должны падать: потерянный flush тогда виден только как EAGAIN, а за 30000 шагов до него не доходит. На master этой опции нет (`Unknown option --hardened`), а на master + первый коммит они падают так: ``` test_blockstore_chaos --hardened --seed 285 --config 21 --steps 30000 --p-delete 30 step 2502: 1 stable version(s) will never be flushed: 1:40000 v1 ``` (112 — step 19404, 118 — step 27050, 439 — step 26602). То есть это сиды на то, что ловит проверка: stable-версия, которую flusher уже никогда не сбросит. Считать ли это настоящим багом — решать тебе. У нас из-за этого вставала запись на OSD под нагрузкой, это и было поводом для PR. Шестой, `--seed 5 --config 12 --steps 30000 --p-delete 30`, от `--hardened` не зависит и на текущем master (a7a6d5f3) виснет: `stuck: write 1:60000 v4 16384+77824`, `stuck: write 1:40000 v2 4096+16384`. Нужны оба параметра: без `--steps 30000` или без `--p-delete 30` он проходит.
koolkhel force-pushed v1-lost-flush from 8ac5cb9510 to 80cd77c09d 2026-11-02 17:18:38 +03:00 Compare
Author
Contributor

Переделал второй коммит, как ты написал, и запушил; ветка заодно перебазирована на текущий master (a7a6d5f3).

Ты прав, баг был именно там. Трассировка --hardened --seed 285 --config 21 по объекту 1:40000:

  • flusher начинает сбрасывать удаление v5;
  • приходит запись поверх удаления (временно v6) и через unshift_stable_flush() ставит в очередь то же удаление v5 второй раз, хотя его уже сбрасывают;
  • flush заканчивается, удаление стёрто, запись перенумерована в v1;
  • enqueue_flush(v1) игнорируется: в flush_versions для объекта висит устаревшая v5, она больше;
  • v5 из очереди пропускается как уже сброшенная, а v1 так и не сбрасывается.

Теперь, если объект сейчас сбрасывается (есть в sync_to_repeat), запись поверх удаления не ставит удаление в очередь заново, а только поднимает версию повтора. После текущего flush объект перепоставится, как для любых версий, пришедших во время flush. is_gone() убран.

Про третий коммит (будить flusher при записи секторов журнала): --seed 5 --config 12 --steps 30000 --p-delete 30 теперь проходит и с одним новым вторым коммитом (порядок flush другой, и до зависания seed не доходит), и на master с одним третьим. Свип seed 1–200 по всем v1-конфигурациям (2400 прогонов, --hardened --steps 30000 --p-delete 30) без третьего коммита зависаний не нашёл. Сама дыра в коде осталась: flusher откладывает записи, чей сектор журнала ещё не записан, и останавливается, а запись сектора его не будит. Поэтому коммит я оставил. Если без отдельного seed не возьмёшь, скажи, уберу его из PR.

Проверено на весь PR: все шесть seed из описания, test_blockstore_v1, test_blockstore_chaos --hardened (200 seed по умолчанию). Описание PR обновил.

Переделал второй коммит, как ты написал, и запушил; ветка заодно перебазирована на текущий master (a7a6d5f3). Ты прав, баг был именно там. Трассировка `--hardened --seed 285 --config 21` по объекту `1:40000`: - flusher начинает сбрасывать удаление v5; - приходит запись поверх удаления (временно v6) и через `unshift_stable_flush()` ставит в очередь то же удаление v5 второй раз, хотя его уже сбрасывают; - flush заканчивается, удаление стёрто, запись перенумерована в v1; - `enqueue_flush(v1)` игнорируется: в `flush_versions` для объекта висит устаревшая v5, она больше; - v5 из очереди пропускается как уже сброшенная, а v1 так и не сбрасывается. Теперь, если объект сейчас сбрасывается (есть в `sync_to_repeat`), запись поверх удаления не ставит удаление в очередь заново, а только поднимает версию повтора. После текущего flush объект перепоставится, как для любых версий, пришедших во время flush. `is_gone()` убран. Про третий коммит (будить flusher при записи секторов журнала): `--seed 5 --config 12 --steps 30000 --p-delete 30` теперь проходит и с одним новым вторым коммитом (порядок flush другой, и до зависания seed не доходит), и на master с одним третьим. Свип seed 1–200 по всем v1-конфигурациям (2400 прогонов, `--hardened --steps 30000 --p-delete 30`) без третьего коммита зависаний не нашёл. Сама дыра в коде осталась: flusher откладывает записи, чей сектор журнала ещё не записан, и останавливается, а запись сектора его не будит. Поэтому коммит я оставил. Если без отдельного seed не возьмёшь, скажи, уберу его из PR. Проверено на весь PR: все шесть seed из описания, `test_blockstore_v1`, `test_blockstore_chaos --hardened` (200 seed по умолчанию). Описание PR обновил.
Checking for merge conflicts ...
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u v1-lost-flush:koolkhel-v1-lost-flush
git checkout koolkhel-v1-lost-flush
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#114
No description provided.