From 831f44dbe50cfd4de6e26bf530ae7db7160ad2db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Thu, 3 Dec 2026 20:19:31 +0100 Subject: [PATCH] docs: describe subtree skipping and add sequence diagrams Co-Authored-By: Claude Opus 5.5 --- README.md | 40 ++++++++++++++- docs/lab.md | 3 +- docs/migration.md | 116 +++++++++++++++++++++++++++++++++++++++++-- docs/raw-transfer.md | 7 ++- 4 files changed, 157 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 57254b3..20a3693 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,41 @@ Steps of a migration: A file system snapshot does not make a database application-consistent. The write stop must cover all clients. +```mermaid +sequenceDiagram + actor Op as Operator + participant M as cephmig + participant S as Source cluster + participant T as Target cluster + + Op->>M: inspect + M->>S: check subvolume + M->>T: check subvolume + loop sync, repeated while the application runs + Op->>M: sync + M->>S: create round snapshot + M->>T: copy changes, verify + M->>T: create round snapshot + M->>S: remove previous round snapshot + M->>T: remove previous round snapshot + end + Note over Op,S: stop all writers + Op->>M: finalize --writers-stopped + M->>S: create final snapshot + M->>T: copy, full verification, create final snapshot + M-->>Op: ready-for-cutover + Note over Op,T: switch clients to the target + Op->>M: cleanup + M->>S: remove final snapshot + M->>T: remove final snapshot +``` + +The detailed sequence is in [docs/migration.md](docs/migration.md#workflow-in-detail). + +Intermediate `sync` rounds skip subtrees whose recursive change time +(`ceph.dir.rctime`) did not change, so a round reads only the changed parts. +`finalize` always reads everything. + Each round creates a snapshot `cephmig--` at source and target; `sync` deletes the older ones as soon as a newer round is complete. Users of the subvolume therefore see at most one such snapshot during the migration, @@ -125,8 +160,9 @@ The configuration is a JSON file, here } ``` -Optional fields are `user` (Ceph client identity, e.g. `client.migration`) -and `workers` (0 to 64; 0 selects the default). `mount` is only needed for +Optional fields are `user` (Ceph client identity, e.g. `client.migration`), +`workers` (0 to 64; 0 selects the default) and `full_scan` (`true` makes +every round read all metadata instead of skipping unchanged subtrees). `mount` is only needed for the rsync backend: the mount of the file system root. ## Examples diff --git a/docs/lab.md b/docs/lab.md index 1b10961..5c0cdab 100644 --- a/docs/lab.md +++ b/docs/lab.md @@ -85,7 +85,8 @@ effective throughput and a fixed upper bound for the write stop will be determined later. The local environment verifies functionality but does not reproduce this amount of data. The native copier uses bounded workers and buffers, a persistent index on local disk and optional bandwidth limiting. -Full metadata scans remain necessary. Evidence for memory, index size, +Intermediate rounds skip unchanged subtrees; the final round still scans all +metadata. Evidence for memory, index size, runtime and the final write stop is missing. 1. Check source, target, permissions, capacity and required metadata. diff --git a/docs/migration.md b/docs/migration.md index 652c261..e225200 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -83,6 +83,43 @@ running `sync` again. The native backend uses snapdiff and the Ceph inode version, so it also detects data changes with the same size and mtime. The rsync path uses checksums. +### Skipping unchanged subtrees + +Reading all metadata of a large subvolume in every round is the main cost of +a round: in the [one-million-file test](million-local.md), even an unchanged +finalization took 1 h 20 min and 19.3 million MDS requests. Snapdiff cannot +replace this scan; in the lab it reported every directory and missed pure +chmod, xattr changes and writes through a hardlink alias. + +Intermediate `sync` rounds therefore skip a subdirectory when, compared with +the base snapshot of the previous round, it has + +- the same inode and the same inode version, which changes at once with + every entry added or removed and every change of its own metadata, and +- the same `ceph.dir.rctime`, the newest ctime in the whole subtree. + +The index takes over the entries of a skipped subtree from the previous base +and marks them `carried`. Snapdiff, copy, pruning and verification all leave +the subtree out. The journal reports the number per round as +`skipped_subtrees`. + +The rctime is not exact. Ceph propagates it to the parent directories with a +delay; in the lab, a change made milliseconds before a snapshot was not yet +visible in that snapshot's rctime. A client whose clock lags behind can also +stamp a change with a ctime older than the newest one in the subtree. An +intermediate round can therefore miss content changes deep inside a subtree. +The following design limits the effect to extra work: + +- `finalize` always scans and verifies everything; it never skips. +- A carried entry describes an older round than the base snapshot, so it never + serves as base for a block delta: a changed carried file is copied in full. +- Snapshots discovered at the source (application snapshots) are always + transferred with a full scan. Only the `cephmig-*` round snapshots, which + are deleted later, can be incomplete. + +`"full_scan": true` in the configuration disables the shortcut for all +rounds. It may be changed when resuming. + `finalize` relies solely on the operator's explicit confirmation of the write stop; it does not stop or lock any application itself. All writers must stay stopped until the cutover is complete. The job ends in `ready-for-cutover`. @@ -106,6 +143,76 @@ Application snapshots are never deleted. The journal marks a snapshot as `removed` before deleting it, so an interrupted run completes the deletion next time. +## Workflow in detail + +The diagram shows one migration with the native backend: an intermediate +`sync` round, `finalize` and `cleanup`. Application snapshots discovered at +the source are transferred like a round, but always with a full scan and +without being deleted. + +```mermaid +sequenceDiagram + autonumber + actor Op as Operator + participant M as cephmig + participant J as Journal (local) + participant I as Index (local bbolt) + participant S as Source cluster + participant T as Target cluster + participant V as Verify client + + Op->>M: sync --config --state + M->>S: fsid, subvolume info, snapshot ls + M->>T: fsid, subvolume info, snapshot ls + M->>T: lock claim in /.cephmig/claims + M->>J: record intent for round snapshot R(n) + M->>S: create snapshot R(n) + M->>J: invalidate the confirmed base + M->>I: open base R(n-1), create pending index + M->>S: snapdiff R(n-1) to R(n) + + loop every directory, from the root down + M->>S: stat dir, ceph.dir.rctime in R(n) and R(n-1) + alt same inode, inode version and rctime (sync rounds only) + M->>I: carry subtree entries, marked carried + else changed + M->>I: record path inventory + M->>T: mkdir, copy changed files (blockdiff or full), symlinks, FIFOs + M->>T: xattrs and quotas, then setattr and ctime stamp + end + end + + M->>T: hardlink aliases, prune surplus entries + M->>T: restore directory metadata, deepest first + M->>T: sync_fs + M->>V: connect a fresh client to the target + V->>T: compare metadata, links and copied ranges with R(n) + M->>T: create snapshot R(n), copy snapshot metadata + V->>T: compare snapshot R(n) with R(n) + M->>I: commit pending index as new base + M->>J: mark R(n) done, base = R(n) + M->>J: mark R(n-1) removed + M->>S: remove snapshot R(n-1) + M->>T: remove snapshot R(n-1) + M-->>Op: journal as JSON + + Note over Op,S: all writers stopped + Op->>M: finalize --writers-stopped + M->>S: create final snapshot F + Note over M,T: same round, but a full scan: no subtree is skipped + M->>J: mark F done, R(n) removed + M->>S: remove snapshot R(n) + M->>T: remove snapshot R(n) + V->>T: verify complete inventory against F + M->>J: phase = ready-for-cutover + + Note over Op,T: clients switched to the target and checked + Op->>M: cleanup + M->>J: mark F removed + M->>S: remove snapshot F + M->>T: remove snapshot F +``` + ## Transferred data - Snapshot names and contents; existing snapshots are transferred in @@ -322,13 +429,14 @@ files and short verification ranges. Unchanged owner, mode and timestamps do not trigger another `setattr` call; a target stat read just before is reused for the metadata check. Path and hardlink mappings live on local disk. Snapdiff and blockdiff avoid repeated full transfers and full reads of -unchanged file contents. The implementation still scans all metadata, -including the full topology and quota check. Renamed files may be copied -again in full. Single transactions of the native index are not yet optimized +unchanged file contents. Intermediate rounds skip unchanged subtrees, but +`finalize` still scans all metadata, including the full topology and quota +check, so the write stop scales with the total number of entries. Renamed +files may be copied again in full. Single transactions of the native index are not yet optimized for 200 million paths. 200 TB and more than 200 million files are therefore not yet proven. What is -missing for that release in particular: change planning that avoids scans, +missing for that release in particular: a final round that avoids full scans, reliable memory and runtime measurements, a capacity model for historical versions and an automated client cutover. A fixed maximum write-stop duration is not guaranteed. Native API calls block; cancellation is checked between diff --git a/docs/raw-transfer.md b/docs/raw-transfer.md index 4019726..04a3217 100644 --- a/docs/raw-transfer.md +++ b/docs/raw-transfer.md @@ -78,8 +78,11 @@ Blockdiff is used from 16 MiB on, provided a confirmed base with matching source and target inodes exists. If the diff interfaces are unavailable, the state is reconstructed fully and natively. There is no silent rsync fallback. -The implementation nevertheless still scans all metadata and checks the full -hardlink topology of every state. Snapdiff does not yet replace these scans. +Snapdiff cannot replace the metadata scan (see +[skipping unchanged subtrees](migration.md#skipping-unchanged-subtrees)). +Intermediate rounds skip subtrees whose recursive ctime did not change; +application snapshots and the final round still scan all metadata and check +the full hardlink topology. Data verification reads all bytes for the first state and only the copied ranges for confirmed later states. Unchanged ranges are taken from the previously verified base. The target must belong exclusively to the