CRUSH MAP RULES
CRUSH maps support the notion of ¡®CRUSH rules¡¯, which are the rules that determine data placement for a pool. For large clusters, you will likely create many pools where each pool may have its own CRUSH ruleset and rules. The default CRUSH map has a rule for each pool, and one ruleset assigned to each of the default pools.
Note
In most cases, you will not need to modify the default rules. When you create a new pool, its default ruleset is 0
.
CRUSH rules define placement and replication strategies or distribution policies that allow you to specify exactly how CRUSH places object replicas. For example, you might create a rule selecting a pair of targets for 2-way mirroring, another rule for selecting three targets in two different data centers for 3-way mirroring, and yet another rule for erasure coding over six storage devices. For a detailed discussion of CRUSH rules, refer to CRUSH - Controlled, Scalable, Decentralized Placement of Replicated Data, and more specifically to Section 3.2.
A rule takes the following form:
rule <rulename> {
ruleset <ruleset>
type [ replicated | erasure ]
min_size <min-size>
max_size <max-size>
step take <bucket-name> [class <device-class>]
step [choose|chooseleaf] [firstn|indep] <N> <bucket-type>
step emit
}
ruleset
Description: | A means of classifying a rule as belonging to a set of rules. Activated by setting the ruleset in a pool. |
---|
Purpose: | A component of the rule mask. |
---|
Type: | Integer |
---|
Required: | Yes |
---|
Default: | 0 |
---|
type
Description: | Describes a rule for either a storage drive (replicated) or a RAID. |
---|
Purpose: | A component of the rule mask. |
---|
Type: | String |
---|
Required: | Yes |
---|
Default: | replicated |
---|
Valid Values: | Currently only replicated and erasure |
---|
min_size
Description: | If a pool makes fewer replicas than this number, CRUSH will NOT select this rule. |
---|
Type: | Integer |
---|
Purpose: | A component of the rule mask. |
---|
Required: | Yes |
---|
Default: | 1 |
---|
max_size
Description: | If a pool makes more replicas than this number, CRUSH will NOT select this rule. |
---|
Type: | Integer |
---|
Purpose: | A component of the rule mask. |
---|
Required: | Yes |
---|
Default: | 10 |
---|
step take <bucket-name> [class <device-class>]
Description: | Takes a bucket name, and begins iterating down the tree. If the device-class is specified, it must match a class previously used when defining a device. All devices that do not belong to the class are excluded. |
---|
Purpose: | A component of the rule. |
---|
Required: | Yes |
---|
Example: | step take data |
---|
step choose firstn {num} type {bucket-type}
Description: | Selects the number of buckets of the given type. The number is usually the number of replicas in the pool (i.e., pool size). - If
{num} == 0 , choose pool-num-replicas buckets (all available). - If
{num} > 0 && < pool-num-replicas , choose that many buckets. - If
{num} < 0 , it means pool-num-replicas - {num} .
|
---|
Purpose: | A component of the rule. |
---|
Prerequisite: | Follows step take or step choose . |
---|
Example: | step choose firstn 1 type row
|
---|
step chooseleaf firstn {num} type {bucket-type}
Description: | Selects a set of buckets of {bucket-type} and chooses a leaf node from the subtree of each bucket in the set of buckets. The number of buckets in the set is usually the number of replicas in the pool (i.e., pool size). - If
{num} == 0 , choose pool-num-replicas buckets (all available). - If
{num} > 0 && < pool-num-replicas , choose that many buckets. - If
{num} < 0 , it means pool-num-replicas - {num} .
|
---|
Purpose: | A component of the rule. Usage removes the need to select a device using two steps. |
---|
Prerequisite: | Follows step take or step choose . |
---|
Example: | step chooseleaf firstn 0 type row
|
---|
step emit
Description: | Outputs the current value and empties the stack. Typically used at the end of a rule, but may also be used to pick from different trees in the same rule. |
---|
Purpose: | A component of the rule. |
---|
Prerequisite: | Follows step choose . |
---|
Example: | step emit |
---|
Important
To activate one or more rules with a common ruleset number to a pool, set the ruleset number of the pool.