Product SiteDocumentation Site

6.7. Colocating Sets of Resources

Another common situation is for an administrator to create a set of colocated resources.
One way to do this would be to define a resource group (see Section 10.1, “Groups - A Syntactic Shortcut”), but that cannot always accurately express the desired state.
Another way would be to define each relationship as an individual constraint, but that causes a constraint explosion as the number of resources and combinations grow. An example of this approach:

Example 6.14. Chain of colocated resources

<constraints>
    <rsc_colocation id="coloc-1" rsc="D" with-rsc="C" score="INFINITY"/>
    <rsc_colocation id="coloc-2" rsc="C" with-rsc="B" score="INFINITY"/>
    <rsc_colocation id="coloc-3" rsc="B" with-rsc="A" score="INFINITY"/>
</constraints>

To make things easier, resource sets (see Section 6.5, “Resource Sets”) can be used within colocation constraints. As with the chained version, a resource that can’t be active prevents any resource that must be colocated with it from being active. For example, if B is not able to run, then both C and by inference D must also remain stopped. Here is an example resource_set:

Example 6.15. Equivalent colocation chain expressed using resource_set

<constraints>
    <rsc_colocation id="coloc-1" score="INFINITY" >
      <resource_set id="colocated-set-example" sequential="true">
        <resource_ref id="A"/>
        <resource_ref id="B"/>
        <resource_ref id="C"/>
        <resource_ref id="D"/>
      </resource_set>
    </rsc_colocation>
</constraints>

Important

If you use a higher-level tool, pay attention to how it exposes this functionality. Depending on the tool, creating a set A B may be equivalent to A with B, or B with A.
This notation can also be used to tell the cluster that sets of resources must be colocated relative to each other, where the individual members of each set may or may not depend on each other being active (controlled by the sequential property).
In this example, A, B, and C will each be colocated with D. D must be active, but any of A, B, or C may be inactive without affecting any other resources.

Example 6.16. Using colocated sets to specify a common peer

<constraints>
    <rsc_colocation id="coloc-1" score="INFINITY" >
      <resource_set id="colocated-set-1" sequential="false">
        <resource_ref id="A"/>
        <resource_ref id="B"/>
        <resource_ref id="C"/>
      </resource_set>
      <resource_set id="colocated-set-2" sequential="true">
        <resource_ref id="D"/>
      </resource_set>
    </rsc_colocation>
</constraints>

Important

A colocated set with sequential=false makes sense only if there is another set in the constraint. Otherwise, the constraint has no effect.
There is no inherent limit to the number and size of the sets used. The only thing that matters is that in order for any member of one set in the constraint to be active, all members of sets listed after it must also be active (and naturally on the same node); and if a set has sequential="true", then in order for one member of that set to be active, all members listed before it must also be active.
If desired, you can restrict the dependency to instances of multistate resources that are in a specific role, using the set’s role property.

Example 6.17. Colocation chain in which the members of the middle set have no interdependencies, and the last listed set (which the cluster places first) is restricted to instances in master status.

<constraints>
    <rsc_colocation id="coloc-1" score="INFINITY" >
      <resource_set id="colocated-set-1" sequential="true">
        <resource_ref id="B"/>
        <resource_ref id="A"/>
      </resource_set>
      <resource_set id="colocated-set-2" sequential="false">
        <resource_ref id="C"/>
        <resource_ref id="D"/>
        <resource_ref id="E"/>
      </resource_set>
      <resource_set id="colocated-set-3" sequential="true" role="Master">
        <resource_ref id="G"/>
        <resource_ref id="F"/>
      </resource_set>
    </rsc_colocation>
</constraints>

Colocation chain

Figure 6.4. Visual representation the above example (resources to the left are placed first)


Note

Pay close attention to the order in which resources and sets are listed. While the colocation dependency for members of any one set is last-to-first, the colocation dependency for multiple sets is first-to-last. In the above example, B is colocated with A, but colocated-set-1 is colocated with colocated-set-2.
Unlike ordered sets, colocated sets do not use the require-all option.