org.apache.cassandra.thrift
Enum ConsistencyLevel
java.lang.Object
java.lang.Enum<ConsistencyLevel>
org.apache.cassandra.thrift.ConsistencyLevel
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable<ConsistencyLevel>, org.apache.thrift.TEnum
public enum ConsistencyLevel
- extends java.lang.Enum<ConsistencyLevel>
- implements org.apache.thrift.TEnum
The ConsistencyLevel is an enum that controls both read and write behavior based on in your
storage-conf.xml. The different consistency levels have different meanings, depending on if you're doing a write or read
operation. Note that if W + R > ReplicationFactor, where W is the number of nodes to block for on write, and R
the number to block for on reads, you will have strongly consistent behavior; that is, readers will always see the most
recent write. Of these, the most interesting is to do QUORUM reads and writes, which gives you consistency while still
allowing availability in the face of node failures up to half of . Of course if latency is more
important than consistency then you can use lower values for either or both.
Write consistency levels make the following guarantees before reporting success to the client:
ANY Ensure that the write has been written once somewhere, including possibly being hinted in a non-target node.
ONE Ensure that the write has been written to at least 1 node's commit log and memory table
QUORUM Ensure that the write has been written to / 2 + 1 nodes
LOCAL_QUORUM Ensure that the write has been written to / 2 + 1 nodes, within the local datacenter (requires NetworkTopologyStrategy)
EACH_QUORUM Ensure that the write has been written to / 2 + 1 nodes in each datacenter (requires NetworkTopologyStrategy)
ALL Ensure that the write is written to <ReplicationFactor>
nodes before responding to the client.
Read:
ANY Not supported. You probably want ONE instead.
ONE Will return the record returned by the first node to respond. A consistency check is always done in a background thread to fix any consistency issues when ConsistencyLevel.ONE is used. This means subsequent calls will have correct data even if the initial read gets an older value. (This is called 'read repair'.)
QUORUM Will query all storage nodes and return the record with the most recent timestamp once it has at least a majority of replicas reported. Again, the remaining replicas will be checked in the background.
LOCAL_QUORUM Returns the record with the most recent timestamp once a majority of replicas within the local datacenter have replied.
EACH_QUORUM Returns the record with the most recent timestamp once a majority of replicas within each datacenter have replied.
ALL Queries all storage nodes and returns the record with the most recent timestamp.
Method Summary |
static ConsistencyLevel |
findByValue(int value)
Find a the enum type by its integer value, as defined in the Thrift IDL. |
int |
getValue()
Get the integer value of this enum value, as defined in the Thrift IDL. |
static ConsistencyLevel |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. |
static ConsistencyLevel[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared. |
Methods inherited from class java.lang.Enum |
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
ONE
public static final ConsistencyLevel ONE
QUORUM
public static final ConsistencyLevel QUORUM
LOCAL_QUORUM
public static final ConsistencyLevel LOCAL_QUORUM
EACH_QUORUM
public static final ConsistencyLevel EACH_QUORUM
ALL
public static final ConsistencyLevel ALL
ANY
public static final ConsistencyLevel ANY
values
public static ConsistencyLevel[] values()
- Returns an array containing the constants of this enum type, in
the order they are declared. This method may be used to iterate
over the constants as follows:
for (ConsistencyLevel c : ConsistencyLevel.values())
System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in
the order they are declared
valueOf
public static ConsistencyLevel valueOf(java.lang.String name)
- Returns the enum constant of this type with the specified name.
The string must match exactly an identifier used to declare an
enum constant in this type. (Extraneous whitespace characters are
not permitted.)
- Parameters:
name
- the name of the enum constant to be returned.
- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant
with the specified name
java.lang.NullPointerException
- if the argument is null
getValue
public int getValue()
- Get the integer value of this enum value, as defined in the Thrift IDL.
- Specified by:
getValue
in interface org.apache.thrift.TEnum
findByValue
public static ConsistencyLevel findByValue(int value)
- Find a the enum type by its integer value, as defined in the Thrift IDL.
- Returns:
- null if the value is not found.
Copyright © 2011 The Apache Software Foundation