Store v1: Fix three journal replay bugs #157

Open
koolkhel wants to merge 4 commits from koolkhel/vitastor:v1-replay-fixes into master
Contributor

Description

Three store v1 journal replay bugs, found with test_blockstore_chaos --p-delete 30 after #114. Each commit names a seed that fails before it and passes with it.

1. Store v1: Start each instance with a journal entry of its own (--seed 61 --config 14 --steps 30000 --p-delete 30)

  • Journal entries are chained only by checksums. After a power outage loses a sector while a later one was written, replay stops at the hole.
  • If the restarted store then writes the same entries into the hole again (a retried write, deletion or stabilize), the stale sectors behind it become a valid continuation. The next restart replays operations that were never acknowledged: a deleted object comes back, or the OSD exits with "big_write journal_entry was allocated over another object". This also happens with immediate_commit=all: config 14 is one.
  • Fix: at start, before accepting operations, write a no-op rollback of the absent object 0:0 to a random version. Nothing written later then matches what a crashed instance wrote. The version is random because vitastor-disk prepare zeroes only the first journal block: a fixed start entry would chain into the previous OSD's sectors on a reused disk (commit 4 tests that).

2. Store v1: Keep journaled small writes under a deletion (--seed 553 --config 22 --steps 30000 --p-delete 30)

  • A deletion forgot every unsynced version before it, small writes too. Their entries are already in the journal and may reach the disk with any later fsync, but forgetting them released their sectors.
  • A trim could then cut between an object's small writes while the deletion was not durable yet. After a power outage, recovery replayed the later small writes without their base: content that never existed, or a checksum mismatch.
  • Fix: forget only unsynced big writes, which are not journaled yet. Only without immediate_commit=all.

3. Store v1: Do not replay an earlier pass of the journal (--seed 350 --config 21 --steps 30000 --p-delete 30)

  • A trim can point the superblock at a sector whose latest write is not durable yet, or not written at all when the journal is emptied. That sector holds an earlier pass of the ring, and replay, which never checked the first entry, took it for live entries: old deletions and writes came back over renumbered objects, or the OSD exited.
  • Fix: every trim stores what the first entry chains to (its crc32_prev) in the superblock's reserved field. Replay and vitastor-disk stop on a mismatch. 0, which older versions write, skips the check. A trim also never moves past a sector still open for appends.
  • No chaos run needed that last part: 3,600 runs on configs 15-17 and 21-23 also pass without it. It is there because the new check depends on it. An entry appended to a sector behind the journal start would change what the next sector chains to, and replay would stop at the first sector.
  • This gives reserved a meaning. Older binaries ignore it, but please say if you'd rather have a separate field or a version bump. Superblocks written by older versions hold 0, so the first restart after an upgrade is not checked.
  • Commits 1 and 3 together do what the FIXME in the journal reset said ("Randomize initial crc32. Track crc32 when trimming"), so the FIXME is removed.

4. Store v1: Test that a new journal does not chain to an old one

Testing (Ubuntu 24.04, RelWithDebInfo):

  • test_blockstore_v1: 3 new tests. Each fails without its fix (the last one with a fixed start entry version) and passes with it; all tests pass at every commit.
  • Every commit was built on its own, and the seed in its subject fails at its parent and passes with it.
  • test_blockstore_chaos --p-delete 30, seeds 1-1500 on each of the 12 v1 configurations (18,000 runs): the series passes all, and seeds 1-300 with --steps 30000 (3,600 runs) too. Master fails 3 of the 18,000. --seed 553 --config 17 is the bug of commit 1. --seed 1204 --config 21 and --config 22 are a different one: they stop with "deadlock?", the flusher idle with 3 objects queued and trim_wanted=1. The series does not fix that, it only changes those runs; I'll look into it separately.
  • make build_tests test, as in .gitea/workflows/test.yml: 16 of 16 pass. tests/test_dump_load.sh with OLD=1, plain and with 32k checksums, passes too: vitastor-disk dump-journal and write-journal keep the start entry.

Contributor Name

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

CLA

### Description Three store v1 journal replay bugs, found with `test_blockstore_chaos --p-delete 30` after #114. Each commit names a seed that fails before it and passes with it. **1. Store v1: Start each instance with a journal entry of its own** (`--seed 61 --config 14 --steps 30000 --p-delete 30`) - Journal entries are chained only by checksums. After a power outage loses a sector while a later one was written, replay stops at the hole. - If the restarted store then writes the same entries into the hole again (a retried write, deletion or stabilize), the stale sectors behind it become a valid continuation. The next restart replays operations that were never acknowledged: a deleted object comes back, or the OSD exits with "big_write journal_entry was allocated over another object". This also happens with `immediate_commit=all`: config 14 is one. - Fix: at start, before accepting operations, write a no-op rollback of the absent object 0:0 to a random version. Nothing written later then matches what a crashed instance wrote. The version is random because `vitastor-disk prepare` zeroes only the first journal block: a fixed start entry would chain into the previous OSD's sectors on a reused disk (commit 4 tests that). **2. Store v1: Keep journaled small writes under a deletion** (`--seed 553 --config 22 --steps 30000 --p-delete 30`) - A deletion forgot every unsynced version before it, small writes too. Their entries are already in the journal and may reach the disk with any later fsync, but forgetting them released their sectors. - A trim could then cut between an object's small writes while the deletion was not durable yet. After a power outage, recovery replayed the later small writes without their base: content that never existed, or a checksum mismatch. - Fix: forget only unsynced big writes, which are not journaled yet. Only without `immediate_commit=all`. **3. Store v1: Do not replay an earlier pass of the journal** (`--seed 350 --config 21 --steps 30000 --p-delete 30`) - A trim can point the superblock at a sector whose latest write is not durable yet, or not written at all when the journal is emptied. That sector holds an earlier pass of the ring, and replay, which never checked the first entry, took it for live entries: old deletions and writes came back over renumbered objects, or the OSD exited. - Fix: every trim stores what the first entry chains to (its `crc32_prev`) in the superblock's `reserved` field. Replay and `vitastor-disk` stop on a mismatch. 0, which older versions write, skips the check. A trim also never moves past a sector still open for appends. - No chaos run needed that last part: 3,600 runs on configs 15-17 and 21-23 also pass without it. It is there because the new check depends on it. An entry appended to a sector behind the journal start would change what the next sector chains to, and replay would stop at the first sector. - **This gives `reserved` a meaning.** Older binaries ignore it, but please say if you'd rather have a separate field or a version bump. Superblocks written by older versions hold 0, so the first restart after an upgrade is not checked. - Commits 1 and 3 together do what the FIXME in the journal reset said ("Randomize initial crc32. Track crc32 when trimming"), so the FIXME is removed. **4. Store v1: Test that a new journal does not chain to an old one** **Testing** (Ubuntu 24.04, RelWithDebInfo): - `test_blockstore_v1`: 3 new tests. Each fails without its fix (the last one with a fixed start entry version) and passes with it; all tests pass at every commit. - Every commit was built on its own, and the seed in its subject fails at its parent and passes with it. - `test_blockstore_chaos --p-delete 30`, seeds 1-1500 on each of the 12 v1 configurations (18,000 runs): the series passes all, and seeds 1-300 with `--steps 30000` (3,600 runs) too. Master fails 3 of the 18,000. `--seed 553 --config 17` is the bug of commit 1. `--seed 1204 --config 21` and `--config 22` are a different one: they stop with "deadlock?", the flusher idle with 3 objects queued and `trim_wanted=1`. The series does not fix that, it only changes those runs; I'll look into it separately. - `make build_tests test`, as in `.gitea/workflows/test.yml`: 16 of 16 pass. `tests/test_dump_load.sh` with `OLD=1`, plain and with 32k checksums, passes too: `vitastor-disk dump-journal` and `write-journal` keep the start entry. ### 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 4 commits 2026-11-23 10:07:49 +03:00
Journal entries chain only by checksums. After a power outage left a
hole with written sectors behind it, the same entries written into the
hole again (a retried write, delete or stabilize) made those sectors a
valid continuation, and the next restart replayed lost operations.
Write a no-op rollback of the absent object 0:0 to a random version at
start, so nothing written later matches what a crashed instance wrote.
A deletion forgot every unsynced version before it, small writes too.
Their entries are already in the journal and may reach the disk with
any later fsync, yet forgetting them released their sectors, so a trim
could cut between an object's small writes while the deletion was not
durable: after a power outage recovery replayed the later ones without
their base. Forget only unsynced big writes, which are not journaled yet.
A trim can point the superblock at a sector whose latest write is not
durable yet, or not written at all when the journal is emptied. That
sector then holds an earlier pass of the ring, and replay, which never
checked the first entry, took it for live entries: old deletions and
writes came back over renumbered objects. Keep what the first entry
chains to in the superblock's reserved field and stop the replay, in the
store and in vitastor-disk, on a mismatch (0 from older versions skips the
check). Never trim past a sector still open for appends.
Preparing an OSD again zeroes only the first block of its journal, so
the sectors of the previous OSD stay behind it. A start entry that is
the same every time would let the replay chain into them; the random
version of the start entry is what prevents it.
This pull request has changes conflicting with the target branch.
  • src/test/test_blockstore_v1.cpp
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u v1-replay-fixes:koolkhel-v1-replay-fixes
git checkout koolkhel-v1-replay-fixes
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#157
No description provided.