Rack awareness
When you create a topic, you specify the number of partitions for the topic and the number of partition replicas. Redpanda software determines where to place the replicas on the cluster such that each replica is on a different node, if possible.
By defining different racks for a cluster, you can specify a preference for the way partition replicas are assigned to nodes. A rack is basically a failure zone, with one or more nodes assigned to it. When the Redpanda software places partition replicas, it takes into account whether a replica has already been placed on a node in a particular rack. If so, the software chooses a node in a different rack. This way, partition replicas are distributed across different failure zones, which provides a measure of fault tolerance in the event that a node or an entire rack becomes unavailable.
When rack awareness is enabled, the Redpanda software places replicas according to these criteria:
-
Number of racks vs. replicas - If the cluster has more racks than the number of replicas, each replica is placed on a node in a unique rack. If the cluster has fewer racks than the number of replicas, some replicas are placed on nodes in the same rack.
-
Number of available CPU cores - Nodes with more available CPU cores are chosen over nodes with fewer available CPU cores.
-
Node utilization - Nodes with fewer partitions are chosen over nodes with more partitions.
Setting up rack awareness
The instructions in this section are based on a cluster with five nodes and three failure zones. The failure zones, or racks, are identified as A, B, and C. The nodes are assigned to the three racks as shown:
Node | Rack |
---|---|
1 |
A |
2 |
A |
3 |
B |
4 |
C |
5 |
C |
To set up rack awareness for this cluster:
-
Open a terminal window and log in to node 1 on the cluster.
-
Run
rpk cluster config edit
. -
In the text editor window that opens, set
enable_rack_awareness
totrue
. -
Save your change and quit the editor.
-
Go to the
/etc/redpanda
directory. -
Open the
redpanda.yaml
file for editing. -
In the
redpanda
section, add therack
property and set the value to A as shown:rack: "A"
-
Log in to the remaining nodes and edit their
redpanda.yaml
files. For node 2, setrack
toA
. For node 3, setrack
toB
. For nodes 4 and 5, setrack
toC
. -
Restart each node in the cluster for the rack assignments to take effect.