CRUSH. How do we allocate the data? Bottom principles dismantled.
From PG Map to OSD Selection , Dismantling CRUSH Algorithms are distributed storage Data distribution process in place 、 Fragmentation area isolation mechanism and practical engineering attention 。
CRUSH Algorithms How do you allocate the data? Distributed storage Bottom Method Dismantling
You go to distribution. storage It's in there. one File , Where did this document end up? server On which disk? , Who decided that? ?
It's not a manual assignment by the administrator, it's not a random throw, but an algorithm called CRUSH. This article opens up the complete process of CRUSH from input to output, including the reason why it does not use traditional Hashi, how to control the distribution of copies through Rule and how to use the easy pits in actual deployment.
I. CRUSH What is it?
CRUSH, full name Controlled Replication Under Scalable Hashing(Moderable copy of expandable Hash) is the cores data distribution algorithm for Ceph distributed system storage Its role is clear: to assign a data object and to calculate which OSD (Object Storage Device, object storage device) it should be stored.
Controllable is the key word. The old Hashi algorithm is "sail" data, and you can't control it. CRUSH It's... "Controlled" represented by : You can pass. Rule( Rule ) Which shelf is the exact control copy? 、 Which node? 、 On which plate? , Instead of giving it to random numbers. 。
The EDSFS storage engine for Sangfor EDS is based on an improved CRUSH algorithm to achieve data distribution, adding weight perception and load balancing capabilities to the original CRUSH and will be discussed later.
II. WHY NOT USE THE TRADITIONAL HUSH
Distribution storage Area , Data distribution algorithms more than that. CRUSH One. 。 The most often compared is Consistent Hashing. Many would ask, "Why do you want to get a CRUSH if Hashi has solved the problem of "nodes and drops, and minimizes data"?
Three cores reasons:
1. Harmonious Hash's migration is still not small enough.
Consistency Hashi, when it comes to nodes, only the data in the adjacent sections need to be migrated, and it already looks good. However, in large clusters, a significant proportion of data is still being migrated for each expansion. CRUSH is different - it is based on a hierarchical structure of cluster expansion, with only PG involving new nodes needing to be remaridated and data available do not need to be fully re-distributed. The particle size of the migration changed from "object class" to "PG class" and the volume of data migration was significantly reduced.
2. Consistency Hash can't control a copy falling in different fault fields
This is the deadliest question. Convergence Hashi only "salute the data evenly" regardless of "separate between copies." Suppose you have 3 copies, Hashi might have left 2 copies on the same shelf. Once this hanger is out of power, 2 copies are lost and the data is gone.
CRUSH is visible by Rule: copy 1 selects host A, copy 2 must choose host B, copy 3 must select host C - three copies must be distributed on different host. This faulty territorial isolation capability is not possible for Hashi to do so.
Rule mechanism for 3. CRUSH to define placement policy
Harsh's distribution strategy is fixed -- the Hash function determines everything, and you can change it only by changing the Hash function. Rule of CRUSH is a configurable logic that you can define:
- How many copies are there?
- At which level each copy should be isolated (host, rack, row)
- Whether or not to go through the decoded mode.
- Whether to distinguish between SSD and HDD storage pools
Change Rule without changing the algorithm, change the configuration. This flexibility is much needed in engineering.
III. CRUSH How to Work: A complete link from object to OSD
CRUSH is not one step in the way. A data object is mapped twice, from writing to finally landing on disk. The following is broken down in order.
Step one. : Object → PG(Placement Group)
The data object first passed a Hash map and landed in a PG (Placement Group, group). formulae:
```
pg_id = hash (object name) %PG quantity
```
PG What is it? ? You can interpret it as a "data bucket". One. storage Thousands to tens of thousands of clusters. PG, Every one PG Responsible for a group of objects 。 This PG mid-map was introduced to reduce the CRUSH calculation frequency - each cluster expansion is recalculated for all objects, with quantity moving in the hundreds of millions, and calculated to explode if the object is directly mapped to OSD. With PG, only CRUSH calculations for PG quantity level are required, and the mapping of objects to PG remains unchanged.
For example: 1024 PG, you write a file called "report.pdf " , the system calculates hash ( " report.pdf " ) % 1024 ' , assuming 768, the file is placed under PG 768.
Step two. :PG → OSD(CRUSH cores Calculate )
PG after ID has been taken, hand over to CRUSH algorithms to calculate which OSD should fall. CRUSH has three inputs:
| input | Description |
|---|---|
| PG ID | Relocation group number from the previous step |
| Rule | Place rules, define the number of copies and the trouble zone isolation policy |
| Cluster Map | Cluster scale map describing all OSD hierarchical relationships |
output is a group of OSD lists, such as `[OSD.12, OSD.35, OSD.78] ', which indicates that the main copy of this PG is in OSD.12, and two others in OSD.35 and OSD.78.
Step three. :Cluster Map—— The tree structure of a cluster.
CRUSH is capable of placing a faulty area in isolation, depending on Cluster Map. It's a tree. Levels from top to bottom:
```
root (root)
└── row( Okay. / Regional )
rack (Falkage)
host (host/node)
– - osd (storage Device)
disk (disk)
```
Each OSD is a leaf node, hanging under a host; Each host hangs under a rack to push like this. CRUSH will follow the tree from the top down when OSD is selected, and each level is selected and isolated.
Step four. :Rule—— How? OSD It's...
Rule is a step-by-step logic that defines the way CRUSH goes through Cluster Map. Take a typical 3 copy of Rule as an example:
```
rule replicated_rule {
ruleset 0
type replicated
min_size 1
max_size 10
step take root # Start with root
step chooseleaf firstn 0 type host # Select 3 Different OSD under host
step emit # Output result
}
```
Rule means:
1. take root: Start with root node of Cluster Map
2. chooseleaf firstn 0 type host: Selection 3 (firstn 0 Organisation num_replicas ) Different. host, And from each of them. host Next pick. one OSD
3. emit: Output final OSD list
The key is `type host ' , this specifications - it specifies the level of faulty area isolation. Sets host, which means that 3 copies must be on 3 and two different host. If `type rack ' is set, 3 copies must be placed on 3 on different shelves, with a higher level of isolation and tolerance for the whole rack failure.
The practical effects of a faulty area isolation
Assuming that the cluster has 3 racks, each of which is 4 hosts, each of which is 6 block OSD:
- Rule set `type host ': 3 copies distributed on 3 different host, and single host machines do not lose data, but a power outage of the same rack could result in a portion of PG of 2 copies being simultaneously unavailable (if this 2 copy coincides with a different host on this shelf)
- Rule set `type rack ': 3 copy distributed on 3 on different racks, undiscarded data on the whole of the single rack, highest level of isolation
The choice of the level depends on what you're looking for. The host level is sufficient for the general small and medium-sized clusters, and the rack level is recommended for large clusters or scenarios with high availability requirements.
Impact of CRUSH in actual operations and maintenance
Understands the rationale for CRUSH, and looks at several of the typical scenarios in operations and maintenance is clear.
scene 1: cluster expansion
Cluster Map updates with new 3 node access to the cluster. CRUSH recalculates all OSD maps for PG. Part of PG will be removed to OSD as the new node has added weight to Cluster Map. But the key is:Only remembraced PG needs to migrate data, the remaining OSD list of PG remains unchanged and existing data remain unchanged。
The difference between this and Hashi is that when Hashi is growing, all the objects in the immediate vicinity of the new node are to migrate; CRUSH is expanded by PG, which is thicker in size but more manageable in total. In the actual project, the data migration is usually at several TB levels, rather than full weight distribution, to a cluster with 3 nodes where 100TB data are available.
scene 2: Node failure
Some station. host Shut up! ,Cluster Map It's time. host Down OSD Marked as down。 CRUSH Recalculations relate to these OSD It's... PG, Re-map them to other living ones. OSD Let's go. 。 What's the process? automatic It's... —— storage Cluster detected OSD After offline. , Trigger PG It's... rebackfill( Backfill ), Copy data from remaining copy to newly selected OSD, Restore copies 。
scene 3: improvement of Sangfor EDS
The original CRUSH algorithm for Ceph has a known problem: weighting is not sufficiently precise to allow for uneven data distribution, especially in the context of node isomers (different capacity disk mix). The EDSFS engine for Sangfor EDS has been improved on CRUSH:
- Weight perception: not just by OSD quantity distribution, but by real capacity weight dynamic, large capacity disc multiples, small capacity lesss
- load balancing: Double-balance based on CRUSH calculations to avoid some OSD becoming hot spots
- Supported:CRUSH Algorithms? supports only Copy mode , Yeah. Supported & Delete mode , both The choice was detailed before us. contrast Pass. (EDS Copy Numbers and Redemption Numbers Which) copy mode for small files and high-random read/write scene, and decode for big files and capacity priority archive scene
V. WHAT TO BE ATTENTION IN THE PRACTICE OF PRACTICE
The CRUSH algorithm itself is well designed, but bad use can cause serious problems. The following three are the most common pits in the project.
1. PG quantity Uneven data due to inappropriate settings
PG quantity sets the cost of subsequent changes (to trigger PG division and data re-distribution) when creating storage pool. PG is too small, each PG carries a large amount of data, and single PG migration takes time; PG is too much, CRUSH calculates the cost and memory occupancy increase.
Officially recommends that:Each OSD loads 50-100 and PG。 formulae:
```
Total PG = OSD quantity x OSD Expected PG / Copy
```
For example: :30 OSD,3 Copy , Every OSD Objective 100 PG:
```
Total PG = 30 × 100 / 3 = 1000
```
Take the nearest 2 number and set it to 1024. If set to 128, only about 13 PG per OSD will the data distribution be tilted; If set to 8192, the cost per OSD approximately 273 PG, CRUSH calculation and memory significantly increases.
2. CRUSH Rule error caused a copy to fall in the same malfunction area
This is the most dangerous mistake. If `type ' in Rule is set to be `osd ' instead of `host ' , CRUSH only ensures that 3 copies fall on 3 different OSD, but not on a different host. The result could be that all copies of 3 were on the same 3 plate of host, the host machine, and the data was thrown out.
(b) Quest method: Check the actual map of PG to OSD with crushtool --test --show-mappings ' to confirm that multiple copies of the same PG are actually distributed in different fault areas. Verification must be done before the production environment is online.
3. CRUSH Calculating Costs for Large Clusters
When cluster size reached 100+ nodes and thousands of OSD, CRUSH was calculated through Cluster Map trees at each time, and the amount of calculation could not be ignored. Although it's a single count. ms Level , But the whole cluster. PG Remagnating ( Like a big area. OSD Failure recovery. ), Number one thousand PG Trigger simultaneously. CRUSH Recosting ,CPU There's a clear peak. 。
Response:
- Control the scale of single-stamper changes, batch access to new nodes
- Rational setting of PG quantity to avoid PG too many to calculate magnification
- Focus on the CRUSH Tree level depth, which increases the cost of going through it.
It's at the end.
The value of cores for CRUSH algorithms is:Turning the data distribution from a pure Hash problem to a configurable problem of popping perception.。 It allows distributed storage to have a certain control capacity on three key scenarios: amplification, failure recovery, and copy isolation.
Understanding the rationale for CRUSH is relevant for both the distributional storage selection and operations and maintenance. If you're assessing...Difference between hyperconverged infrastructure and distributed storageOr want to know.What's the hyperconverged infrastructure option?,CRUSH The data distribution mechanism is: one An important technical judgement dimension. —— hyperconverged infrastructure It's usually calculated and storage Integration deployment , Distribution storage And focus. storage Independence expansion , both Yes. CRUSH There are significant differences in the way in which they are used and in the design of the malfunctioning area. 。
In actual deployment, PG quantity planning, Rule configuration validation, and large-scale cluster computing cost management are three key points that have used CRUSH well. CRUSH is the cornerstone of the reliability of distributed storage data; The configuration is wrong, and it can also be a hazard to data loss.











