Also document the snapshot cleanup: older round snapshots are removed during sync, and `cephmig cleanup` removes the rest after the cutover. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
336 lines
18 KiB
Markdown
336 lines
18 KiB
Markdown
# Migration prototype
|
|
|
|
The evaluation of a direct RADOS object transfer and the native alternative
|
|
through libcephfs are documented in [raw-transfer.md](raw-transfer.md).
|
|
|
|
## Snapshot identity: documented deviation
|
|
|
|
Native snapshot IDs and Ceph birth times are assigned anew at the target. As
|
|
agreed, this deviation does not block the migration. `inspect`, the transfer
|
|
output and the persistent journal contain a note; the original and the new
|
|
creation times are recorded for every transferred snapshot. An application
|
|
that stores native IDs directly must account for the new values.
|
|
|
|
The supported `ceph_mksnap` interface accepts a name, a mode and custom
|
|
metadata, but no desired native ID or birth time. `ceph.snap.btime` is
|
|
explicitly read-only in the client. CephFS mirroring also creates a new
|
|
snapshot at the target and records the source ID as separate metadata.
|
|
|
|
Sources:
|
|
|
|
- [libcephfs interface](https://github.com/ceph/ceph/blob/main/src/include/cephfs/libcephfs.h)
|
|
- [Client: virtual snapshot attributes](https://github.com/ceph/ceph/blob/main/src/client/Client.cc)
|
|
- [Mirror: creating a target snapshot](https://github.com/ceph/ceph/blob/main/src/tools/cephfs_mirror/PeerReplayer.cc)
|
|
|
|
In the local Ceph 21.2.0 lab, a snapshot of the same name had source ID 6 and
|
|
target ID 2 and different birth times. An attempt to write the existing value
|
|
of `ceph.snap.btime` on our own test snapshot was rejected with `EROFS`.
|
|
|
|
The examined interfaces do not allow the native snapshot identity to be set.
|
|
This limitation is accepted and explicitly recorded. Load tests and an
|
|
automated production client cutover are still missing.
|
|
|
|
## Commands
|
|
|
|
The native backend needs Linux, the Ceph CLI, libcephfs and a copier built
|
|
with CGO and `-tags ceph`. It needs no operating system mounts and no
|
|
privileged container. Preserving foreign UID/GID and protected xattrs requires
|
|
the corresponding client and process privileges; the lab uses root. The
|
|
optional reference path `backend: rsync` additionally needs rsync and source
|
|
and target file systems mounted at the file system root.
|
|
The subvolumes must already exist. For a new job, the data tree, snapshots and
|
|
custom metadata of the target must be empty. No application may write to the
|
|
target.
|
|
|
|
The configuration in `dev/migration.example.json` selects `backend: native`
|
|
and applies to the lab service `native`. `mount` is not used there and may be
|
|
omitted. `workers` limits concurrent file copies (default 8, at most 64),
|
|
`bandwidth_kib` limits the total payload bytes written per second. Both values
|
|
may be changed when resuming.
|
|
The native `transfer` statistics in the journal report the mode, the base
|
|
snapshot, visited and copied files, and bytes written and read for
|
|
verification. `bytes_copied` counts payload writes without skipped zero
|
|
ranges; it does not measure the total network traffic including protocol and
|
|
verification.
|
|
|
|
```sh
|
|
make dev-native-build
|
|
docker compose -f dev/compose.yaml up -d --wait native
|
|
docker compose -f dev/compose.yaml exec native \
|
|
cephmig-native inspect --config /lab/migration.example.json
|
|
```
|
|
|
|
The read-only preflight compares the FSID from the CLI with the
|
|
`ceph.cluster_fsid` read through the client, checks paths and subvolume state
|
|
and reports the current data size and snapshot names. The data size is **not**
|
|
a capacity forecast for all historical snapshots.
|
|
|
|
The backend has the following transfer commands:
|
|
|
|
```sh
|
|
cephmig sync --config /absolute/config.json --state /local-state/job.json
|
|
cephmig status --state /local-state/job.json
|
|
# Stop and flush all source writers, including other clients.
|
|
cephmig finalize --config /absolute/config.json \
|
|
--state /local-state/job.json --writers-stopped
|
|
# After the cutover has been checked:
|
|
cephmig cleanup --config /absolute/config.json --state /local-state/job.json
|
|
```
|
|
|
|
`sync` processes known, unfinished states, newly discovered application
|
|
snapshots and then a new source snapshot. Further changes are caught up by
|
|
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.
|
|
|
|
`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`.
|
|
Remounts, application restarts and a migration back after writes to the
|
|
target are not automated.
|
|
|
|
### Migration snapshots
|
|
|
|
Each round creates a snapshot `cephmig-<job>-<round>` at source and target.
|
|
Only the newest one is needed, as base for the next round. As soon as a round
|
|
is complete, `sync` deletes the older round snapshots on both sides. Users of
|
|
the subvolume therefore see at most one migration snapshot at a time.
|
|
|
|
`cleanup` deletes the remaining round snapshot, including the final one,
|
|
after the job is `ready-for-cutover`. Afterwards the subvolumes hold only the
|
|
snapshots of the application. Since the final snapshot is the immutable
|
|
reference of the last round, run `cleanup` only after the cutover has been
|
|
checked. `cleanup` is idempotent.
|
|
|
|
Application snapshots are never deleted. The journal marks a snapshot as
|
|
`removed` before deleting it, so an interrupted run completes the deletion
|
|
next time.
|
|
|
|
## Transferred data
|
|
|
|
- Snapshot names and contents; existing snapshots are transferred in
|
|
chronological order.
|
|
- Numeric UID/GID, mode, POSIX ACLs including default ACLs.
|
|
- Timestamps of every file, directory and symlink:
|
|
|
|
| Timestamp | native | rsync |
|
|
| --- | --- | --- |
|
|
| mtime (last modification) | yes | yes |
|
|
| btime (creation) | yes | no |
|
|
| atime (last access) | yes | no |
|
|
| ctime (last status change) | yes¹ | no |
|
|
|
|
¹ To the nanosecond, but never lower than the mtime: if the source mtime is
|
|
newer than its ctime (mtime set into the future), the target gets
|
|
ctime = mtime.
|
|
|
|
No file system interface sets the ctime directly; Ceph 21.2.0 ignores
|
|
`CEPH_SETATTR_CTIME`. The MDS does, however, take the ctime from the time
|
|
stamp the client sends with each request, and libcephfs reads that stamp
|
|
from `clock_gettime(CLOCK_REALTIME)`. The native backend replaces
|
|
`clock_gettime` in its own process (symbol interposition, only in the
|
|
calling thread and only for the duration of one libcephfs call; the Go
|
|
runtime reads the clock through the vDSO and is not affected):
|
|
|
|
- Every modifying call runs with the time stamp 1970-01-01T00:00:01Z.
|
|
- As the last change to an entry, the backend creates and removes the xattr
|
|
`user.cephmig.ctime`, stamped with the source ctime. The MDS then sets
|
|
ctime = max(stamp, mtime), also backwards. Setattr and cap flushes, in
|
|
contrast, only move the ctime forward.
|
|
- Directories are stamped after all changes to their children, hardlinks
|
|
after linking and after removing surplus names.
|
|
- The writing client sometimes caches a different ctime for directories.
|
|
The verification before publication therefore reads the target through a
|
|
separate, freshly connected client.
|
|
|
|
This behaviour was measured in the lab and is not guaranteed by Ceph; the
|
|
verification reports every deviation. The atime at the target subsequently
|
|
changes through normal reads of the application. rsync cannot transfer the
|
|
btime on Linux; the atime is not transferred because the checksum
|
|
verification through the mount can change the target atime.
|
|
- User xattrs and other portable xattrs, including empty values and removals.
|
|
- Hardlinks within the subvolume, symlinks and FIFOs.
|
|
- Sparse file contents; the native path skips zero ranges or punches holes.
|
|
The physical space usage is not guaranteed.
|
|
- Directory quotas `ceph.quota.max_bytes` and `ceph.quota.max_files`, also at
|
|
the data root.
|
|
- Custom subvolume and snapshot metadata through the manager API.
|
|
- Original and new snapshot creation times in the journal.
|
|
|
|
Symlinks are kept as link text, even if their target does not exist. The
|
|
native path also preserves hardlinks to symlinks and FIFOs; for symlinks it
|
|
links the inode through the public low-level interface, so that the link
|
|
itself and not its referent is linked.
|
|
Absolute links are not rewritten; at cutover, the application's mount path
|
|
must match them. Hardlinks across the boundary of the transferred subvolume
|
|
are not migrated as a shared link.
|
|
|
|
Cluster-internal layout, pool and other `ceph.*` attributes are not copied
|
|
blindly; quotas are transferred separately. Pool and layout mappings,
|
|
subvolume group quotas, pinning, authorizations, snapshot schedules, active
|
|
clone jobs and other Ceph management state are not implemented.
|
|
The migration transfers the snapshots listed by the subvolume API with their
|
|
entire directory tree. CephFS supports directory snapshots in general, but
|
|
the MDS refuses separate snapshots below a managed subvolume. In the Ceph
|
|
21.2.0 lab, a snapshot of a plain directory succeeded, while the same attempt
|
|
in a subvolume subdirectory failed with `EPERM`. Inherited snapshot views
|
|
visible in subdirectories are part of the parent subvolume snapshot. The
|
|
earlier warning about separate subdirectory snapshots was too broad for this
|
|
managed subvolume model.
|
|
See [MDS check of the subvolume boundary](https://github.com/ceph/ceph/blob/main/src/mds/Server.cc).
|
|
With the rsync backend, ctime and atime are not preserved; with both
|
|
backends, original inode numbers and native snapshot IDs are assigned anew.
|
|
Encrypted, normalized, case-insensitive or earmarked subvolumes are rejected.
|
|
|
|
## Resumption and verification
|
|
|
|
The job keeps a JSON journal with mode 0600 that is replaced atomically and
|
|
secured with fsync. It contains the configuration, the cluster FSIDs, the
|
|
concrete subvolume data paths and per-snapshot intent and completion records.
|
|
Recreating the same subvolume name with a different data UUID is rejected.
|
|
|
|
A local flock lock prevents concurrent access to the same journal. A
|
|
persistent claim under `<target-filesystem>/.cephmig/claims/` with an
|
|
exclusive file/CephFS lock protects the target even across different local
|
|
journal paths. A missing or incomplete journal is never replaced by
|
|
automatically adopting existing target data.
|
|
|
|
Each snapshot state is copied, verified including quotas, and only then
|
|
created as a snapshot at the target. A target snapshot that was created but
|
|
not yet confirmed in the journal is verified again against the immutable
|
|
source on resumption. Replacement or loss of already completed snapshots is
|
|
detected from the stored identity; snapshots the journal marks as `removed`
|
|
are exempt.
|
|
|
|
The native data path uses a local bbolt index with source inode, inode
|
|
version, size and target inode per path. It contains no file contents. The
|
|
confirmed base is invalidated in the JSON journal before any change to the
|
|
target and confirmed again only after successful verification and an fsync of
|
|
the index. Clusters, data UUID paths and snapshot name must match. After an
|
|
interruption, the open state is reconstructed fully and natively; a partially
|
|
applied blockdiff must not count as a base. An already published but
|
|
unconfirmed target snapshot is verified again. After SIGKILL, the release of
|
|
old Ceph client sessions can delay the restart.
|
|
|
|
The index also contains the complete path inventory of the immutable source
|
|
snapshot: files, directories, hardlink aliases and special files. It is
|
|
marked complete only after it has been fully recorded. Pruning and the check
|
|
for surplus target paths compare target paths with this local inventory and
|
|
thus avoid another `stat` call for every source path. Incomplete or damaged
|
|
inventories abort the run. Identical inode rows are not written to the index
|
|
again during verification.
|
|
|
|
Immutable paths under `.snap` are read with `AT_STATX_DONT_SYNC` for `stat`
|
|
and `readdirplus`, as in Ceph's own mirror. This avoids requesting metadata
|
|
locks just to resynchronize snapshot inodes that cannot change anyway. Live
|
|
target paths keep their normal synchronization semantics. Details and
|
|
measurements are in [smallfiles-local.md](smallfiles-local.md).
|
|
|
|
For a full copy, the native verification compares all file contents. For
|
|
later states, it checks copied files or the ranges reported by blockdiff.
|
|
Unchanged bytes come from the previously verified base. The target tree must
|
|
therefore belong exclusively to the copier for the entire job. Foreign
|
|
changes to unchanged file ranges are not reliably detected this way.
|
|
Metadata, quotas and hardlink topology are checked in every state. A target
|
|
snapshot created right after the verification is checked for metadata and
|
|
links; the same immutable data is not read again.
|
|
|
|
The rsync verification reads file contents by checksum and also compares the
|
|
supported metadata. Quota values are checked separately. Resuming within a
|
|
state reuses the existing partial copies, but has to scan the tree again;
|
|
checkpoints currently exist per snapshot, not per file. For a hardlink
|
|
`EEXIST` reproduced in the lab, the transfer is retried exactly once,
|
|
idempotently; other errors are returned immediately.
|
|
|
|
In addition, the hardlink topology is verified in both directions: all source
|
|
paths of the same inode must belong together at the target, and independent
|
|
source files must not accidentally share an inode at the target. This is
|
|
needed because [rsync -H](https://download.samba.org/pub/rsync/rsync.1) does
|
|
not resolve surplus existing target links in every case. Before copying, the
|
|
rsync path removes such surplus links in the exclusive target and rebuilds
|
|
them from the source snapshot. The native path creates full copies
|
|
atomically as new inodes and then sets the hardlink aliases. Old target
|
|
snapshots stay unchanged. Symlinked directories are not followed.
|
|
|
|
The verification mappings live in a temporary bbolt index next to the
|
|
journal; write transactions are committed after 4,096 observations. The index
|
|
is discarded after every verification or repair run and rebuilt when needed.
|
|
It is not a resumption journal. The native base index under
|
|
`<journal>.native/base.bolt`, in contrast, is kept. Sufficient local disk
|
|
space is required for it. Path depths beyond 128 directories are currently
|
|
rejected. After a hard process abort during an index run, temporary index
|
|
directories can remain; they are never used as checkpoints.
|
|
|
|
Journal and claim must be kept for resumption. An incomplete claim after a
|
|
crash during its very first creation is deliberately not repaired
|
|
automatically; that requires checking the original job ID.
|
|
|
|
## Tests and scale
|
|
|
|
```sh
|
|
make check
|
|
go test -race ./...
|
|
make dev-migration-test
|
|
make dev-native-test
|
|
```
|
|
|
|
The integration tests create their own subvolumes and check historical
|
|
states, catching up with changes, metadata, removed files, copy errors and a
|
|
SIGKILL after a target snapshot was created but before the journal commit.
|
|
They also check the stored note about new snapshot identities, the
|
|
resolution of previously existing hardlinks with unchanged file contents, the
|
|
removal of older round snapshots during `sync` and the removal of all
|
|
migration snapshots by `cleanup`. On success they remove only their own
|
|
fixtures; on failure the reported test paths are kept for diagnosis.
|
|
|
|
The native test uses a copier without a FUSE device, CephFS mounts or rsync.
|
|
A separate FUSE application client independently checks all file contents
|
|
with SHA-256, as well as metadata, links and snapshots. It checks a 4 KiB
|
|
change in a 64 MiB file with the same mtime, growth and zero ranges, link
|
|
groups that are split and rejoined, and changes between directory and
|
|
symlink. Hardlinks to unresolvable symlinks and FIFOs are also compared
|
|
independently by inode, including a later split of a FIFO group. Further
|
|
checks cover cancellation during the copy, SIGKILL right after snapshot
|
|
creation, restart and idempotent completion. Meanwhile, an application keeps
|
|
writing to another source subvolume.
|
|
|
|
Lab result of 2026-11-05 with Ceph 21.2.0: native integration test and rsync
|
|
regression passed; Go tests including the race detector and `go vet` for the
|
|
Ceph build passed. The native test completed five states with
|
|
`ready-for-cutover` and additionally checked them through the application
|
|
client. For the 4 KiB change in the 64 MiB file, 4 KiB were written for this
|
|
file and 4,128 payload bytes for the whole second state including other
|
|
changed files. In the unchanged final state, 0 payload bytes were written.
|
|
This is a functional proof, not a throughput benchmark.
|
|
|
|
The read-only identity comparison for existing lab snapshots is:
|
|
|
|
```sh
|
|
python3 /lab/snapshot-identity.py \
|
|
--config /absolute/lab-config.json --snapshot existing-snapshot
|
|
```
|
|
|
|
Go reads directory quotas in batches and keeps no list of all files. This
|
|
does **not** bound the memory of the external rsync process: large single
|
|
directories and hardlink groups can need considerable memory there. Every
|
|
state causes full scans and checksum reads. Changed large files can need
|
|
considerable additional target space for new snapshots.
|
|
|
|
In the native path, file workers, data buffers and directory iteration are
|
|
bounded; copy and compare buffers are at most 4 MiB and shrink for small
|
|
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
|
|
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,
|
|
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
|
|
calls and waits for I/O already in progress.
|