osd, cli: Pause writes while making a live snapshot #177

Open
koolkhel wants to merge 5 commits from koolkhel/vitastor:readonly-inode-check into master
Contributor

Description

A live snapshot is one etcd transaction: the image's inode is renamed into the snapshot and marked readonly, and a new top layer is created. Clients and OSDs learn about it from their own etcd watches, each at its own moment. readonly is checked only on the client, so a client that is late keeps writing into the snapshot, and OSDs accept it. With several clients writing to one image, the snapshot can then hold a write while missing an earlier one it depends on, and writes made after the snapshot are missing from the image.

What the PR does:

  • snap-create first sets a new paused flag in the image's inode config and waits until every primary OSD reports, in a new config_revision field of its /osd/state, a revision at or above that change. An OSD rewrites its /osd/state (under its lease) only when it applies a config change with a paused inode, or finds one when it loads PGs. Then snap-create makes the snapshot as before, records the new top layer in the snapshot's config as successor_id/successor_pool (encoded like parent_id/parent_pool) and drops the pause.
  • If OSDs don't apply the pause in --pause-timeout seconds (10 by default), or the snapshot fails, snap-create removes the pause. If it is killed while writes are paused, repeating it makes the snapshot. If some primary OSD doesn't report config_revision at all (an older version), it warns and snapshots without pausing.
  • Clients announce a readonly_check feature in SHOW_CONFIG. A PG primary rejects WRITE/DELETE from such a client to a paused inode, or to a readonly inode with a successor, with -ESTALE (-EROFS for CAS writes). Older clients get no new error codes and behave as before.
  • The client retries a -ESTALE write until its own view shows the snapshot, then resends the whole write to the successor, following several snapshots if it missed them. With immediate_commit other than all, the copy kept for replay moves with it. It warns only if it waits longer than 10 s.
  • Merge, flatten, rm-data and write-back flushes, which write into readonly layers on purpose, send a new rw flag OSD_OP_IGNORE_INODE_READONLY (8) and aren't checked.
  • A hidden debug option etcd_watch_delay_ms applies watch events that much later, in order, so a lagging client or OSD can be made deterministic in tests.

New in the protocol and in etcd: rw flag 8, the readonly_check feature, the inode config fields paused, successor_id and successor_pool, and config_revision in /osd/state. No new opcodes.

Not covered: clients without readonly_check aren't paused or redirected, so with them a live snapshot is consistent only with a single writer, as before.

Found: by reading the code (readonly is checked only on the client), then reproduced by delaying etcd watch events on one client.

Tested: osd_test (test_readonly_check: rejection for a paused inode and a snapshot, the /osd/state rewrite), test_cluster_client (test_ignore_readonly_flag, test_stale_write_follows_successor), and tests/test_snapshot_switch.sh, also with IMMEDIATE_COMMIT=1. That test has three parts. Two clients write across snap-create, one of them applying etcd events 3 s late, and the snapshot must not change afterwards. Then all OSDs apply etcd events 3 s late too: snap-create --pause-timeout 1 must give up and leave nothing paused, and writes sent right after snap-create must not reach the snapshot. Without the pause step, the last part fails with "Snapshot s2 got writes made after it". tests/test_rm.sh passes. test_snapshot*.sh pass up to the point where they need qemu-img with the vitastor driver, which the test host doesn't have.

Contributor Name

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

CLA

### Description A live snapshot is one etcd transaction: the image's inode is renamed into the snapshot and marked readonly, and a new top layer is created. Clients and OSDs learn about it from their own etcd watches, each at its own moment. `readonly` is checked only on the client, so a client that is late keeps writing into the snapshot, and OSDs accept it. With several clients writing to one image, the snapshot can then hold a write while missing an earlier one it depends on, and writes made after the snapshot are missing from the image. What the PR does: - `snap-create` first sets a new `paused` flag in the image's inode config and waits until every primary OSD reports, in a new `config_revision` field of its `/osd/state`, a revision at or above that change. An OSD rewrites its `/osd/state` (under its lease) only when it applies a config change with a paused inode, or finds one when it loads PGs. Then `snap-create` makes the snapshot as before, records the new top layer in the snapshot's config as `successor_id`/`successor_pool` (encoded like `parent_id`/`parent_pool`) and drops the pause. - If OSDs don't apply the pause in `--pause-timeout` seconds (10 by default), or the snapshot fails, `snap-create` removes the pause. If it is killed while writes are paused, repeating it makes the snapshot. If some primary OSD doesn't report `config_revision` at all (an older version), it warns and snapshots without pausing. - Clients announce a `readonly_check` feature in `SHOW_CONFIG`. A PG primary rejects WRITE/DELETE from such a client to a paused inode, or to a readonly inode with a successor, with `-ESTALE` (`-EROFS` for CAS writes). Older clients get no new error codes and behave as before. - The client retries a `-ESTALE` write until its own view shows the snapshot, then resends the whole write to the successor, following several snapshots if it missed them. With `immediate_commit` other than `all`, the copy kept for replay moves with it. It warns only if it waits longer than 10 s. - Merge, flatten, rm-data and write-back flushes, which write into readonly layers on purpose, send a new rw flag `OSD_OP_IGNORE_INODE_READONLY` (8) and aren't checked. - A hidden debug option `etcd_watch_delay_ms` applies watch events that much later, in order, so a lagging client or OSD can be made deterministic in tests. New in the protocol and in etcd: rw flag 8, the `readonly_check` feature, the inode config fields `paused`, `successor_id` and `successor_pool`, and `config_revision` in `/osd/state`. No new opcodes. Not covered: clients without `readonly_check` aren't paused or redirected, so with them a live snapshot is consistent only with a single writer, as before. Found: by reading the code (`readonly` is checked only on the client), then reproduced by delaying etcd watch events on one client. Tested: `osd_test` (`test_readonly_check`: rejection for a paused inode and a snapshot, the `/osd/state` rewrite), `test_cluster_client` (`test_ignore_readonly_flag`, `test_stale_write_follows_successor`), and `tests/test_snapshot_switch.sh`, also with `IMMEDIATE_COMMIT=1`. That test has three parts. Two clients write across `snap-create`, one of them applying etcd events 3 s late, and the snapshot must not change afterwards. Then all OSDs apply etcd events 3 s late too: `snap-create --pause-timeout 1` must give up and leave nothing paused, and writes sent right after `snap-create` must not reach the snapshot. Without the pause step, the last part fails with "Snapshot s2 got writes made after it". `tests/test_rm.sh` passes. `test_snapshot*.sh` pass up to the point where they need `qemu-img` with the vitastor driver, which the test host doesn't have. ### 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-24 16:33:25 +03:00
Bugs where a client or an OSD acts on stale metadata after a change in
etcd, like writing into a layer that has just become a snapshot, depend
on a narrow timing window and are hard to reproduce. Add a hidden
etcd_watch_delay_ms option which applies watch events that much later,
in order, so tests can make a lagging participant deterministic. Events
still queued when the state is reloaded after a compaction are dropped.
When snap-create renames the current layer into a snapshot, nothing in
its config says which layer took its place, and the name alone is
ambiguous because clones of the snapshot have it as their parent too.
Store the new layer as successor_id/successor_pool, encoded like
parent_id/parent_pool, so clients holding the old inode number can
follow it.
Inode readonly is only checked on the client, and a client learns about
a snapshot from its own etcd watch. Until then it keeps writing into the
inode that has become the snapshot, so writes made after the snapshot
change it and are missing from the image. Make PG primaries reject such
writes with -ESTALE (-EROFS for CAS writes) when the client announces
the readonly_check feature and the snapshot has a successor. The client
retries until its own view shows the snapshot, then resends the whole
write to the successor. Merge, flatten, rm-data and write-back flushes
send OSD_OP_IGNORE_INODE_READONLY and are not checked.
A writer that applies etcd events 3 seconds late keeps writing while
snap-create runs. Check that the snapshot does not change after it was
taken and that the image has every write.
koolkhel force-pushed readonly-inode-check from 9dc06ed9e4 to bef72607cd 2026-11-26 08:25:39 +03:00 Compare
koolkhel changed title from osd, client: Reject writes to snapshots from clients that missed the switch to osd, cli: Pause writes while making a live snapshot 2026-11-26 08:25:48 +03:00
Author
Contributor

Reworked as we discussed: the OSD-side refusal stays, and the snapshot now waits for the OSDs.

  • New commit "osd, cli: Pause writes to an image while making its snapshot": the paused flag in the inode config, config_revision in /osd/state (rewritten under the lease only when the OSD applies a paused inode), and snap-create in three steps (pause, wait for every primary OSD, snapshot), with --pause-timeout.
  • The refusal, successor_id/successor_pool and the client resend are unchanged; the OSD now also refuses writes to a paused inode.
  • tests/test_snapshot_switch.sh now also covers OSDs lagging behind etcd and two writers.
  • Rebased onto master.
Reworked as we discussed: the OSD-side refusal stays, and the snapshot now waits for the OSDs. - New commit "osd, cli: Pause writes to an image while making its snapshot": the `paused` flag in the inode config, `config_revision` in `/osd/state` (rewritten under the lease only when the OSD applies a paused inode), and `snap-create` in three steps (pause, wait for every primary OSD, snapshot), with `--pause-timeout`. - The refusal, `successor_id`/`successor_pool` and the client resend are unchanged; the OSD now also refuses writes to a paused inode. - `tests/test_snapshot_switch.sh` now also covers OSDs lagging behind etcd and two writers. - Rebased onto master.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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