cleanup now deletes the claim file under .cephmig/claims as its last step, if it holds the job's own ID, and removes the claim directories when they are empty. A cleaned-up job is finished: cleanup and finalize do nothing and do not claim the target again, and sync is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 KiB
Migration prototype
The evaluation of a direct RADOS object transfer and the native alternative through libcephfs are documented in 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:
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.
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:
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.
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, 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:
finalizealways 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.
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. As its last step, cleanup deletes the target claim (see below) and
the directories .cephmig/claims and .cephmig if they are empty. The job
is then finished: cleanup and finalize do nothing more, and sync is
refused. 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.
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.
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 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 fromclock_gettime(CLOCK_REALTIME). The native backend replacesclock_gettimein 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_bytesandceph.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.
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.
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 full content comparison after the cutover is proposed in verify-concept.md. 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 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; cleanup deletes the claim
only after the job is finished, and only if it holds the job's own ID. The
lock is an advisory CephFS flock: it excludes other cephmig processes, but
does not block any application. 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
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:
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. 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: 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 calls and waits for I/O already in progress.