Database Reference
In-Depth Information
NOTE
For determining replica placement, Cassandra implements the Gang of Four Strategy pattern. The
strategy is outlined in the common abstract class, allowing different implementations of an algorithm
(different strategies for accomplishing the same work). Each algorithm implementation is encapsulated
inside a single class that adheres to the interface. So you can provide the strategy framework a variety
of different implementations of the algorithm, all of which are interchangeable to the runtime. Clients
do not have to be concerned about which strategy is used. A common use of the Strategy pattern is for
sorting. Imagine a SortStrategy interface with a single sort operation and different implementations
for Quicksort , Mergesort , and so on. Each sorts in different ways, depending on your needs.
The interface provides 11 public methods that require implementation; if your strategy can make
use of some of the method implementations provided in the abstract parent, then you can over-
ride only the methods you want. Of course, you don't have to implement this yourself. Out of
the box, Cassandra provides three implementations of this interface (extensions of the abstract
class): Rack-Aware Strategy, Rack-Unaware Strategy, and Data Center Shard Strategy.
Choosing the right replication strategy is important because the strategy determines which nodes
are responsible for which key ranges. The implication is that you're also determining which nodes
should receive which write operations, which can have a big impact on efficiency in different
scenarios. If you set up your cluster such that all writes are going to two data centers—one in
Australia and one in Reston, Virginia—you will see a matching performance degradation. The
variety of pluggable strategies allows you greater flexibility, so that you can tune Cassandra ac-
cording to your network topology and needs.
The first replica will always be the node that claims the range in which the token falls, but the
remainder of the replicas are placed according to the replica placement strategy you use.
NOTE
As I write this chapter, the names of the strategies are changing. The new names in 0.7 will be
SimpleStrategy (formerly known as RackUnawareStrategy ), OldNetworkTopologyStrategy
(formerly known as RackAwareStrategy ), and NetworkTopologyStrategy (formerly known as
DatacenterShardStrategy) .
Simple Strategy
Simple Strategy is the new name for Rack-Unaware Strategy.
The strategy used by default in the configuration file is org.apache.cassandra.locat-
or.RackUnawareStrategy . This strategy only overrides the calculateNaturalEndpoints
Search WWH ::




Custom Search