Data durability
Ceph strives to prevent the permanent loss of data. However, after an OSD fails, the risk of permanent data loss increases until the data it had is fully recovered. Permanent data loss, though rare, is still possible.
The following scenario describes how Ceph could permanently lose data in a single placement group with three copies of the data:
-
An OSD fails and all copies of the object it contains are lost. For all objects within a placement group stored on the OSD, the number of replicas suddenly drops from three to two.
-
Ceph starts recovery for each placement group stored on the failed OSD by choosing a new OSD to re-create the third copy of all objects for each placement group.
-
The second OSD containing a copy of the same placement group fails before the new OSD is fully populated with the third copy. Some objects will then only have one surviving copy.
-
Ceph picks yet another OSD and keeps copying objects to restore the desired number of copies.
-
The third OSD containing a copy of the same placement group fails before recovery is complete. If this OSD contained the only remaining copy of an object, the object is lost permanently.
Hardware failure isn’t an exception, but an expectation. To prevent the foregoing scenario, ideally the recovery process should be as fast as reasonably possible. The size of your cluster, your hardware configuration and the number of placement groups play an important role in total recovery time.
Small clusters don’t recover as quickly.
In a cluster containing 10 OSDs with 512 placement groups in a three replica pool, CRUSH will
give each placement group three OSDs. Each OSD will end up hosting (512 * 3) / 10 =
~150 placement groups. When the first OSD fails, the cluster will start recovery for all
150 placement groups simultaneously.
It is likely that Ceph stored the remaining 150 placement groups randomly across the 9 remaining OSDs. Therefore, each remaining OSD is likely to send copies of objects to all other OSDs and also receive some new objects, because the remaining OSDs become responsible for some of the 150 placement groups now assigned to them.
The total recovery time depends upon the hardware supporting the pool. For example, in a 10 OSD
cluster, if a host contains one OSD with a 1 TB SSD, and a 10 GB/s switch connects each of the 10
hosts, the recovery time will take M minutes. By contrast, if a host contains two
SATA OSDs and a 1 GB/s switch connects the five hosts, recovery will take substantially longer.
Interestingly, in a cluster of this size, the number of placement groups has almost no influence on
data durability. The placement group count could be 128 or 8192 and the recovery would not be slower
or faster.
However, growing the same Ceph cluster to 20 OSDs instead of 10 OSDs is likely to speed up recovery and therefore improve data durability significantly. Why? Each OSD now participates in only 75 placement groups instead of 150. The 20 OSD cluster will still require all 19 remaining OSDs to perform the same amount of copy operations in order to recover. In the 10 OSD cluster, each OSDs had to copy approximately 100 GB. In the 20 OSD cluster each OSD only has to copy 50 GB each. If the network was the bottleneck, recovery will happen twice as fast. In other words, recovery time decreases as the number of OSDs increases.
In large clusters, PG count is important!
If the exemplary cluster grows to 40 OSDs, each OSD will only host 35 placement groups. If an OSD
dies, recovery time will decrease unless another bottleneck precludes improvement. However, if this
cluster grows to 200 OSDs, each OSD will only host approximately 7 placement groups. If an OSD dies,
recovery will happen between at most of 21 (7 * 3) OSDs in these placement groups:
recovery takes longer than when there were 40 OSDs, meaning the number of placement groups should be
increased!
In the 10 OSD cluster described, if any OSD fails, then approximately 8 placement groups (that is
75 pgs / 9 osds being recovered) will only have one surviving copy. And if any of
the 8 remaining OSDs fail, the last objects of one placement group are likely to be lost (that is
8 pgs / 8 osds with only one remaining copy being recovered). This is why starting
with a somewhat larger cluster is preferred (for example, 50 OSDs).
35 pgs / 19
osds being recovered) instead of 8 and the third OSD lost will only lose data if it is one
of the two OSDs containing the surviving copy. In other words, if the probability of losing one OSD
is 0.0001% during the recovery time frame, it goes from 8 *
0.0001% in the cluster with 10 OSDs to 2 * 0.0001% in the cluster with 20
OSDs. Having 512 or 4096 placement groups is roughly equivalent in a cluster with less than 50 OSDs
as far as data durability is concerned.When you add an OSD to the cluster, it might take a long time to populate the new OSD with placement groups and objects. However there is no degradation of any object and adding the OSD has no impact on data durability.