Replication & Placement
The xyz placement code, racks and data centers, and repairing missing copies
SeaweedFS replicates volumes, not objects. Every object in a volume has exactly as many copies as the volume, on the same servers. The number and placement of copies is a three-digit code.
The placement code xyz
| Digit | Extra copies |
|---|---|
x | In other data centers |
y | On other racks in the same data center |
z | On other servers in the same rack |
| Code | Copies | Survives |
|---|---|---|
000 | 1 | Nothing. What you get if you don't set one |
001 | 2 | One server, not its rack |
010 | 2 | One rack (this lab's default) |
100 | 2 | One data center |
200 | 3 | Two data centers |
The masters run with -defaultReplication=010. A bucket can use a
different code (in the filer's per-path configuration, fs.configure in
weed shell), so scratch data can be 000 and invoices 010.
docker compose -f compose_prod.yaml run --rm labs python needles.py
volume 4 is on ['volume-1:8080', 'volume-3:8080'] (replication 010: two copies, different racks)
rack1/volume-1:8080: volume 4 size 171184 files 4 replication {'rack': 1}
rack3/volume-3:8080: volume 4 size 171184 files 4 replication {'rack': 1}Writes are synchronous
The volume server that receives a write forwards it to every other replica
and answers only when all of them have it. A 200 OK means every copy is
on disk. The cost: a write is as slow as the slowest replica, and a
write fails if any replica of the chosen volume is unreachable. The
master works around that by assigning new writes only to volumes whose
replicas are all up. With one of four servers down, writes kept working.
With two down, new writes failed with InternalError in the
drill, even though two racks
were still up. Lab question 4 asks you to find out why.
This is replication for durability, not quorum writes. There's no "2 of 3" here: all copies or failure. Raft quorums are used only among the masters, for cluster metadata.
Losing a copy
When a volume server dies, its volumes are under-replicated: one copy left. SeaweedFS doesn't repair this on its own, because a server that's rebooting would otherwise trigger terabytes of copying. You decide:
docker stop volume-4
docker exec -it master-1 weed shell -master=master-1:9333
> lock
> volume.fix.replication # dry run
Running in simulation mode. Use "-apply" option to apply the changes.
volume 38 replication 010, but under replicated +1
...
replicating volume 42 010 from volume-3:8080 to dataNode volume-2:8080 ...
replicating volume 39 010 from volume-2:8080 to dataNode volume-3:8080 ...
failed to place volume 38 replica as 010, existing:1
failed to place volume 45 replica as 010, existing:1
failed to place volume 44 replica as 010, existing:1
failed to place volume 34 replica as 010, existing:1
> volume.fix.replication -apply # actually copyFour volumes couldn't be repaired: the three remaining servers had only 10 free volume slots between them. Repair needs spare capacity.
Keep enough free space that the cluster can re-replicate the contents of
its largest failure domain. With 4 racks, that means staying under about
75% full, and less if a rack can hold more than a quarter of the data.
The alert SeaweedFSDiskFillingUp fires at 15% free, which is already
too late for that.
Here the server came back instead. Its volumes rejoined, and the dry run
reported nothing to fix. The SeaweedFS_master_under_replicated_volumes
metric took about 5 minutes longer to drop back to 0, because the
leader only recounts it on its periodic volume-growth pass. Alerts on it
need a for: longer than that, or they flap.
Other housekeeping
Lab
- Stop
volume-4, runvolume.fix.replicationdry, then with-apply. Startvolume-4again. What does the cluster do with the extra copies? - Write to a bucket configured for
000and stop the server holding its volume. What happens on GET? - Run
volume.check.diskand read what it compares. - Stop
volume-2andvolume-3, then try a write and read the leader master's log andvolume.list. Which volumes were writable, where were their copies, and did the master grow new ones on the survivors?