com.datastax.driver.core.exceptions.UnavailableException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of driver-cql-shaded Show documentation
Show all versions of driver-cql-shaded Show documentation
A Shaded CQL ActivityType driver for http://nosqlbench.io/
/*
* Copyright DataStax, Inc.
*
* This software can be used solely with DataStax Enterprise. Please consult the license at
* http://www.datastax.com/terms/datastax-dse-driver-license-terms
*/
package com.datastax.driver.core.exceptions;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.EndPoint;
import java.net.InetAddress;
import java.net.InetSocketAddress;
/**
* Exception thrown when the coordinator knows there is not enough replicas alive to perform a query
* with the requested consistency level.
*/
public class UnavailableException extends QueryExecutionException implements CoordinatorException {
private static final long serialVersionUID = 0;
private final EndPoint endPoint;
private final ConsistencyLevel consistency;
private final int required;
private final int alive;
/**
* This constructor should only be used internally by the driver when decoding error responses.
*/
public UnavailableException(ConsistencyLevel consistency, int required, int alive) {
this(null, consistency, required, alive);
}
public UnavailableException(
EndPoint endPoint, ConsistencyLevel consistency, int required, int alive) {
super(
String.format(
"Not enough replicas available for query at consistency %s (%d required but only %d alive)",
consistency, required, alive));
this.endPoint = endPoint;
this.consistency = consistency;
this.required = required;
this.alive = alive;
}
private UnavailableException(
EndPoint endPoint,
String message,
Throwable cause,
ConsistencyLevel consistency,
int required,
int alive) {
super(message, cause);
this.endPoint = endPoint;
this.consistency = consistency;
this.required = required;
this.alive = alive;
}
/**
* The consistency level of the operation triggering this unavailable exception.
*
* @return the consistency level of the operation triggering this unavailable exception.
*/
public ConsistencyLevel getConsistencyLevel() {
return consistency;
}
/**
* The number of replica acknowledgements/responses required to perform the operation (with its
* required consistency level).
*
* @return the number of replica acknowledgements/responses required to perform the operation.
*/
public int getRequiredReplicas() {
return required;
}
/**
* The number of replicas that were known to be alive by the Cassandra coordinator node when it
* tried to execute the operation.
*
* @return The number of replicas that were known to be alive by the Cassandra coordinator node
* when it tried to execute the operation.
*/
public int getAliveReplicas() {
return alive;
}
@Override
public EndPoint getEndPoint() {
return endPoint;
}
@Override
@Deprecated
public InetSocketAddress getAddress() {
return (endPoint == null) ? null : endPoint.resolve();
}
@Override
@Deprecated
public InetAddress getHost() {
return (endPoint == null) ? null : endPoint.resolve().getAddress();
}
@Override
public UnavailableException copy() {
return new UnavailableException(
getEndPoint(), getMessage(), this, consistency, required, alive);
}
/**
* Create a copy of this exception with a nicer stack trace, and including the coordinator address
* that caused this exception to be raised.
*
* This method is mainly intended for internal use by the driver and exists mainly because:
*
*
* - the original exception was decoded from a response frame and at that time, the
* coordinator address was not available; and
*
- the newly-created exception will refer to the current thread in its stack trace, which
* generally yields a more user-friendly stack trace that the original one.
*
*
* @param endPoint The full connection information of the host that caused this exception to be
* thrown.
* @return a copy/clone of this exception, but with the given host address instead of the original
* one.
*/
public UnavailableException copy(EndPoint endPoint) {
return new UnavailableException(endPoint, getMessage(), this, consistency, required, alive);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy