Erasure Coding
10+4 shards, the four-server minimum, and what shard placement really looked like
Two full copies cost 2× the storage and survive one failure. Three cost 3× and survive two. Erasure coding gets better durability for less: SeaweedFS splits a volume into 10 data shards and computes 4 parity shards (Reed-Solomon). Any 10 of the 14 rebuild the volume, so it survives losing 4 shards for 1.4× the storage.
| Storage | Survives | |
|---|---|---|
Replication 010 | 2.0× | 1 server |
Replication 020 | 3.0× | 2 servers |
| EC 10+4, shards spread over ≥ 14 servers | 1.4× | 4 servers |
| EC 10+4, on 4 servers | 1.4× | Depends on placement (below) |
The trade-off is CPU and latency: a read whose shard is missing has to fetch 10 others and decode. SeaweedFS applies EC to sealed, warm volumes (full and not written recently), while new writes go to replicated volumes. Hot data stays fast; the bulk of older data gets cheaper.
Encoding
In production you'd leave the defaults (-fullPercent=95 -quietFor=1h)
and run it on a schedule (cron piping commands into weed shell).
On the first try, with three volume servers, ec.encode printed nothing
and changed nothing. With -debug the reason appeared: "skip erasure
coding with 3 nodes, less than recommended 4 nodes." With 14 shards on 3
servers, one server holds at least 5, more than the 4 that parity can
replace. ec.encode -force overrides the check; this cluster got a fourth volume
server instead.
Where the shards went
After encoding six volumes of the drill collection on four servers, and
after ec.balance -apply:
DataNode volume-1:8080
ec volume id:29 collection:drill shards:[3 4 5 6 7 8 9 10 11 12 13]
ec volume id:26 collection:drill shards:[0]
DataNode volume-2:8080
ec volume id:29 collection:drill shards:[0]
DataNode volume-3:8080
ec volume id:29 collection:drill shards:[1]
DataNode volume-4:8080
ec volume id:29 collection:drill shards:[2]Each volume put 11 of its 14 shards on one server. Losing that server
loses 11 shards, more than the 4 that parity covers, so in principle those
volumes can't be rebuilt. ec.balance -apply didn't move them; the older
-force flag is deprecated. The placement guarantees you might expect
from the table above simply weren't there.
Why reads still worked
Stopping volume-1 should have made volumes 25, 29 and 30 unreadable. They
stayed readable. The reason is an artifact of the lab: SeaweedFS stripes a
volume across the 10 data shards in 1 MB blocks, and each drill volume
was only about 1 MB, so all of the data sat in shard 0, which was on
another server. Shards 1 to 9 were essentially empty.
Erasure coding only delivers its durability when every server holds at
most 4 shards of each volume, which in practice means 14 or more
servers (or racks, for rack safety). Use ec.check.replication and
volume.list after encoding to verify placement, and don't trust a
survival test on tiny volumes: test with volumes larger than 10 MB, so
the data really spreads across shards. On small clusters, replication is
simpler and more predictable.
Going back
> ec.decode -collection=drill # rebuild normal volumes from shards
> ec.rebuild -apply # recreate missing shards from the restLab
- Encode the
drillcollection and look at the shard layout withvolume.list. Is it the same as above? - Write 50 objects of 1 MB each to a new bucket so its volume is about 50 MB, encode it, stop the server with the most shards, and run the check. Does the bucket survive now?
- Run
ec.decodeand confirm the volumes are back to two replicas.