Ga naar hoofdinhoud

SeaweedFS HA migration (wordsworth#193 task 1.2)

One-off migration from the all-in-one SeaweedFS pod to a shape that survives losing a node, node-01 included. Target manifests: homelab PR #32, which is merged at the end of the window, not before. Scripts: scripts/seaweedfs-ha/. Day-to-day operation stays in SeaweedFS.

Window: the night of Saturday 31 October to Sunday 1 November 2026, start about 23:45 CET, hard stop 02:30 CET. Expected: about an hour. wordsworth (API and console) is down during the window.

What changes​

PieceTodayAfter
master1, inside the all-in-one on node-013 in Raft, one per worker node
filer metadata (which S3 key is which file)leveldb on node-01's volumePostgres database seaweedfs on the CNPG cluster homelab-pg
filer + S3 gateway1, inside the all-in-one2 stateless pods, any node
volume serversnode-01 (all-in-one) + node-02node-01 (same volume, nothing copied) + node-02 + node-03

The document bytes don't move. The node-01 volume keeps the old leveldb (filerldb2/) and master state (m9333/) untouched; that is the rollback.

The five conditions (Mark, 2026-10-29)​

1. How the master survives losing node-01​

Three masters in Raft, one per worker node (required anti-affinity). Two of three keep a leader. Measured in the rehearsal (below): the masters on the other two nodes elected a new leader 48 seconds after the leader's node was cut off. The cut-off master rejoined as a follower when its node came back. A fresh master needs no state from the old one: it learns the highest volume id and file key from the volume servers' heartbeats (rehearsal: MaxVolumeId correct right after start).

The rest of SeaweedFS also survives losing node-01:

  • Reads: every volume has a copy on a second node (001).
  • Writes: with three volume servers, a new volume still finds two servers to grow on. In the rehearsal, writes kept working with a node cut off.
  • Metadata: the filers keep nothing locally; they read Postgres.

Known limit, measured: after a node goes away, the filers keep trying the lost volume server first for a while before falling back to the copy. In the rehearsal, 16 of 40 reads exceeded a 20-second client timeout in the first minutes. Ten minutes in, it still happened now and then (1 of 40). A kubectl -n seaweedfs rollout restart deploy/seaweedfs-filer cleared it: 40 of 40 reads, twice, with no dial timeouts after. So after losing a node: restart the filers. That is degraded reads, not an outage; today, losing node-01 means no S3 at all until node-01 is back.

2. Where CNPG runs; is a failover expected?​

homelab-pg has 3 instances (CNPG 1.29.1, PostgreSQL 17): primary homelab-pg-1 on node-02, replicas homelab-pg-2 on node-03 and homelab-pg-3 on node-01 (2026-10-31).

No failover is expected. The migration doesn't touch the CNPG pods. Adding a managed role and a Database resource is done online by CNPG's instance manager, without a restart; that is how the keycloak role and database were added. The node-01 drill cuts off only SeaweedFS pods, not homelab-pg-3. Go/no-go requires a healthy cluster with the primary on node-02.

After the migration, S3 depends on homelab-pg, as Keycloak already does. If the primary's node goes away, CNPG promotes a replica and homelab-pg-rw follows. The filers reconnect (connections are recycled every 300 s, and a failed one is replaced). That path was not tested here; it is a separate drill.

3. Restore test of the filer metadata backup​

Done on 2026-10-31 at 08:41 CET, read-only on the live system:

  1. fs.meta.save on the live filer: 441 records (15 directories, 426 files), 187,213 bytes, sha256 3ebcd2ac…f942. Copied off the pod, to jumpy and to the agent host (~/seaweedfs-backup/).
  2. Loaded into a throwaway filer of the target store type (postgres2, own Postgres, own namespace) with fs.meta.load.
  3. Compared every file under /buckets/wordsworth between live and restored through the filer's listing (path, size, md5, each chunk's file id, offset and size).

First result: one file missing. 422 of 423 files came back; the missing one was the backup's last record. Cause, in the 4.39 source (weed/shell/command_fs_meta_load.go): file records are written from goroutines, and at the end of the stream the command returns without waiting for them. The last insert races the shell's exit and is lost without an error.

Fix, without a code change: append a copy of the last directory record to the backup ("sealing"). A directory record makes the loader wait for all pending files first, and re-creating an existing directory is an idempotent upsert. cutover.sh backup does this.

Second result: identical. 423 files and 522 chunks, byte-identical listings (both sha256 e9411b0a…211d). This is the same check as the cutover's verify step.

Also from the restore test: with the database's default collation (en_US.utf8), the postgres2 store warns that S3 listings are not in byte order and falls back to a slower sort. The target config declares the name column COLLATE "C". In the rehearsal the warning was gone.

4. Stop criteria, rollback, post-checks​

See Stop criteria, Rollback and Post-checks below.

5. The date​

Saturday 31 October 2026 was the first attempt; it rolled back at the drill (see "31 October: what stopped it"). Next window: Saturday 7 November 2026, start about 23:45 CET, hard stop 02:30.

31 October: what stopped it, and what changed​

The cutover was clean, but in the node-01 drill writes failed: the node-02 volume server was full (10 of max 10 volumes) and every writable 001 volume had a copy on node-01, so no two servers had a free slot for a new volume. Rollback A; wordsworth was down 737 s. Details: wordsworth#193.

Changed since:

  • Slots (homelab#38): -volume.max=20 / -max=20 on every volume server, and WEED_MASTER_VOLUME_GROWTH_COPY_2=2, so a 001 growth takes two volumes, not six. Empty and test volumes were removed (wordsworth#193, 2 Nov). PR #32 carries the same settings into the HA shape.
  • A slot check: cutover.sh slots lists every volume server's free slots and, per node, how many other servers keep at least 2 free if that node is lost. It stops below 2. In today's shape (2 servers) that can never hold; after the cutover (3 servers) it must.
  • The rehearsal first grows its volumes to production's count (rehearsal/grow.sh), and the write test during the drill stops the rehearsal when it fails. On 31 October the rehearsal had few volumes and could not show the slot problem.
  • Interruption target: the API is down from step 1 to step 6. Expect about 12 minutes, as on 31 October up to the drill. Above 30 minutes without having reached the drill: Rollback A.

Rehearsal (2026-10-31)​

The full migration, with the PR #32 manifests unchanged, in a throwaway namespace seaweedfs-rehearsal with synthetic data. Postgres there was a throwaway pod, standing in for CNPG, without TLS. It started in today's shape (all-in-one + second volume server, bucket with 001, 40 random objects up to 9 MiB). It ran cutover.sh step by step, then drill.sh on a node, then heal, then rollback.

StepResult
mastersRaft leader at once; MaxVolumeId learned from heartbeats
volume serversevery volume id with the same number of copies as before
metadata load + verifyboth filers identical to the baseline (path, size, md5, chunks); filer.conf (the 001 rule) identical
S340/40 objects read back by md5; write + read back OK
node-loss drill (leader's node)new leader after 48 s; writes OK; reads degraded until the filers were restarted (see condition 1)
healmaster rejoined as follower; 3 data nodes; every 001 volume with 2 copies; 40/40
rollback Aall-in-one back from the untouched leveldb: identical to the baseline

Second run, end to end with the final scripts (rehearsal/rehearse.sh, 08:21–08:27 UTC). All steps green: masters, volumes (a filer log volume grown after the baseline is allowed and listed; every baseline volume must be back with the same copies), load, verify on both filers, readall 40/40, writetest OK. Drill on the node holding the old data volume, as node-01 will tonight: a new leader within 60 s, readall and writetest clean before and after the filer restart; heal clean. Through the filer (HTTP), reads did not degrade in this run. The degraded reads of the first run were seen through S3. So the filer restart stays in the drill, and the S3 probe as wordsworth after resume (step 6) is the proof that counts.

Rehearsal (2026-11-05), with production-like slots​

Same setup as above, rendered with rehearsal/render.sh from main and PR #32 (both with 20 slots and growth 2), then rehearsal/grow.sh 7 so the wordsworth collection has production's 7 volumes with 001 before the cutover. rehearse.sh stops at the first failure, including the write test during the drill.

StepResult
grow, baseline7 wordsworth volumes (001), 40 files, 42.4 MB
cutoverRaft leader at once; all 7 baseline volumes back with the same copies; both filers identical; readall 40/40; writetest OK
slots8/20, 10/20, 1/20 used; losing any one node leaves 2 servers with free slots
drill (node with the old data volume)new leader within 60 s; writetest OK with the node cut off (the 31 October stop point); readall 40/40; same after the filer restart
healreadall 40/40, writetest OK, slots OK; S3 check 40/40
Rollback Aapplied in 34 s; old filer identical to the baseline

In a first run the same day, grow.sh failed (the master's HTTP API is not on localhost; fixed) and the rehearsal ran on few volumes; it was green too, except one S3 read right after heal (39/40). Three repeats a minute later gave 40/40: the replaced filer was still starting. In the window, the S3 probe counts once both filers are Ready; a single bad read right after heal is repeated, not acted on.

Restore test, again on 2026-11-05 (read-only on the live system): fs.meta.save of 441 records (15 directories, 426 files), sealed, loaded into a throwaway postgres2 filer with COLLATE "C": 423 files, 1,805,025,235 bytes, identical to the live walk (sha256 e9411b0a…, the same as on 31 October). No collation warning.

Procedure​

Everything runs on jumpy, from a checkout of the PR branch:

cd ~/homelab && git fetch -q && git checkout -q seaweedfs-ha-manifests && git pull -q
kubectl kustomize cluster-config/infra/seaweedfs > ~/ha-target.yaml
cd scripts/seaweedfs-ha
C="./cutover.sh seaweedfs $HOME/ha-target.yaml"

Each cutover.sh step stops with STOP: … when its check fails. Evidence lands in scripts/seaweedfs-ha/evidence-seaweedfs/.

0. Go / no-go (23:30)​

All must hold, otherwise don't start:

  • kubectl -n cnpg-database get cluster homelab-pg: healthy, 3/3 ready, primary homelab-pg-1 (node-02).
  • kubectl -n argocd get app seaweedfs cnpg-database wordsworth: Synced, Healthy.
  • Disk on node-01/02/03 below 85 % (df -h / on the nodes).
  • The S3 probe as wordsworth reads everything: kubectl -n wordsworth cp s3probe.py <api-pod>:/tmp/ && kubectl -n wordsworth exec <api-pod> -- python /tmp/s3probe.py all. It must say bad=0. Write down objects= and bytes=.
  • No factory build running for wordsworth or homelab.
  • ./cutover.sh seaweedfs /dev/null slots prints each volume server's occupancy. In today's shape it ends with STOP (2 servers can't survive a node loss; that is what the window fixes). Just check that every server has at least 4 free slots.
  • cnpg-database may show OutOfSync: a known cosmetic diff (storageClassName, CNPG defaults on the keycloak role). Not a stop, as long as its last sync succeeded.

1. Freeze (23:45)​

systemctl --user stop ratatoskr-agents # on the agent host: no factory deploys in the window
for a in seaweedfs cnpg-database wordsworth; do
kubectl -n argocd patch application $a --type merge -p '{"spec":{"syncPolicy":{"automated":null}}}'
done
kubectl -n wordsworth scale deploy/wordsworth-api --replicas=0 # no writes from here on

2. Baseline and backup​

$C baseline # every file + chunk, volume list, filer.conf
$C backup # fs.meta.save, copied off the pod, sealed; prints sha256

3. Postgres role and database​

The role, the Database seaweedfs and the secret seaweedfs-db in both namespaces exist since 31 October (kept on purpose). Create the secrets only if they are missing:

if ! kubectl -n seaweedfs get secret seaweedfs-db >/dev/null 2>&1; then
PW=$(openssl rand -hex 24)
for ns in cnpg-database seaweedfs; do
kubectl -n $ns create secret generic seaweedfs-db --type=kubernetes.io/basic-auth \
--from-literal=username=seaweedfs --from-literal=password="$PW"
done; unset PW
fi
kubectl apply -n cnpg-database --validate=warn -k ~/homelab/cluster-config/infra/cnpg-database
kubectl -n cnpg-database get cluster homelab-pg -o jsonpath='{.status.managedRolesStatus.byStatus.reconciled}' # contains seaweedfs
kubectl -n cnpg-database get database seaweedfs # APPLIED true

Both flags matter (found with a server-side dry-run on 2026-10-31):

  • -n cnpg-database: the kustomization has no namespace (ArgoCD supplies it). Without the flag, the Database resources land in default.
  • --validate=warn: cluster.yaml has storage.storageClassName, a field CNPG doesn't know (CNPG calls it storageClass). ArgoCD tolerates it; a strict kubectl apply refuses the whole Cluster. The fix is a separate change, not part of this window.

4. Cutover​

$C stop-old # all-in-one to 0 replicas; its volume untouched
$C apply-new # masters, filers, volume servers, Services
$C wait-masters # a Raft leader
$C wait-volumes # every volume id with the same copies as the baseline
$C load # sealed backup into the Postgres store
$C verify # both filers identical to the baseline; filer.conf identical
$C readall # every file read through a filer: md5/size
$C writetest # write, read back, delete outside the buckets
$C slots # 3 servers: losing any one node leaves >= 2 with free slots

Then give the filer log volume (collection '', replication 000, today only on node-01) a second copy:

kubectl -n seaweedfs exec seaweedfs-master-0 -- sh -c 'printf "lock\nvolume.list\nunlock\n" | weed shell -master=seaweedfs-master:9333' | grep "Collection:,"
kubectl -n seaweedfs exec seaweedfs-master-0 -- sh -c 'printf "lock\nvolume.configure.replication -volumeId=<id> -replication=001\nvolume.fix.replication -apply\nunlock\n" | weed shell -master=seaweedfs-master:9333'

5. node-01 drill (writes still frozen)​

./drill.sh seaweedfs node-01 isolate # NetworkPolicy: SeaweedFS pods on node-01 cut off
# after 60 s: a leader on the other two masters
for m in $(kubectl -n seaweedfs get pod -l app=seaweedfs-master -o jsonpath='{.items[*].metadata.name}'); do
kubectl -n seaweedfs exec $m -- wget -qO- -T 5 http://localhost:9333/cluster/status; echo; done
$C writetest # the 31 October stop point: with node-01 gone, writes must work
kubectl -n seaweedfs rollout restart deploy/seaweedfs-filer && kubectl -n seaweedfs rollout status deploy/seaweedfs-filer
$C readall; $C writetest
./drill.sh seaweedfs node-01 heal
# after 45 s: three masters, one leader; then
$C readall; $C writetest
kubectl -n seaweedfs exec seaweedfs-master-0 -- sh -c 'printf "lock\nvolume.fix.replication -verbose\nunlock\n" | weed shell -master=seaweedfs-master:9333' | grep -c "has 2 replicas"

The drill cuts off only SeaweedFS pods on node-01 (masters, the node-01 volume server, a filer). Everything else on node-01 (Keycloak, OpenBao, Ollama, ArgoCD, homelab-pg-3) keeps running, which a kubectl drain would not allow.

6. Resume​

kubectl -n wordsworth scale deploy/wordsworth-api --replicas=2 # as before the window
kubectl -n wordsworth exec <api-pod> -- python /tmp/s3probe.py all # bad=0, same objects= and bytes= as go/no-go

Writes are resumed from here; after this point, rollback is B, not A.

7. Make Git match​

  1. In PR #32, set the roadmap item "Storage survives a node" in docs/reference/roadmap.yml to done, with the #193 comment that reports the migration as evidence. Then merge PR #32.
  2. Make ArgoCD see the merge before restoring auto-sync. Hard-refresh the apps (kubectl -n argocd annotate application seaweedfs cnpg-database wordsworth argocd.argoproj.io/refresh=hard --overwrite) and wait until status.sync.revision of seaweedfs is the merge commit. Then restore auto-sync: kubectl apply -f apps/infrastructure/seaweedfs.yaml -f apps/infrastructure/cnpg-database.yaml -f apps/infrastructure/wordsworth.yaml (on main). On 8 November this was done straight after the merge. ArgoCD still had the pre-merge revision cached and, with selfHeal, brought the all-in-one back for about 2 minutes (Service seaweedfs pointing at the old filer). No writes happened in that window; the API was frozen again, a hard refresh fixed it, and every check was re-run green.
  3. ArgoCD prunes the scaled-down seaweedfs Deployment; the PVC stays. Wait until all three apps are Synced and Healthy.
  4. Start the factory again: systemctl --user start ratatoskr-agents.

8 November: the result​

Done. Interruption 788 s up to the first resume, plus about 6 minutes of a second freeze because of the ArgoCD point above. The node-01 drill: the writetest right after the cut-off failed until the filers were restarted; after the restart it was clean three times, with node-01 still gone. That matches the known limit in condition 1: after losing a node, restart the filers, also for writes. Details: wordsworth#193.

Stop criteria​

WhenStop ifThen
go/no-goCNPG not healthy or primary not on node-02; an app not Synced/Healthy; a node above 85 % disk; the probe has bad>0don't start; new date
step 3role not reconciled or Database not applied within 5 minRollback A (nothing of SeaweedFS has changed yet)
any timeCNPG reports a switchover or failoverpause; $C readall; green → continue, otherwise Rollback A
wait-mastersno Raft leader within 5 minRollback A
wait-volumesvolume list differs from the baseline after 2 minRollback A
load / verifyload error, or any filer differs, or filer.conf differsRollback A
readall / writetestany bad, or FAILRollback A
slots (after cutover)STOP: losing some node leaves fewer than 2 servers with free slotsRollback A
drillno leader on the other two masters within 2 min, or after the filer restart readall/writetest not cleanheal; Rollback A
resumeprobe bad>0 or objects/bytes differ from go/no-goapi to 0, Rollback A
clocknot at step 6 by 02:30 CET, or 30 min after freeze without having reached the drillRollback A

Rollback​

A, before writes resume (step 6). Nothing written since the baseline; the old filer and master state are untouched on node-01's volume. About ten minutes.

kubectl -n seaweedfs delete deploy seaweedfs-filer seaweedfs-volume-data
kubectl -n seaweedfs delete sts seaweedfs-master
kubectl -n seaweedfs delete svc seaweedfs-master-peers
kubectl -n seaweedfs delete cm seaweedfs-filer-config
git -C ~/homelab checkout -q main && kubectl apply -k ~/homelab/cluster-config/infra/seaweedfs
kubectl -n seaweedfs scale deploy/seaweedfs --replicas=1
kubectl -n seaweedfs rollout status deploy/seaweedfs && kubectl -n seaweedfs rollout status sts/seaweedfs-volume

Then:

  1. Check that the old filer is identical to the baseline: walk it with walk.py (as in cutover.sh baseline) and diff against evidence-seaweedfs/before-chunks.tsv.
  2. Restore auto-sync (step 7, without merging), scale the API to 2, run the probe, and start the factory.
  3. The role, database and secret in CNPG can stay; they are unused.
  4. The second new volume server's PVC (data-seaweedfs-volume-1, node-03) can be deleted.

Rehearsed: identical to the baseline.

B, after writes resumed (a problem found later). The new writes are only in Postgres.

  1. Freeze again (step 1).
  2. Run fs.meta.save on a new filer and seal the file as in cutover.sh backup.
  3. Move filerldb2/ aside on node-01's volume (a one-off pod mounting seaweedfs-data), so the old filer starts empty.
  4. Run Rollback A, but keep seaweedfs-volume at 2 replicas: new volumes may have their copies on node-02 and node-03.
  5. fs.meta.load the sealed file into the all-in-one.
  6. volume.fix.replication -apply.
  7. Verify with a walk and the probe.

Not rehearsed.

Post-checks​

  • Right after step 6: probe all as wordsworth, bad=0, same object count and bytes as at go/no-go.
  • Right after step 7: ArgoCD seaweedfs, cnpg-database and wordsworth Synced and Healthy; kubectl -n seaweedfs get pods -o wide shows 3 masters on 3 nodes, 3 volume servers on 3 nodes, 2 filers.
  • The morning after: the console shows documents and a redacted PDF opens (Mark); the daily film check (06:43) passes its storage claims.
  • After a week without problems: remove filerldb2/ and m9333/ from node-01's volume and the old PVC copies of the metadata backup; update SeaweedFS to the new shape.