org.apache.cassandra.thrift.ConsistencyLevel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cassandra-thrift Show documentation
Show all versions of cassandra-thrift Show documentation
The Apache Cassandra Project develops a highly scalable second-generation distributed database, bringing together Dynamo's fully distributed design and Bigtable's ColumnFamily-based data model.
/**
* Autogenerated by Thrift Compiler (0.9.1)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package org.apache.cassandra.thrift;
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
import java.util.Map;
import java.util.HashMap;
import org.apache.thrift.TEnum;
/**
* The ConsistencyLevel is an enum that controls both read and write
* behavior based on the ReplicationFactor of the keyspace. The
* different consistency levels have different meanings, depending on
* if you're doing a write or read operation.
*
* 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.
*
* Some ConsistencyLevels (ONE, TWO, THREE) refer to a specific number
* of replicas rather than a logical concept that adjusts
* automatically with the replication factor. Of these, only ONE is
* commonly used; TWO and (even more rarely) THREE are only useful
* when you care more about guaranteeing a certain level of
* durability, than consistency.
*
* 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
* TWO Ensure that the write has been written to at least 2 node's commit log and memory table
* THREE Ensure that the write has been written to at least 3 node's commit log and memory table
* QUORUM Ensure that the write has been written to / 2 + 1 nodes
* LOCAL_ONE Ensure that the write has been written to 1 node within the local datacenter (requires NetworkTopologyStrategy)
* 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 consistency levels make the following guarantees before returning successful results to the client:
* ANY Not supported. You probably want ONE instead.
* ONE Returns the record obtained from a single replica.
* TWO Returns the record with the most recent timestamp once two replicas have replied.
* THREE Returns the record with the most recent timestamp once three replicas have replied.
* QUORUM Returns the record with the most recent timestamp once a majority of replicas have replied.
* LOCAL_ONE Returns the record with the most recent timestamp once a single replica within the local datacenter have replied.
* 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 Returns the record with the most recent timestamp once all replicas have replied (implies no replica may be down)..
*/
public enum ConsistencyLevel implements org.apache.thrift.TEnum {
ONE(1),
QUORUM(2),
LOCAL_QUORUM(3),
EACH_QUORUM(4),
ALL(5),
ANY(6),
TWO(7),
THREE(8),
SERIAL(9),
LOCAL_SERIAL(10),
LOCAL_ONE(11);
private final int value;
private ConsistencyLevel(int value) {
this.value = value;
}
/**
* Get the integer value of this enum value, as defined in the Thrift IDL.
*/
public int getValue() {
return value;
}
/**
* Find a the enum type by its integer value, as defined in the Thrift IDL.
* @return null if the value is not found.
*/
public static ConsistencyLevel findByValue(int value) {
switch (value) {
case 1:
return ONE;
case 2:
return QUORUM;
case 3:
return LOCAL_QUORUM;
case 4:
return EACH_QUORUM;
case 5:
return ALL;
case 6:
return ANY;
case 7:
return TWO;
case 8:
return THREE;
case 9:
return SERIAL;
case 10:
return LOCAL_SERIAL;
case 11:
return LOCAL_ONE;
default:
return null;
}
}
}