A replication strategy determines which nodes store replicas of each partition. NetworkTopologyStrategy accounts for datacenters and racks, placing replicas across failure domains instead of treating the cluster as a flat ring. section 5.2.2
NetworkTopologyStrategy places replicas by following this process:
- Assign each datacenter a replication factor. section 5.2.2
- Locate the partition on the ring and identify its owning node in each datacenter. section 5.2.2
- Select the next node in the same datacenter but a different rack, then continue until the datacenter’s replication factor is satisfied. section 5.2.2
Creating a topology-aware keyspace
This configuration gives datacenter1 three replicas for each partition: CREATE KEYSPACE reviews WITH replication = { 'class': 'NetworkTopologyStrategy', 'datacenter1': '3'};. With three racks, the placement can tolerate an entire rack failure; quorum-based consistency can continue serving traffic. section 5.2.2
Listing 5.1 Creating your keyspace
cqlsh> CREATE KEYSPACE reviews WITH replication = {
'class': 'NetworkTopologyStrategy', 'datacenter1': '3'};
Use the runnable CQL listing to configure a keyspace with NetworkTopologyStrategy. section 5.2.2
