1 ============================
2 PG (Placement Group) notes
3 ============================
5 Miscellaneous copy-pastes from emails, when this gets cleaned up it
6 should move out of /dev.
11 PG = "placement group". When placing data in the cluster, objects are
12 mapped into PGs, and those PGs are mapped onto OSDs. We use the
13 indirection so that we can group objects, which reduces the amount of
14 per-object metadata we need to keep track of and processes we need to
15 run (it would be prohibitively expensive to track eg the placement
16 history on a per-object basis). Increasing the number of PGs can
17 reduce the variance in per-OSD load across your cluster, but each PG
18 requires a bit more CPU and memory on the OSDs that are storing it. We
19 try and ballpark it at 100 PGs/OSD, although it can vary widely
20 without ill effects depending on your cluster. You hit a bug in how we
21 calculate the initial PG number from a cluster description.
23 There are a couple of different categories of PGs; the 6 that exist
24 (in the original emailer's ``ceph -s`` output) are "local" PGs which
25 are tied to a specific OSD. However, those aren't actually used in a
26 standard Ceph configuration.
29 Mapping algorithm (simplified)
30 ==============================
32 | > How does the Object->PG mapping look like, do you map more than one object on
33 | > one PG, or do you sometimes map an object to more than one PG? How about the
34 | > mapping of PGs to OSDs, does one PG belong to exactly one OSD?
36 | > Does one PG represent a fixed amount of storage space?
38 Many objects map to one PG.
40 Each object maps to exactly one PG.
42 One PG maps to a single list of OSDs, where the first one in the list
43 is the primary and the rest are replicas.
45 Many PGs can map to one OSD.
47 A PG represents nothing but a grouping of objects; you configure the
48 number of PGs you want, number of OSDs * 100 is a good starting point
49 , and all of your stored objects are pseudo-randomly evenly distributed
50 to the PGs. So a PG explicitly does NOT represent a fixed amount of
51 storage; it represents 1/pg_num'th of the storage you happen to have
54 Ignoring the finer points of CRUSH and custom placement, it goes
55 something like this in pseudocode::
58 obj_hash = hash(locator)
59 pg = obj_hash % num_pg
60 OSDs_for_pg = crush(pg) # returns a list of OSDs
61 primary = osds_for_pg[0]
62 replicas = osds_for_pg[1:]
64 If you want to understand the crush() part in the above, imagine a
65 perfectly spherical datacenter in a vacuum ;) that is, if all OSDs
66 have weight 1.0, and there is no topology to the data center (all OSDs
67 are on the top level), and you use defaults, etc, it simplifies to
68 consistent hashing; you can think of it as::
71 all_osds = ['osd.0', 'osd.1', 'osd.2', ...]
73 # size is the number of copies; primary+replicas
74 while len(result) < size:
76 chosen = all_osds[ r % len(all_osds) ]
78 # OSD can be picked only once
83 User-visible PG States
84 ======================
86 .. todo:: diagram of states and how they can overlap
89 the PG is still being created
92 requests to the PG will be processed
95 all objects in the PG are replicated the correct number of times
98 a replica with necessary data is down, so the pg is offline
101 the PG is waiting for clients to replay operations after an OSD crashed
104 the PG is being split into multiple PGs (not functional as of 2012-02)
107 the PG is being checked for inconsistencies
110 some objects in the PG are not replicated enough times yet
113 replicas of the PG are not consistent (e.g. objects are
114 the wrong size, objects are missing from one replica *after* recovery
118 the PG is undergoing the :doc:`/dev/peering` process
121 the PG is being checked and any inconsistencies found will be repaired (if possible)
124 objects are being migrated/synchronized with replicas
127 the PG is waiting for the local/remote recovery reservations
130 a special case of recovery, in which the entire contents of
131 the PG are scanned and synchronized, instead of inferring what
132 needs to be transferred from the PG logs of recent operations
135 the PG is waiting in line to start backfill
138 backfill reservation rejected, OSD too full
141 a pg is missing a necessary period of history from its
142 log. If you see this state, report a bug, and try to start any
143 failed OSDs that may contain the needed information.
146 the PG is in an unknown state - the monitors have not received
147 an update for it since the PG mapping changed.
150 the PG is temporarily mapped to a different set of OSDs from what