Files
CephfsMig/README.md
T
Sebastian UnterschützandClaude Opus 5.5 6dcb7b676f fix!: remove skipping of unchanged subtrees
Intermediate rounds skipped a directory when its inode version and its
ceph.dir.rctime matched the previous round. In the 10,000-file lab test
a round snapshot taken seconds after changes skipped tree/ with about
250 changed files in its subdirectories: the inode version of tree/
changes only with its own entries, and Ceph had not yet propagated the
rctime of the grandchildren. The target snapshot of that round was
incomplete, and its verification skipped the same subtrees; only
finalize closed the gap.

Every round now scans all metadata again. Base index entries that the
old version marked carried are never trusted, so such files are copied
in full in the next round.

The smallfiles verification now checks only snapshots that sync did not
remove.

BREAKING CHANGE: the configuration field "full_scan" and the transfer
statistic "skipped_subtrees" are removed; a configuration with
"full_scan" is rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 22:17:47 +01:00

230 lines
8.6 KiB
Markdown

# CephMig: migrate CephFS subvolumes between Ceph clusters
A Go tool that copies a CephFS subvolume, including its snapshots, POSIX ACLs,
xattrs, quotas and timestamps, from one Ceph cluster to another while the
application keeps running.
## Description
**Why?** A subvolume has to move to a new cluster with only a short write
stop. The target size is up to 200 TB and more than 200 million files. A
plain copy is not enough: snapshots, hardlinks and Ceph metadata must be
preserved, and an interrupted run must be resumable.
**How?** CephMig works in rounds. Each round transfers a consistent source
snapshot, verifies the target and creates a snapshot of the same name there.
A journal on local disk records every step. For the last round, all writers
are stopped briefly.
The copier talks to both clusters directly through libcephfs. It needs no
kernel or FUSE mount. After the initial transfer it uses snapdiff and, where
possible, blockdiff.
**Status:** prototype. The features are verified in the local lab. Load
tests at the target size and a production cutover are still missing.
> **Documented deviations:** native snapshot IDs and snapshot creation times
> are assigned anew at the target. CephMig takes mtime, atime,
> ctime and birth time (btime) of every file from the source; the ctime is
> never lower than the mtime. The original snapshot creation times are kept
> in the journal.
> Details: [docs/migration.md](docs/migration.md).
## Installation
Requirements:
- Linux, Go 1.25 or later and GNU Make
- for the copier and the lab: Docker Engine with Docker Compose and
`/dev/fuse` on the Docker host
- for the lab: up to 12 GiB RAM for the containers and about 8 GiB of disk
space for the two OSDs, plus space for the images
Get the source and build it:
```sh
git clone ssh://git@git.zb-server.de:30022/Sebi/CephfsMig.git
cd CephfsMig
make doctor # checks Go, Docker and Docker Compose
make build # builds bin/cephmig without libcephfs (doctor and status only)
make check # go vet, Go tests and a syntax check of the test scripts
```
The copier needs CGO and the libcephfs headers (build tag `ceph`), so it is
built in a container. The build also runs the Go tests with the race
detector:
```sh
make dev-native-build # builds the image cephmig-native:dev
```
## Usage
```text
cephmig doctor
cephmig inspect --config FILE
cephmig sync --config FILE --state FILE
cephmig finalize --config FILE --state FILE --writers-stopped
cephmig cleanup --config FILE --state FILE
cephmig status --state FILE
```
| Command | Effect |
|------------|----------------------------------------------------------------------|
| `inspect` | checks source and target without changing anything |
| `sync` | transfers the current state; can be repeated any number of times |
| `finalize` | last round after the write stop, then ready for cutover |
| `cleanup` | deletes the snapshots cephmig created and its claim on the target |
| `status` | prints the journal |
All results are written to standard output as JSON. The state file belongs
on local disk.
Steps of a migration:
1. Check source, target, permissions and capacity with `inspect`.
2. Make the initial copy with `sync` while the application keeps running.
3. Repeat `sync` to catch up with changes.
4. Stop all writing applications, then run `finalize --writers-stopped`.
5. Switch the clients to the target and release the applications.
6. Once the cutover is checked, remove the migration snapshots with `cleanup`.
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).
Every round reads the metadata of the whole subvolume; only changed file
contents are copied.
Each round creates a snapshot `cephmig-<job>-<round>` 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,
and none after `cleanup`. Application snapshots are never deleted.
The configuration is a JSON file, here
[dev/migration.example.json](dev/migration.example.json) from the lab:
```json
{
"backend": "native",
"source": {
"config": "/clusters/source/ceph.conf",
"keyring": "/clusters/source/ceph.client.admin.keyring",
"filesystem": "cephfs",
"group": "migration",
"subvolume": "demo"
},
"target": {
"config": "/clusters/target/ceph.conf",
"keyring": "/clusters/target/ceph.client.admin.keyring",
"filesystem": "cephfs",
"group": "migration",
"subvolume": "demo"
},
"bandwidth_kib": 0
}
```
Optional fields are `user` (Ceph client identity, e.g. `client.migration`),
and `workers` (0 to 64; 0 selects the default). `backend` may be omitted;
its only value is `native`.
## Examples
The lab starts two independent Ceph clusters (Ceph 21.2.0) in Docker and runs
the migration between them:
```sh
make dev-up # start the clusters
make dev-status # state of both clusters
make dev-smoke # smoke test: snapshot, ACLs, xattrs, hardlinks, quotas
make dev-native-test # native functional test
docker compose -f dev/compose.yaml exec native cephmig-native inspect \
--config /lab/migration.example.json
make dev-down # stop; the data is kept
```
More tests:
| Target | Content |
|----------------------------|-----------------------------------------------------------|
| `make dev-smallfiles-test` | 10,000 small files (`FILES=2000` limits the number) |
| `make dev-million-start` | one million files with four snapshot states |
| `make dev-restart-check` | restart of the lab; FSIDs and data are preserved |
Results of documented runs: [docs/smallfiles-local.md](docs/smallfiles-local.md)
and [docs/million-local.md](docs/million-local.md).
## Project structure
```text
.
├── cmd/
│ ├── cephmig/ command-line program
│ └── nativeprobe/ diagnostic tool for the libcephfs binding
├── internal/
│ ├── migration/ migration workflow, journal and native transfer
│ ├── storage/ file system interface of the native copier
│ └── cephfsnative/ CGO binding to libcephfs (build tag ceph)
├── dev/ lab: Compose files, Dockerfiles, test scripts
├── docs/ detailed documentation and measurements
└── Makefile build, check and lab targets
```
## Documentation
- [docs/migration.md](docs/migration.md): commands, limits and evidence
- [docs/lab.md](docs/lab.md): the lab in detail, Ceph version, known warnings
- [docs/raw-transfer.md](docs/raw-transfer.md): direct RADOS import and limits of the native implementation
- [docs/verify-concept.md](docs/verify-concept.md): concept for a full content verification after the cutover
- API documentation of the Go packages: `go doc -all ./internal/migration`
## Contributing
- Go code follows [Effective Go](https://go.dev/doc/effective_go) and is
formatted with `gofmt`. Exported identifiers have doc comments.
- Run `make check` before every commit.
- Commit messages follow [Conventional Commits 1.0.0](https://www.conventionalcommits.org/en/v1.0.0/),
for example `feat(migration): add bandwidth limit` or
`fix(native): retry on EEXIST`. Breaking changes are marked with `!` and a
`BREAKING CHANGE:` footer.
## License
No license has been chosen yet. Without a license, all rights are reserved.
## Contact
Sebastian Unterschütz. Please report questions and bugs as issues in the
repository [Sebi/CephfsMig](https://git.zb-server.de/Sebi/CephfsMig).