Database Reference
In-Depth Information
copies of your data and DC2 having three. In the event of a complete data center failure,
you can still work from the other data center.
This strategy is a recommended setting for production setup even if you have just one data
center to start with. To specify this strategy, you should do the following:
{ 'class' : 'NetworkTopologyStrategy'[, '<datacenter_name>'
: <positive_integer>, '<datacenter_name>' :
<positive_integer>, ...] }
Here are a couple of examples:
# Single data center, replication factor: 3
{ 'class' : 'NetworkTopologyStrategy', 'DC1' : 3}
# Three data centers, with RF as 3, 2, and 1
{ 'class' : 'NetworkTopologyStrategy', 'DC_NY' : 3,
'TokyoDC' : 2, 'DC_Hadoop': 1}
# Two data centers with three replica each
{ 'class' : 'NetworkTopologyStrategy', 'DC1' : 3, 'DC2' : 3}
Now, how would each node know which data center it belongs to? Snitch; you configure
snitch in Cassandra's configuration file cassandra.yaml . We have already seen snitch
and how it works and configured in Chapter 2 , Cassandra Architecture , and we will see
them again in Chapter 4 , Deploying a Cluster .
Note that while you may still create a keyspace without any data center configuration
when using NetworkTopologyStrategy , you may get an error when writing data to
Cassandra.
Here are two examples of what your standard keyspace creation looks like:
# Keyspace with SimpleStrategy
CREATE KEYSPACE IF NOT EXISTS demo_keyspace
WITH REPLICATION = { 'class' : 'SimpleStrategy',
'replication_factor' : 3 }
# Keyspace with NetworkTopologyStrategy
CREATE KEYSPACE IF NOT EXISTS demo_keyspace1
Search WWH ::




Custom Search