Databases Reference
In-Depth Information
A1
D2
C3
A
B
D1
C2
B3
B1
A2
D3
Figure 8.5 A sample of how replication works on a
Cassandra keyspace using the SimpleStrategy
configuration. Items A1, B1, C1, and D1 are written
to a four-node cluster with a replication factor of 3.
Each item is stored on three distinct nodes. After
writing to an initial node, Cassandra “walks around
the ring” in a clockwise direction until it stores the
item on two additional nodes.
D
C
C1
B2
A3
An example of a Cassandra keyspace is usually drawn as a ring, as illustrated in
figure 8.5.
Cassandra allows you to fine-tune replication based on the properties of keyspace.
When you add any row to a Cassandra system, you must associate a keyspace with that
row. Each keyspace allows you to set and change the replication factor of that row. An
example of a keyspace declaration is shown in figure 8.6.
Using this strategy will allow you to evenly distribute the rows over all the nodes in
the cluster, eliminating bottlenecks. Although you can use specific bits in your key,
this practice is strongly discouraged, as it leads to hotspots in your cluster and can be
administratively complex. The main disadvantage with this approach is that if you
change your partitioning algorithm, you have to save and restore your entire dataset.
When you have multiple racks or multiple data centers, the algorithm might need
to be modified to ensure data is written to multiple racks or even to multiple data cen-
ters before the write acknowledgement is returned. If you change the placement-
strategy value from SimpleStrategy to NetworkTopologyStrategy , Cassandra will walk
around the ring until it finds a node that's on a different rack or a different data center.
Because Cassandra has a full peer-to-peer deployment model, it's seen as a good fit
for organizations that want both scalability and availability in a column family system.
In our next case study, you'll see how Couchbase 2.0 uses a peer-to-peer model with a
JSON document store.
For a single location site, use “SimpleStrategy.”
If you have multiple sites, use “NetworkTopologyStrategy.”
CREATEKEYSPACE myKeySpace
with placement_strategy='org.apache.cassandra.locator.SimpleStrategy'
and strategy_options={replication_factor:3};
We set a replication factor of 3 so that each
item will be stored on three separate nodes in the cluster.
Figure 8.6 A sample of how replication is configured within Cassandra. Replication is
a property of keys that indicates the type of network you're on and the replication for
each key.
Search WWH ::




Custom Search