Learn Labs
Durability

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.

StorageSurvives
Replication 0102.0×1 server
Replication 0203.0×2 servers
EC 10+4, shards spread over ≥ 14 servers1.4×4 servers
EC 10+4, on 4 servers1.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

docker exec -it master-1 weed shell -master=master-1:9333> lock> ec.encode -collection=drill -fullPercent=0 -quietFor=1slab: encode even small, recent volumes> ec.balance -applyspread shards> volume.listsee where they went> unlock

In production you'd leave the defaults (-fullPercent=95 -quietFor=1h) and run it on a schedule (cron piping commands into weed shell).

Where the shards went

After encoding six volumes of the drill collection on four servers, and after ec.balance -apply:

servervol 25shardsvol 26shardsvol 27shardsvol 28shardsvol 29shardsvol 30shardsvolume-1!✓✓✓!!volume-2✓✓✓✓✓✓volume-3✓!!!✓✓volume-4✓✓✓✓✓✓
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.

Going back

> ec.decode -collection=drill     # rebuild normal volumes from shards
> ec.rebuild -apply                # recreate missing shards from the rest

Lab

  1. Encode the drill collection and look at the shard layout with volume.list. Is it the same as above?
  2. 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?
  3. Run ec.decode and confirm the volumes are back to two replicas.

On this page