Finer grained exception hierarchy, and adds error codes

patch by slebresne; reviewed by thepaul for CASSANDRA-3979
This commit is contained in:
Sylvain Lebresne 2012-08-01 08:40:50 +02:00
parent 00e7150545
commit 3a2faf9424
183 changed files with 2173 additions and 1113 deletions

View File

@ -47,6 +47,7 @@
* remove schema agreement checking from all external APIs (Thrift, CQL and CQL3) (CASSANDRA-4487)
* add Murmur3Partitioner and make it default for new installations (CASSANDRA-3772)
* (cql3) update pseudo-map syntax to use map syntax (CASSANDRA-4497)
* Finer grained exceptions hierarchy and provides error code with exceptions (CASSANDRA-3979)
1.1.5

View File

@ -255,8 +255,9 @@ Table of Contents
4.2.1. ERROR
Indicates an error processing a request. The body of the message will be an
error code ([int]) followed by a [string] error message. The error codes are
defined in Section 6.
error code ([int]) followed by a [string] error message. Then, depending on
the exception, more content may follow. The error codes are defined in
Section 6, along with their additional content if any.
4.2.2. READY
@ -404,11 +405,70 @@ Table of Contents
6. Error codes
The currently supported errors are:
0x0000 Server error
0x0001 Protocol error
0x0002 Authentication error
0x0100 Unavailable exception
0x0101 Timeout exception
0x0102 Schema disagreement exception
0x0200 Request exception
The supported error codes are described below:
0x0000 Server error: something unexpected happened. This indicates a
server-side bug.
0x000A Protocol error: some client message triggered a protocol
violation (for instance a QUERY message is sent before a STARTUP
one has been sent)
0x1000 Unavailable exception. The rest of the ERROR message body will be
<cl><required><alive>
where:
<cl> is a [string] representing the consistency level of the
query having triggered the exception.
<required> is an [int] representing the number of node that
should be alive to respect <cl>
<alive> is an [int] representing the number of replica that
were known to be alive when the request has been
processed (since an unavailable exception has been
triggered, there will be <alive> < <required>)
0x1001 Overloaded: the request cannot be processed because the
coordinator node is overloaded
0x1002 Is_bootstrapping: the request was a read request but the
coordinator node is bootstrapping
0x1003 Truncate_error: error during a truncation error.
0x1100 Write_timeout: Timeout exception during a write request. The rest
of the ERROR message body will be
<cl><received><blockfor>
where:
<cl> is a [string] representing the consistency level of the
query having triggered the exception.
<received> is an [int] representing the number of nodes having
acknowledged the request.
<blockfor> is the number of replica whose acknowledgement is
required to achieve <cl>.
0x1200 Read_timeout: Timeout exception during a read request. The rest
of the ERROR message body will be
<cl><received><blockfor><data_present>
where:
<cl> is a [string] representing the consistency level of the
query having triggered the exception.
<received> is an [int] representing the number of nodes having
answered the request.
<blockfor> is the number of replica whose response is
required to achieve <cl>. Please note that it is
possible to have <received> >= <blockfor> if
<data_present> is false. And also in the (unlikely)
case were <cl> is achieved but the coordinator node
timeout while waiting for read-repair
acknowledgement.
<data_present> is a single byte. If its value is 0, it means
the replica that was asked for data has not
responded. Otherwise, the value is != 0.
0x2000 Syntax_error: The submitted query has a syntax error.
0x2100 Unauthorized: The logged user doesn't have the right to perform
the query.
0x2200 Invalid: The query is syntactically correct but invalid.
0x2300 Config_error: The query is invalid because of some configuration issue
0x2400 Already_exists: The query attempted to create a keyspace or a
table that was already existing. The rest of the ERROR message
body will be <ks><table> where:
<ks> is a [string] representing either the keyspace that
already exists, or the keyspace in which the table that
already exists is.
<table> is a [string] representing the name of the table that
already exists. If the query was attempting to create a
keyspace, <table> will be present but will be the empty
string.

View File

@ -29,7 +29,7 @@ import java.security.MessageDigest;
import java.util.Map;
import java.util.Properties;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.util.FileUtils;
import org.apache.cassandra.thrift.AuthenticationException;
import org.apache.cassandra.utils.FBUtilities;

View File

@ -29,7 +29,7 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Properties;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.util.FileUtils;
public class SimpleAuthority implements IAuthority

View File

@ -19,7 +19,7 @@ package org.apache.cassandra.auth;
import java.util.Map;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.thrift.AuthenticationException;
public class AllowAllAuthenticator implements IAuthenticator

View File

@ -20,7 +20,7 @@ package org.apache.cassandra.auth;
import java.util.EnumSet;
import java.util.List;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
public class AllowAllAuthority implements IAuthority
{

View File

@ -19,7 +19,7 @@ package org.apache.cassandra.auth;
import java.util.Map;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.thrift.AuthenticationException;
public interface IAuthenticator

View File

@ -20,7 +20,7 @@ package org.apache.cassandra.auth;
import java.util.EnumSet;
import java.util.List;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
/**
* Cassandra's resource hierarchy looks something like:

View File

@ -34,7 +34,7 @@ import org.apache.commons.lang.StringUtils;
import org.antlr.runtime.tree.Tree;
import org.apache.cassandra.auth.IAuthenticator;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.db.ColumnFamilyStoreMBean;
import org.apache.cassandra.db.compaction.CompactionManagerMBean;
import org.apache.cassandra.db.compaction.OperationType;
@ -547,7 +547,7 @@ public class CliClient
{
return TypeParser.parse(compareWith);
}
catch (ConfigurationException ce)
catch (RequestValidationException ce)
{
StringBuilder errorMessage = new StringBuilder("Unknown comparator '" + compareWith + "'. ");
errorMessage.append("Available functions: ");
@ -1545,7 +1545,7 @@ public class CliClient
{
comparator = TypeParser.parse(defaultType);
}
catch (ConfigurationException e)
catch (RequestValidationException e)
{
try
{

View File

@ -26,6 +26,8 @@ import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.BytesType;
import org.apache.cassandra.db.marshal.TypeParser;
import org.apache.cassandra.db.migration.avro.CfDef;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.io.compress.CompressionParameters;
import org.apache.cassandra.locator.AbstractReplicationStrategy;
import org.apache.cassandra.locator.NetworkTopologyStrategy;
@ -211,7 +213,7 @@ public class Avro
AbstractType<?> validatorType = TypeParser.parse(cd.validation_class);
return new ColumnDefinition(ByteBufferUtil.clone(cd.name), validatorType, index_type, ColumnDefinition.getStringMap(cd.index_options), index_name, null);
}
catch (ConfigurationException e)
catch (RequestValidationException e)
{
throw new RuntimeException(e);
}

View File

@ -40,11 +40,14 @@ import org.apache.cassandra.db.*;
import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
import org.apache.cassandra.db.index.SecondaryIndex;
import org.apache.cassandra.db.marshal.*;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.io.IColumnSerializer;
import org.apache.cassandra.io.compress.CompressionParameters;
import org.apache.cassandra.io.compress.SnappyCompressor;
import org.apache.cassandra.thrift.IndexType;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.tracing.Tracing;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
@ -287,11 +290,7 @@ public final class CFMetaData
statement.applyPropertiesTo(cfmd);
return cfmd;
}
catch (InvalidRequestException e)
{
throw new RuntimeException(e);
}
catch (ConfigurationException e)
catch (RequestValidationException e)
{
throw new RuntimeException(e);
}
@ -658,34 +657,34 @@ public final class CFMetaData
applyImplicitDefaults(cf_def);
CFMetaData newCFMD = new CFMetaData(cf_def.keyspace,
cf_def.name,
cfType,
TypeParser.parse(cf_def.comparator_type),
cf_def.subcomparator_type == null ? null : TypeParser.parse(cf_def.subcomparator_type));
if (cf_def.isSetGc_grace_seconds()) { newCFMD.gcGraceSeconds(cf_def.gc_grace_seconds); }
if (cf_def.isSetMin_compaction_threshold()) { newCFMD.minCompactionThreshold(cf_def.min_compaction_threshold); }
if (cf_def.isSetMax_compaction_threshold()) { newCFMD.maxCompactionThreshold(cf_def.max_compaction_threshold); }
if (cf_def.isSetKey_alias()) { newCFMD.keyAliases(Collections.<ByteBuffer>singletonList(cf_def.key_alias)); }
if (cf_def.isSetKey_validation_class()) { newCFMD.keyValidator(TypeParser.parse(cf_def.key_validation_class)); }
if (cf_def.isSetCompaction_strategy())
newCFMD.compactionStrategyClass = createCompactionStrategy(cf_def.compaction_strategy);
if (cf_def.isSetCompaction_strategy_options())
newCFMD.compactionStrategyOptions(new HashMap<String, String>(cf_def.compaction_strategy_options));
if (cf_def.isSetBloom_filter_fp_chance())
newCFMD.bloomFilterFpChance(cf_def.bloom_filter_fp_chance);
if (cf_def.isSetCaching())
newCFMD.caching(Caching.fromString(cf_def.caching));
if (cf_def.isSetRead_repair_chance())
newCFMD.readRepairChance(cf_def.read_repair_chance);
if (cf_def.isSetDclocal_read_repair_chance())
newCFMD.dcLocalReadRepairChance(cf_def.dclocal_read_repair_chance);
CompressionParameters cp = CompressionParameters.create(cf_def.compression_options);
try
{
CFMetaData newCFMD = new CFMetaData(cf_def.keyspace,
cf_def.name,
cfType,
TypeParser.parse(cf_def.comparator_type),
cf_def.subcomparator_type == null ? null : TypeParser.parse(cf_def.subcomparator_type));
if (cf_def.isSetGc_grace_seconds()) { newCFMD.gcGraceSeconds(cf_def.gc_grace_seconds); }
if (cf_def.isSetMin_compaction_threshold()) { newCFMD.minCompactionThreshold(cf_def.min_compaction_threshold); }
if (cf_def.isSetMax_compaction_threshold()) { newCFMD.maxCompactionThreshold(cf_def.max_compaction_threshold); }
if (cf_def.isSetKey_alias()) { newCFMD.keyAliases(Collections.<ByteBuffer>singletonList(cf_def.key_alias)); }
if (cf_def.isSetKey_validation_class()) { newCFMD.keyValidator(TypeParser.parse(cf_def.key_validation_class)); }
if (cf_def.isSetCompaction_strategy())
newCFMD.compactionStrategyClass = createCompactionStrategy(cf_def.compaction_strategy);
if (cf_def.isSetCompaction_strategy_options())
newCFMD.compactionStrategyOptions(new HashMap<String, String>(cf_def.compaction_strategy_options));
if (cf_def.isSetBloom_filter_fp_chance())
newCFMD.bloomFilterFpChance(cf_def.bloom_filter_fp_chance);
if (cf_def.isSetCaching())
newCFMD.caching(Caching.fromString(cf_def.caching));
if (cf_def.isSetRead_repair_chance())
newCFMD.readRepairChance(cf_def.read_repair_chance);
if (cf_def.isSetDclocal_read_repair_chance())
newCFMD.dcLocalReadRepairChance(cf_def.dclocal_read_repair_chance);
CompressionParameters cp = CompressionParameters.create(cf_def.compression_options);
return newCFMD.comment(cf_def.comment)
.replicateOnWrite(cf_def.replicate_on_write)
.defaultValidator(TypeParser.parse(cf_def.default_validation_class))
@ -693,6 +692,10 @@ public final class CFMetaData
.columnMetadata(ColumnDefinition.fromThrift(cf_def.column_metadata))
.compressionParameters(cp);
}
catch (SyntaxException e)
{
throw new ConfigurationException(e.getMessage());
}
catch (MarshalException e)
{
throw new ConfigurationException(e.getMessage());
@ -1301,6 +1304,10 @@ public final class CFMetaData
return cfm;
}
catch (SyntaxException e)
{
throw new RuntimeException(e);
}
catch (ConfigurationException e)
{
throw new RuntimeException(e);

View File

@ -27,6 +27,7 @@ import org.apache.cassandra.cql3.UntypedResultSet;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.db.marshal.*;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.ColumnDef;
import org.apache.cassandra.thrift.IndexType;
@ -115,7 +116,7 @@ public class ColumnDefinition
return cd;
}
public static ColumnDefinition fromThrift(ColumnDef thriftColumnDef) throws ConfigurationException
public static ColumnDefinition fromThrift(ColumnDef thriftColumnDef) throws SyntaxException, ConfigurationException
{
return new ColumnDefinition(ByteBufferUtil.clone(thriftColumnDef.name),
TypeParser.parse(thriftColumnDef.validation_class),
@ -125,7 +126,7 @@ public class ColumnDefinition
null);
}
public static Map<ByteBuffer, ColumnDefinition> fromThrift(List<ColumnDef> thriftDefs) throws ConfigurationException
public static Map<ByteBuffer, ColumnDefinition> fromThrift(List<ColumnDef> thriftDefs) throws SyntaxException, ConfigurationException
{
if (thriftDefs == null)
return new HashMap<ByteBuffer,ColumnDefinition>();
@ -231,7 +232,7 @@ public class ColumnDefinition
index_name,
componentIndex));
}
catch (ConfigurationException e)
catch (RequestValidationException e)
{
throw new RuntimeException(e);
}

View File

@ -40,6 +40,7 @@ import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.DefsTable;
import org.apache.cassandra.db.SystemTable;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.FSWriteError;
import org.apache.cassandra.io.util.FileUtils;
import org.apache.cassandra.locator.DynamicEndpointSnitch;

View File

@ -27,6 +27,7 @@ import org.apache.cassandra.cql3.QueryProcessor;
import org.apache.cassandra.cql3.UntypedResultSet;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.locator.*;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.CfDef;

View File

@ -22,8 +22,9 @@ import java.util.List;
import org.apache.cassandra.db.IMutation;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.UnauthorizedException;
public abstract class AbstractModification
{
@ -102,7 +103,7 @@ public abstract class AbstractModification
* @throws InvalidRequestException on the wrong request
*/
public abstract List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, List<ByteBuffer> variables)
throws org.apache.cassandra.thrift.InvalidRequestException;
throws InvalidRequestException, UnauthorizedException;
/**
* Convert statement into a list of mutations to apply on the server
@ -116,5 +117,5 @@ public abstract class AbstractModification
* @throws InvalidRequestException on the wrong request
*/
public abstract List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, Long timestamp, List<ByteBuffer> variables)
throws org.apache.cassandra.thrift.InvalidRequestException;
throws InvalidRequestException, UnauthorizedException;
}

View File

@ -19,8 +19,8 @@ package org.apache.cassandra.cql;
import org.apache.cassandra.config.*;
import org.apache.cassandra.db.marshal.TypeParser;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.io.compress.CompressionParameters;
import org.apache.cassandra.thrift.InvalidRequestException;
import java.nio.ByteBuffer;
import java.util.HashMap;
@ -63,7 +63,7 @@ public class AlterTableStatement
}
}
public CFMetaData getCFMetaData(String keyspace) throws ConfigurationException, InvalidRequestException
public CFMetaData getCFMetaData(String keyspace) throws ConfigurationException, InvalidRequestException, SyntaxException
{
CFMetaData meta = Schema.instance.getCFMetaData(keyspace, columnFamily);
CFMetaData cfm = meta.clone();
@ -171,7 +171,7 @@ public class AlterTableStatement
{
cfm.defaultValidator(cfProps.getValidator());
}
catch (ConfigurationException e)
catch (RequestValidationException e)
{
throw new InvalidRequestException(String.format("Invalid validation type %s",
cfProps.getProperty(CFPropDefs.KW_DEFAULTVALIDATION)));

View File

@ -17,7 +17,7 @@
*/
package org.apache.cassandra.cql;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.db.ConsistencyLevel;
/**
* Class to contain attributes for statements

View File

@ -22,9 +22,10 @@ import java.util.LinkedList;
import java.util.List;
import org.apache.cassandra.db.IMutation;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.UnauthorizedException;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.InvalidRequestException;
/**
* A <code>BATCH</code> statement parsed from a CQL query.
@ -75,7 +76,7 @@ public class BatchStatement
}
public List<IMutation> getMutations(String keyspace, ClientState clientState, List<ByteBuffer> variables)
throws InvalidRequestException
throws InvalidRequestException, UnauthorizedException
{
List<IMutation> batch = new LinkedList<IMutation>();

View File

@ -19,13 +19,14 @@ package org.apache.cassandra.cql;
import com.google.common.collect.Sets;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.TypeParser;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.io.compress.CompressionParameters;
import org.apache.cassandra.io.compress.SnappyCompressor;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -204,14 +205,14 @@ public class CFPropDefs {
* knows what they are doing (a custom comparator/validator for example), and pass it on as-is.
*/
public AbstractType<?> getComparator() throws ConfigurationException
public AbstractType<?> getComparator() throws ConfigurationException, SyntaxException
{
return TypeParser.parse((comparators.get(getPropertyString(KW_COMPARATOR, "text")) != null)
? comparators.get(getPropertyString(KW_COMPARATOR, "text"))
: getPropertyString(KW_COMPARATOR, "text"));
}
public AbstractType<?> getValidator() throws ConfigurationException
public AbstractType<?> getValidator() throws ConfigurationException, SyntaxException
{
return TypeParser.parse((comparators.get(getPropertyString(KW_DEFAULTVALIDATION, "text")) != null)
? comparators.get(getPropertyString(KW_DEFAULTVALIDATION, "text"))

View File

@ -33,9 +33,9 @@ options {
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.utils.Pair;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.db.ConsistencyLevel;
import static org.apache.cassandra.cql.AlterTableStatement.OperationType;
}
@ -56,10 +56,10 @@ options {
return recognitionErrors;
}
public void throwLastRecognitionError() throws InvalidRequestException
public void throwLastRecognitionError() throws SyntaxException
{
if (recognitionErrors.size() > 0)
throw new InvalidRequestException(recognitionErrors.get((recognitionErrors.size()-1)));
throw new SyntaxException(recognitionErrors.get((recognitionErrors.size()-1)));
}
// used by UPDATE of the counter columns to validate if '-' was supplied by user
@ -72,7 +72,7 @@ options {
@lexer::header {
package org.apache.cassandra.cql;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.SyntaxException;
}
@lexer::members {
@ -104,10 +104,10 @@ options {
return recognitionErrors;
}
public void throwLastRecognitionError() throws InvalidRequestException
public void throwLastRecognitionError() throws SyntaxException
{
if (recognitionErrors.size() > 0)
throw new InvalidRequestException(recognitionErrors.get((recognitionErrors.size()-1)));
throw new SyntaxException(recognitionErrors.get((recognitionErrors.size()-1)));
}
}

View File

@ -26,11 +26,12 @@ import java.util.Map;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.db.ColumnFamilyType;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.TypeParser;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.io.compress.CompressionParameters;
@ -69,6 +70,10 @@ public class CreateColumnFamilyStatement
{
throw new InvalidRequestException(e.toString());
}
catch (SyntaxException e)
{
throw new InvalidRequestException(e.toString());
}
for (Map.Entry<Term, String> column : columns.entrySet())
{
@ -139,6 +144,12 @@ public class CreateColumnFamilyStatement
ex.initCause(e);
throw ex;
}
catch (SyntaxException e)
{
InvalidRequestException ex = new InvalidRequestException(e.toString());
ex.initCause(e);
throw ex;
}
}
return columnDefs;
@ -191,6 +202,10 @@ public class CreateColumnFamilyStatement
{
throw new InvalidRequestException(e.toString());
}
catch (SyntaxException e)
{
throw new InvalidRequestException(e.toString());
}
return newCFMD;
}

View File

@ -20,7 +20,7 @@ package org.apache.cassandra.cql;
import java.util.HashMap;
import java.util.Map;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
/** A <code>CREATE KEYSPACE</code> statement parsed from a CQL query. */
public class CreateKeyspaceStatement

View File

@ -28,8 +28,9 @@ import org.apache.cassandra.db.IMutation;
import org.apache.cassandra.db.RowMutation;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.UnauthorizedException;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.InvalidRequestException;
import static org.apache.cassandra.thrift.ThriftValidation.validateColumnFamily;
import static org.apache.cassandra.cql.QueryProcessor.validateColumnName;
@ -61,12 +62,14 @@ public class DeleteStatement extends AbstractModification
return keys;
}
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, List<ByteBuffer> variables) throws InvalidRequestException
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, List<ByteBuffer> variables)
throws InvalidRequestException, UnauthorizedException
{
return prepareRowMutations(keyspace, clientState, null, variables);
}
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, Long timestamp, List<ByteBuffer> variables) throws InvalidRequestException
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, Long timestamp, List<ByteBuffer> variables)
throws InvalidRequestException, UnauthorizedException
{
CFMetaData metadata = validateColumnFamily(keyspace, columnFamily);

View File

@ -20,9 +20,10 @@ package org.apache.cassandra.cql;
import java.io.IOException;
import org.apache.cassandra.config.*;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.thrift.CfDef;
import org.apache.cassandra.thrift.ColumnDef;
import org.apache.cassandra.thrift.InvalidRequestException;
public class DropIndexStatement
{

View File

@ -36,12 +36,24 @@ import org.apache.cassandra.db.marshal.AsciiType;
import org.apache.cassandra.db.marshal.MarshalException;
import org.apache.cassandra.db.marshal.TypeParser;
import org.apache.cassandra.dht.*;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.StorageProxy;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.service.MigrationManager;
import org.apache.cassandra.thrift.*;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.thrift.CqlMetadata;
import org.apache.cassandra.thrift.CqlResult;
import org.apache.cassandra.thrift.CqlResultType;
import org.apache.cassandra.thrift.CqlRow;
import org.apache.cassandra.thrift.CqlPreparedResult;
import org.apache.cassandra.thrift.IndexExpression;
import org.apache.cassandra.thrift.IndexOperator;
import org.apache.cassandra.thrift.IndexType;
import org.apache.cassandra.thrift.RequestType;
import org.apache.cassandra.thrift.SchemaDisagreementException;
import org.apache.cassandra.thrift.ThriftValidation;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Pair;
@ -65,7 +77,7 @@ public class QueryProcessor
public static final String DEFAULT_KEY_NAME = bufferToString(CFMetaData.DEFAULT_KEY_NAME);
private static List<org.apache.cassandra.db.Row> getSlice(CFMetaData metadata, SelectStatement select, List<ByteBuffer> variables)
throws InvalidRequestException, TimedOutException, UnavailableException
throws InvalidRequestException, ReadTimeoutException, UnavailableException, IsBootstrappingException
{
QueryPath queryPath = new QueryPath(select.getColumnFamily());
List<ReadCommand> commands = new ArrayList<ReadCommand>();
@ -111,10 +123,6 @@ public class QueryProcessor
{
return StorageProxy.read(commands, select.getConsistencyLevel());
}
catch (TimeoutException e)
{
throw new TimedOutException();
}
catch (IOException e)
{
throw new RuntimeException(e);
@ -137,7 +145,7 @@ public class QueryProcessor
}
private static List<org.apache.cassandra.db.Row> multiRangeSlice(CFMetaData metadata, SelectStatement select, List<ByteBuffer> variables)
throws TimedOutException, UnavailableException, InvalidRequestException
throws ReadTimeoutException, UnavailableException, InvalidRequestException
{
List<org.apache.cassandra.db.Row> rows;
IPartitioner<?> p = StorageService.getPartitioner();
@ -197,14 +205,6 @@ public class QueryProcessor
{
throw new RuntimeException(e);
}
catch (org.apache.cassandra.thrift.UnavailableException e)
{
throw new UnavailableException();
}
catch (TimeoutException e)
{
throw new TimedOutException();
}
// if start key was set and relation was "greater than"
if (select.getKeyStart() != null && !select.includeStartKey() && !rows.isEmpty())
@ -225,7 +225,7 @@ public class QueryProcessor
}
private static void batchUpdate(ClientState clientState, List<UpdateStatement> updateStatements, ConsistencyLevel consistency, List<ByteBuffer> variables )
throws InvalidRequestException, UnavailableException, TimedOutException
throws RequestValidationException, RequestExecutionException
{
String globalKeyspace = clientState.getKeyspace();
List<IMutation> rowMutations = new ArrayList<IMutation>(updateStatements.size());
@ -250,14 +250,7 @@ public class QueryProcessor
validateKey(mutation.key());
}
try
{
StorageProxy.mutate(rowMutations, consistency);
}
catch (org.apache.cassandra.thrift.UnavailableException e)
{
throw new UnavailableException();
}
StorageProxy.mutate(rowMutations, consistency);
}
private static IFilter filterFromSelect(SelectStatement select, CFMetaData metadata, List<ByteBuffer> variables)
@ -279,7 +272,7 @@ public class QueryProcessor
/* Test for SELECT-specific taboos */
private static void validateSelect(String keyspace, SelectStatement select, List<ByteBuffer> variables) throws InvalidRequestException
{
ThriftValidation.validateConsistencyLevel(keyspace, select.getConsistencyLevel(), RequestType.READ);
select.getConsistencyLevel().validateForRead(keyspace);
// Finish key w/o start key (KEY < foo)
if (!select.isKeyRange() && (select.getKeyFinish() != null))
@ -405,7 +398,7 @@ public class QueryProcessor
}
public static CqlResult processStatement(CQLStatement statement,ClientState clientState, List<ByteBuffer> variables )
throws UnavailableException, InvalidRequestException, TimedOutException
throws RequestExecutionException, RequestValidationException
{
String keyspace = null;
@ -564,14 +557,14 @@ public class QueryProcessor
case INSERT: // insert uses UpdateStatement
case UPDATE:
UpdateStatement update = (UpdateStatement)statement.statement;
ThriftValidation.validateConsistencyLevel(keyspace, update.getConsistencyLevel(), RequestType.WRITE);
update.getConsistencyLevel().validateForWrite(keyspace);
batchUpdate(clientState, Collections.singletonList(update), update.getConsistencyLevel(), variables);
result.type = CqlResultType.VOID;
return result;
case BATCH:
BatchStatement batch = (BatchStatement) statement.statement;
ThriftValidation.validateConsistencyLevel(keyspace, batch.getConsistencyLevel(), RequestType.WRITE);
batch.getConsistencyLevel().validateForWrite(keyspace);
if (batch.getTimeToLive() != 0)
throw new InvalidRequestException("Global TTL on the BATCH statement is not supported.");
@ -593,14 +586,7 @@ public class QueryProcessor
validateKey(mutation.key());
}
try
{
StorageProxy.mutate(mutations, batch.getConsistencyLevel());
}
catch (org.apache.cassandra.thrift.UnavailableException e)
{
throw new UnavailableException();
}
StorageProxy.mutate(mutations, batch.getConsistencyLevel());
result.type = CqlResultType.VOID;
return result;
@ -624,11 +610,11 @@ public class QueryProcessor
}
catch (TimeoutException e)
{
throw (UnavailableException) new UnavailableException().initCause(e);
throw new TruncateException(e);
}
catch (IOException e)
{
throw (UnavailableException) new UnavailableException().initCause(e);
throw new RuntimeException(e);
}
result.type = CqlResultType.VOID;
@ -819,14 +805,14 @@ public class QueryProcessor
}
public static CqlResult process(String queryString, ClientState clientState)
throws UnavailableException, InvalidRequestException, TimedOutException
throws RequestValidationException, RequestExecutionException
{
logger.trace("CQL QUERY: {}", queryString);
return processStatement(getStatement(queryString), clientState, new ArrayList<ByteBuffer>(0));
}
public static CqlPreparedResult prepare(String queryString, ClientState clientState)
throws InvalidRequestException
throws InvalidRequestException, SyntaxException
{
logger.trace("CQL QUERY: {}", queryString);
@ -843,7 +829,7 @@ public class QueryProcessor
}
public static CqlResult processPrepared(CQLStatement statement, ClientState clientState, List<ByteBuffer> variables)
throws UnavailableException, InvalidRequestException, TimedOutException
throws RequestValidationException, RequestExecutionException
{
// Check to see if there are any bound variables to verify
if (!(variables.isEmpty() && (statement.boundTerms == 0)))
@ -891,7 +877,7 @@ public class QueryProcessor
return keyString;
}
private static CQLStatement getStatement(String queryStr) throws InvalidRequestException
private static CQLStatement getStatement(String queryStr) throws SyntaxException
{
try
{
@ -913,14 +899,12 @@ public class QueryProcessor
}
catch (RuntimeException re)
{
InvalidRequestException ire = new InvalidRequestException("Failed parsing statement: [" + queryStr + "] reason: " + re.getClass().getSimpleName() + " " + re.getMessage());
ire.initCause(re);
SyntaxException ire = new SyntaxException("Failed parsing statement: [" + queryStr + "] reason: " + re.getClass().getSimpleName() + " " + re.getMessage());
throw ire;
}
catch (RecognitionException e)
{
InvalidRequestException ire = new InvalidRequestException("Invalid or malformed CQL query string");
ire.initCause(e);
SyntaxException ire = new SyntaxException("Invalid or malformed CQL query string: " + e.getMessage());
throw ire;
}
}

View File

@ -24,7 +24,7 @@ import java.util.Set;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.db.ConsistencyLevel;
/**
* Encapsulates a completely parsed SELECT query, including the target

View File

@ -26,7 +26,7 @@ import org.apache.cassandra.db.marshal.FloatType;
import org.apache.cassandra.db.marshal.IntegerType;
import org.apache.cassandra.db.marshal.LexicalUUIDType;
import org.apache.cassandra.db.marshal.MarshalException;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
/** A term parsed from a CQL statement. */
public class Term

View File

@ -24,19 +24,19 @@ import org.apache.cassandra.auth.Permission;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.db.CounterMutation;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.db.IMutation;
import org.apache.cassandra.db.RowMutation;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.UnauthorizedException;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.InvalidRequestException;
import static org.apache.cassandra.cql.QueryProcessor.validateColumn;
import static org.apache.cassandra.cql.QueryProcessor.validateKey;
import static org.apache.cassandra.thrift.ThriftValidation.validateColumnFamily;
import static org.apache.cassandra.thrift.ThriftValidation.validateCommutativeForWrite;
/**
* An <code>UPDATE</code> statement parsed from a CQL query statement.
@ -122,13 +122,15 @@ public class UpdateStatement extends AbstractModification
}
/** {@inheritDoc} */
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, List<ByteBuffer> variables) throws InvalidRequestException
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, List<ByteBuffer> variables)
throws InvalidRequestException, UnauthorizedException
{
return prepareRowMutations(keyspace, clientState, null, variables);
}
/** {@inheritDoc} */
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, Long timestamp, List<ByteBuffer> variables) throws InvalidRequestException
public List<IMutation> prepareRowMutations(String keyspace, ClientState clientState, Long timestamp, List<ByteBuffer> variables)
throws InvalidRequestException, UnauthorizedException
{
List<String> cfamsSeen = new ArrayList<String>();
@ -145,7 +147,7 @@ public class UpdateStatement extends AbstractModification
CFMetaData metadata = validateColumnFamily(keyspace, columnFamily, hasCommutativeOperation);
if (hasCommutativeOperation)
validateCommutativeForWrite(metadata, cLevel);
cLevel.validateCounterForWrite(metadata);
QueryProcessor.validateKeyAlias(metadata, keyName);

View File

@ -17,7 +17,7 @@
*/
package org.apache.cassandra.cql3;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.db.ConsistencyLevel;
/**
* Utility class for the Parser to gather attributes for modification

View File

@ -29,7 +29,7 @@ import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.ColumnToCollectionType;
import org.apache.cassandra.db.marshal.CompositeType;
import org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.utils.ByteBufferUtil;
/**

View File

@ -19,7 +19,7 @@ package org.apache.cassandra.cql3;
import com.google.common.collect.Sets;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
import org.apache.cassandra.io.compress.CompressionParameters;
import org.slf4j.Logger;

View File

@ -22,9 +22,7 @@ import java.util.List;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.TimedOutException;
import org.apache.cassandra.thrift.UnavailableException;
import org.apache.cassandra.exceptions.*;
public interface CQLStatement
{
@ -38,7 +36,7 @@ public interface CQLStatement
*
* @param state the current client state
*/
public void checkAccess(ClientState state) throws InvalidRequestException;
public void checkAccess(ClientState state) throws UnauthorizedException, InvalidRequestException;
/**
* Perform additional validation required by the statment.
@ -46,7 +44,7 @@ public interface CQLStatement
*
* @param state the current client state
*/
public void validate(ClientState state) throws InvalidRequestException;
public void validate(ClientState state) throws RequestValidationException;
/**
* Execute the statement and return the resulting result or null if there is no result.
@ -55,5 +53,5 @@ public interface CQLStatement
* @param variables the values for bounded variables. The implementation
* can assume that each bound term have a corresponding value.
*/
public ResultMessage execute(ClientState state, List<ByteBuffer> variables) throws InvalidRequestException, UnavailableException, TimedOutException;
public ResultMessage execute(ClientState state, List<ByteBuffer> variables) throws RequestValidationException, RequestExecutionException;
}

View File

@ -20,7 +20,7 @@ package org.apache.cassandra.cql3;
import java.nio.ByteBuffer;
import java.util.List;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
/**
* Build a potentially composite column name.

View File

@ -36,11 +36,12 @@ options {
import org.apache.cassandra.cql3.operations.*;
import org.apache.cassandra.cql3.statements.*;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.utils.Pair;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.db.ConsistencyLevel;
}
@members {
@ -64,10 +65,10 @@ options {
return recognitionErrors;
}
public void throwLastRecognitionError() throws InvalidRequestException
public void throwLastRecognitionError() throws SyntaxException
{
if (recognitionErrors.size() > 0)
throw new InvalidRequestException(recognitionErrors.get((recognitionErrors.size()-1)));
throw new SyntaxException(recognitionErrors.get((recognitionErrors.size()-1)));
}
// used by UPDATE of the counter columns to validate if '-' was supplied by user
@ -101,7 +102,7 @@ options {
@lexer::header {
package org.apache.cassandra.cql3;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.SyntaxException;
}
@lexer::members {
@ -135,10 +136,10 @@ options {
return recognitionErrors;
}
public void throwLastRecognitionError() throws InvalidRequestException
public void throwLastRecognitionError() throws SyntaxException
{
if (recognitionErrors.size() > 0)
throw new InvalidRequestException(recognitionErrors.get((recognitionErrors.size()-1)));
throw new SyntaxException(recognitionErrors.get((recognitionErrors.size()-1)));
}
}
@ -627,8 +628,10 @@ comparatorType returns [ParsedType t]
{
try {
$t = new ParsedType.Custom($s.text);
} catch (ConfigurationException e) {
} catch (SyntaxException e) {
addRecognitionError("Cannot parse type " + $s.text + ": " + e.getMessage());
} catch (ConfigurationException e) {
addRecognitionError("Errot setting type " + $s.text + ": " + e.getMessage());
}
}
;

View File

@ -17,9 +17,10 @@
*/
package org.apache.cassandra.cql3;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.db.marshal.*;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.SyntaxException;
public interface ParsedType
{
@ -67,9 +68,9 @@ public interface ParsedType
{
private final AbstractType<?> type;
public Custom(String className) throws ConfigurationException
public Custom(String className) throws SyntaxException, ConfigurationException
{
this.type = TypeParser.parse(className);
this.type = TypeParser.parse(className);
}
public boolean isCollection()

View File

@ -30,8 +30,9 @@ import org.apache.cassandra.config.*;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.filter.*;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.*;
import org.apache.cassandra.thrift.SchemaDisagreementException;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.SemanticVersion;
@ -100,7 +101,7 @@ public class QueryProcessor
}
private static ResultMessage processStatement(CQLStatement statement, ClientState clientState, List<ByteBuffer> variables)
throws UnavailableException, InvalidRequestException, TimedOutException
throws RequestExecutionException, RequestValidationException
{
statement.checkAccess(clientState);
statement.validate(clientState);
@ -109,7 +110,7 @@ public class QueryProcessor
}
public static ResultMessage process(String queryString, ClientState clientState)
throws UnavailableException, InvalidRequestException, TimedOutException
throws RequestExecutionException, RequestValidationException
{
logger.trace("CQL QUERY: {}", queryString);
return processStatement(getStatement(queryString, clientState).statement, clientState, Collections.<ByteBuffer>emptyList());
@ -126,18 +127,14 @@ public class QueryProcessor
else
return null;
}
catch (UnavailableException e)
catch (RequestExecutionException e)
{
throw new RuntimeException(e);
}
catch (InvalidRequestException e)
catch (RequestValidationException e)
{
throw new AssertionError(e);
}
catch (TimedOutException e)
{
throw new RuntimeException(e);
}
}
public static UntypedResultSet resultify(String query, Row row)
@ -148,14 +145,14 @@ public class QueryProcessor
ResultSet cqlRows = ss.process(Collections.singletonList(row));
return new UntypedResultSet(cqlRows);
}
catch (InvalidRequestException e)
catch (RequestValidationException e)
{
throw new AssertionError(e);
}
}
public static ResultMessage.Prepared prepare(String queryString, ClientState clientState)
throws InvalidRequestException
throws RequestValidationException
{
logger.trace("CQL QUERY: {}", queryString);
@ -171,7 +168,7 @@ public class QueryProcessor
}
public static ResultMessage processPrepared(CQLStatement statement, ClientState clientState, List<ByteBuffer> variables)
throws UnavailableException, InvalidRequestException, TimedOutException
throws RequestExecutionException, RequestValidationException
{
// Check to see if there are any bound variables to verify
if (!(variables.isEmpty() && (statement.getBoundsTerms() == 0)))
@ -197,7 +194,8 @@ public class QueryProcessor
return cql.hashCode();
}
private static ParsedStatement.Prepared getStatement(String queryStr, ClientState clientState) throws InvalidRequestException
private static ParsedStatement.Prepared getStatement(String queryStr, ClientState clientState)
throws RequestValidationException
{
ParsedStatement statement = parseStatement(queryStr);
@ -208,7 +206,7 @@ public class QueryProcessor
return statement.prepare();
}
public static ParsedStatement parseStatement(String queryStr) throws InvalidRequestException
public static ParsedStatement parseStatement(String queryStr) throws SyntaxException
{
try
{
@ -230,14 +228,12 @@ public class QueryProcessor
}
catch (RuntimeException re)
{
InvalidRequestException ire = new InvalidRequestException("Failed parsing statement: [" + queryStr + "] reason: " + re.getClass().getSimpleName() + " " + re.getMessage());
ire.initCause(re);
SyntaxException ire = new SyntaxException("Failed parsing statement: [" + queryStr + "] reason: " + re.getClass().getSimpleName() + " " + re.getMessage());
throw ire;
}
catch (RecognitionException e)
{
InvalidRequestException ire = new InvalidRequestException("Invalid or malformed CQL query string");
ire.initCause(e);
SyntaxException ire = new SyntaxException("Invalid or malformed CQL query string: " + e.getMessage());
throw ire;
}
}

View File

@ -21,12 +21,12 @@ import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.MarshalException;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
/** A term parsed from a CQL statement. */
public class Term

View File

@ -28,7 +28,7 @@ import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.db.marshal.LongType;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.Pair;

View File

@ -31,7 +31,7 @@ import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.db.IColumn;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.utils.Pair;
import org.apache.cassandra.utils.UUIDGen;

View File

@ -30,7 +30,7 @@ import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.db.IColumn;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.utils.Pair;
public class MapOperation implements Operation

View File

@ -27,7 +27,7 @@ import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.db.IColumn;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.utils.Pair;
public interface Operation

View File

@ -27,7 +27,7 @@ import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.db.IColumn;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.Pair;

View File

@ -27,8 +27,8 @@ import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.db.marshal.ColumnToCollectionType;
import org.apache.cassandra.db.marshal.CompositeType;
import org.apache.cassandra.db.marshal.CounterColumnType;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.MigrationManager;
import org.apache.cassandra.thrift.InvalidRequestException;
import static org.apache.cassandra.thrift.ThriftValidation.validateColumnFamily;

View File

@ -26,11 +26,10 @@ import org.apache.cassandra.cql3.*;
import org.apache.cassandra.db.IMutation;
import org.apache.cassandra.db.RowMutation;
import org.apache.cassandra.db.CounterMutation;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.RequestType;
import org.apache.cassandra.thrift.ThriftValidation;
import org.apache.cassandra.thrift.UnavailableException;
import org.apache.cassandra.utils.Pair;
/**
@ -63,7 +62,7 @@ public class BatchStatement extends ModificationStatement
}
@Override
public void checkAccess(ClientState state) throws InvalidRequestException
public void checkAccess(ClientState state) throws InvalidRequestException, UnauthorizedException
{
Set<String> cfamsSeen = new HashSet<String>();
for (ModificationStatement statement : statements)
@ -93,12 +92,12 @@ public class BatchStatement extends ModificationStatement
if (statement.getTimeToLive() < 0)
throw new InvalidRequestException("A TTL must be greater or equal to 0");
ThriftValidation.validateConsistencyLevel(statement.keyspace(), getConsistencyLevel(), RequestType.WRITE);
getConsistencyLevel().validateForWrite(statement.keyspace());
}
}
public List<IMutation> getMutations(ClientState clientState, List<ByteBuffer> variables)
throws UnavailableException, TimeoutException, InvalidRequestException
throws RequestExecutionException, RequestValidationException
{
Map<Pair<String, ByteBuffer>, RowAndCounterMutation> mutations = new HashMap<Pair<String, ByteBuffer>, RowAndCounterMutation>();
for (ModificationStatement statement : statements)

View File

@ -19,7 +19,7 @@ package org.apache.cassandra.cql3.statements;
import org.apache.cassandra.cql3.CFName;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
/**
* Abstract class for statements that apply on a given column family.

View File

@ -30,7 +30,8 @@ import org.apache.cassandra.config.Schema;
import org.apache.cassandra.cql3.*;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.db.ColumnFamilyType;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.CollectionType;
@ -38,10 +39,10 @@ import org.apache.cassandra.db.marshal.ColumnToCollectionType;
import org.apache.cassandra.db.marshal.CompositeType;
import org.apache.cassandra.db.marshal.ReversedType;
import org.apache.cassandra.db.marshal.CounterColumnType;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.MigrationManager;
import org.apache.cassandra.thrift.CqlResult;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.utils.ByteBufferUtil;
/** A <code>CREATE COLUMNFAMILY</code> parsed from a CQL query statement. */
@ -85,7 +86,7 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
return columnDefs;
}
public void announceMigration() throws InvalidRequestException, ConfigurationException
public void announceMigration() throws RequestValidationException
{
MigrationManager.announceNewColumnFamily(getCFMetaData());
}
@ -97,22 +98,15 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
* @return a CFMetaData instance corresponding to the values parsed from this statement
* @throws InvalidRequestException on failure to validate parsed parameters
*/
public CFMetaData getCFMetaData() throws InvalidRequestException
public CFMetaData getCFMetaData() throws RequestValidationException
{
CFMetaData newCFMD;
try
{
newCFMD = new CFMetaData(keyspace(),
columnFamily(),
ColumnFamilyType.Standard,
comparator,
null);
applyPropertiesTo(newCFMD);
}
catch (ConfigurationException e)
{
throw new InvalidRequestException(e.getMessage());
}
newCFMD = new CFMetaData(keyspace(),
columnFamily(),
ColumnFamilyType.Standard,
comparator,
null);
applyPropertiesTo(newCFMD);
return newCFMD;
}
@ -148,162 +142,155 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
/**
* Transform this raw statement into a CreateColumnFamilyStatement.
*/
public ParsedStatement.Prepared prepare() throws InvalidRequestException
public ParsedStatement.Prepared prepare() throws RequestValidationException
{
try
// Column family name
if (!columnFamily().matches("\\w+"))
throw new InvalidRequestException(String.format("\"%s\" is not a valid column family name (must be alphanumeric character only: [0-9A-Za-z]+)", columnFamily()));
if (columnFamily().length() > Schema.NAME_LENGTH)
throw new InvalidRequestException(String.format("Column family names shouldn't be more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, columnFamily()));
for (Multiset.Entry<ColumnIdentifier> entry : definedNames.entrySet())
if (entry.getCount() > 1)
throw new InvalidRequestException(String.format("Multiple definition of identifier %s", entry.getElement()));
properties.validate();
CreateColumnFamilyStatement stmt = new CreateColumnFamilyStatement(cfName, properties);
stmt.setBoundTerms(getBoundsTerms());
Map<ByteBuffer, CollectionType> definedCollections = null;
for (Map.Entry<ColumnIdentifier, ParsedType> entry : definitions.entrySet())
{
// Column family name
if (!columnFamily().matches("\\w+"))
throw new InvalidRequestException(String.format("\"%s\" is not a valid column family name (must be alphanumeric character only: [0-9A-Za-z]+)", columnFamily()));
if (columnFamily().length() > Schema.NAME_LENGTH)
throw new InvalidRequestException(String.format("Column family names shouldn't be more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, columnFamily()));
for (Multiset.Entry<ColumnIdentifier> entry : definedNames.entrySet())
if (entry.getCount() > 1)
throw new InvalidRequestException(String.format("Multiple definition of identifier %s", entry.getElement()));
properties.validate();
CreateColumnFamilyStatement stmt = new CreateColumnFamilyStatement(cfName, properties);
stmt.setBoundTerms(getBoundsTerms());
Map<ByteBuffer, CollectionType> definedCollections = null;
for (Map.Entry<ColumnIdentifier, ParsedType> entry : definitions.entrySet())
ColumnIdentifier id = entry.getKey();
ParsedType pt = entry.getValue();
if (pt.isCollection())
{
ColumnIdentifier id = entry.getKey();
ParsedType pt = entry.getValue();
if (pt.isCollection())
{
if (definedCollections == null)
definedCollections = new HashMap<ByteBuffer, CollectionType>();
definedCollections.put(id.key, (CollectionType)pt.getType());
}
stmt.columns.put(id, pt.getType()); // we'll remove what is not a column below
if (definedCollections == null)
definedCollections = new HashMap<ByteBuffer, CollectionType>();
definedCollections.put(id.key, (CollectionType)pt.getType());
}
stmt.columns.put(id, pt.getType()); // we'll remove what is not a column below
}
if (keyAliases.size() != 1)
throw new InvalidRequestException("You must specify one and only one PRIMARY KEY");
if (keyAliases.size() != 1)
throw new InvalidRequestException("You must specify one and only one PRIMARY KEY");
List<ColumnIdentifier> kAliases = keyAliases.get(0);
List<ColumnIdentifier> kAliases = keyAliases.get(0);
List<AbstractType<?>> keyTypes = new ArrayList<AbstractType<?>>(kAliases.size());
for (ColumnIdentifier alias : kAliases)
List<AbstractType<?>> keyTypes = new ArrayList<AbstractType<?>>(kAliases.size());
for (ColumnIdentifier alias : kAliases)
{
stmt.keyAliases.add(alias.key);
AbstractType<?> t = getTypeAndRemove(stmt.columns, alias);
if (t instanceof CounterColumnType)
throw new InvalidRequestException(String.format("counter type is not supported for PRIMARY KEY part %s", alias));
keyTypes.add(t);
}
stmt.keyValidator = keyTypes.size() == 1 ? keyTypes.get(0) : CompositeType.getInstance(keyTypes);
// Handle column aliases
if (columnAliases.isEmpty())
{
if (useCompactStorage)
{
stmt.keyAliases.add(alias.key);
AbstractType<?> t = getTypeAndRemove(stmt.columns, alias);
if (t instanceof CounterColumnType)
throw new InvalidRequestException(String.format("counter type is not supported for PRIMARY KEY part %s", alias));
keyTypes.add(t);
}
stmt.keyValidator = keyTypes.size() == 1 ? keyTypes.get(0) : CompositeType.getInstance(keyTypes);
// There should remain some column definition since it is a non-composite "static" CF
if (stmt.columns.isEmpty())
throw new InvalidRequestException("No definition found that is not part of the PRIMARY KEY");
// Handle column aliases
if (columnAliases.isEmpty())
{
if (useCompactStorage)
{
// There should remain some column definition since it is a non-composite "static" CF
if (stmt.columns.isEmpty())
throw new InvalidRequestException("No definition found that is not part of the PRIMARY KEY");
stmt.comparator = CFDefinition.definitionType;
}
else
{
List<AbstractType<?>> types = new ArrayList<AbstractType<?>>(definedCollections == null ? 1 : 2);
types.add(CFDefinition.definitionType);
if (definedCollections != null)
types.add(ColumnToCollectionType.getInstance(definedCollections));
stmt.comparator = CompositeType.getInstance(types);
}
stmt.comparator = CFDefinition.definitionType;
}
else
{
// If we use compact storage and have only one alias, it is a
// standard "dynamic" CF, otherwise it's a composite
if (useCompactStorage && columnAliases.size() == 1)
List<AbstractType<?>> types = new ArrayList<AbstractType<?>>(definedCollections == null ? 1 : 2);
types.add(CFDefinition.definitionType);
if (definedCollections != null)
types.add(ColumnToCollectionType.getInstance(definedCollections));
stmt.comparator = CompositeType.getInstance(types);
}
}
else
{
// If we use compact storage and have only one alias, it is a
// standard "dynamic" CF, otherwise it's a composite
if (useCompactStorage && columnAliases.size() == 1)
{
if (definedCollections != null)
throw new InvalidRequestException("Collection types are not supported with COMPACT STORAGE");
stmt.columnAliases.add(columnAliases.get(0).key);
stmt.comparator = getTypeAndRemove(stmt.columns, columnAliases.get(0));
if (stmt.comparator instanceof CounterColumnType)
throw new InvalidRequestException(String.format("counter type is not supported for PRIMARY KEY part %s", stmt.columnAliases.get(0)));
}
else
{
List<AbstractType<?>> types = new ArrayList<AbstractType<?>>(columnAliases.size() + 1);
for (ColumnIdentifier t : columnAliases)
{
stmt.columnAliases.add(t.key);
AbstractType<?> type = getTypeAndRemove(stmt.columns, t);
if (type instanceof CounterColumnType)
throw new InvalidRequestException(String.format("counter type is not supported for PRIMARY KEY part %s", t.key));
types.add(type);
}
if (useCompactStorage)
{
if (definedCollections != null)
throw new InvalidRequestException("Collection types are not supported with COMPACT STORAGE");
stmt.columnAliases.add(columnAliases.get(0).key);
stmt.comparator = getTypeAndRemove(stmt.columns, columnAliases.get(0));
if (stmt.comparator instanceof CounterColumnType)
throw new InvalidRequestException(String.format("counter type is not supported for PRIMARY KEY part %s", stmt.columnAliases.get(0)));
}
else
{
List<AbstractType<?>> types = new ArrayList<AbstractType<?>>(columnAliases.size() + 1);
for (ColumnIdentifier t : columnAliases)
{
stmt.columnAliases.add(t.key);
AbstractType<?> type = getTypeAndRemove(stmt.columns, t);
if (type instanceof CounterColumnType)
throw new InvalidRequestException(String.format("counter type is not supported for PRIMARY KEY part %s", t.key));
types.add(type);
}
if (useCompactStorage)
{
if (definedCollections != null)
throw new InvalidRequestException("Collection types are not supported with COMPACT STORAGE");
}
else
{
// For sparse, we must add the last UTF8 component
// and the collection type if there is one
types.add(CFDefinition.definitionType);
if (definedCollections != null)
types.add(ColumnToCollectionType.getInstance(definedCollections));
}
if (types.isEmpty())
throw new IllegalStateException("Nonsensical empty parameter list for CompositeType");
stmt.comparator = CompositeType.getInstance(types);
// For sparse, we must add the last UTF8 component
// and the collection type if there is one
types.add(CFDefinition.definitionType);
if (definedCollections != null)
types.add(ColumnToCollectionType.getInstance(definedCollections));
}
if (types.isEmpty())
throw new IllegalStateException("Nonsensical empty parameter list for CompositeType");
stmt.comparator = CompositeType.getInstance(types);
}
}
if (useCompactStorage && stmt.columns.size() <= 1)
if (useCompactStorage && stmt.columns.size() <= 1)
{
if (stmt.columns.isEmpty())
{
if (stmt.columns.isEmpty())
{
if (columnAliases.isEmpty())
throw new InvalidRequestException(String.format("COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY (got: %s)", StringUtils.join(stmt.columns.keySet(), ", ")));
if (columnAliases.isEmpty())
throw new InvalidRequestException(String.format("COMPACT STORAGE with non-composite PRIMARY KEY require one column not part of the PRIMARY KEY (got: %s)", StringUtils.join(stmt.columns.keySet(), ", ")));
// The only value we'll insert will be the empty one, so the default validator don't matter
stmt.defaultValidator = CFDefinition.definitionType;
// We need to distinguish between
// * I'm upgrading from thrift so the valueAlias is null
// * I've define my table with only a PK (and the column value will be empty)
// So, we use an empty valueAlias (rather than null) for the second case
stmt.valueAlias = ByteBufferUtil.EMPTY_BYTE_BUFFER;
}
else
{
Map.Entry<ColumnIdentifier, AbstractType> lastEntry = stmt.columns.entrySet().iterator().next();
stmt.defaultValidator = lastEntry.getValue();
stmt.valueAlias = lastEntry.getKey().key;
stmt.columns.remove(lastEntry.getKey());
}
// The only value we'll insert will be the empty one, so the default validator don't matter
stmt.defaultValidator = CFDefinition.definitionType;
// We need to distinguish between
// * I'm upgrading from thrift so the valueAlias is null
// * I've define my table with only a PK (and the column value will be empty)
// So, we use an empty valueAlias (rather than null) for the second case
stmt.valueAlias = ByteBufferUtil.EMPTY_BYTE_BUFFER;
}
else
{
if (useCompactStorage && !columnAliases.isEmpty())
throw new InvalidRequestException(String.format("COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY (got: %s)", StringUtils.join(stmt.columns.keySet(), ", ")));
// There is no way to insert/access a column that is not defined for non-compact storage, so
// the actual validator don't matter much (except that we want to recognize counter CF as limitation apply to them).
stmt.defaultValidator = !stmt.columns.isEmpty() && (stmt.columns.values().iterator().next() instanceof CounterColumnType)
? CounterColumnType.instance
: CFDefinition.definitionType;
Map.Entry<ColumnIdentifier, AbstractType> lastEntry = stmt.columns.entrySet().iterator().next();
stmt.defaultValidator = lastEntry.getValue();
stmt.valueAlias = lastEntry.getKey().key;
stmt.columns.remove(lastEntry.getKey());
}
return new ParsedStatement.Prepared(stmt);
}
catch (ConfigurationException e)
else
{
throw new InvalidRequestException(e.getMessage());
if (useCompactStorage && !columnAliases.isEmpty())
throw new InvalidRequestException(String.format("COMPACT STORAGE with composite PRIMARY KEY allows no more than one column not part of the PRIMARY KEY (got: %s)", StringUtils.join(stmt.columns.keySet(), ", ")));
// There is no way to insert/access a column that is not defined for non-compact storage, so
// the actual validator don't matter much (except that we want to recognize counter CF as limitation apply to them).
stmt.defaultValidator = !stmt.columns.isEmpty() && (stmt.columns.values().iterator().next() instanceof CounterColumnType)
? CounterColumnType.instance
: CFDefinition.definitionType;
}
return new ParsedStatement.Prepared(stmt);
}
private AbstractType<?> getTypeAndRemove(Map<ColumnIdentifier, AbstractType> columns, ColumnIdentifier t) throws InvalidRequestException, ConfigurationException

View File

@ -26,13 +26,13 @@ import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.cql3.*;
import org.apache.cassandra.db.index.composites.CompositesIndex;
import org.apache.cassandra.db.marshal.CompositeType;
import org.apache.cassandra.service.MigrationManager;
import org.apache.cassandra.thrift.IndexType;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.thrift.ThriftValidation;
/** A <code>CREATE INDEX</code> statement parsed from a CQL query. */

View File

@ -20,15 +20,16 @@ package org.apache.cassandra.cql3.statements;
import java.util.HashMap;
import java.util.Map;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.KSMetaData;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.locator.AbstractReplicationStrategy;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.MigrationManager;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.ThriftValidation;
/** A <code>CREATE KEYSPACE</code> statement parsed from a CQL query. */
@ -64,7 +65,7 @@ public class CreateKeyspaceStatement extends SchemaAlteringStatement
* @throws InvalidRequestException if arguments are missing or unacceptable
*/
@Override
public void validate(ClientState state) throws InvalidRequestException
public void validate(ClientState state) throws RequestValidationException
{
super.validate(state);
ThriftValidation.validateKeyspaceNotSystem(name);
@ -94,24 +95,16 @@ public class CreateKeyspaceStatement extends SchemaAlteringStatement
}
// trial run to let ARS validate class + per-class options
try
{
AbstractReplicationStrategy.createReplicationStrategy(name,
AbstractReplicationStrategy.getClass(strategyClass),
StorageService.instance.getTokenMetadata(),
DatabaseDescriptor.getEndpointSnitch(),
strategyOptions);
}
catch (ConfigurationException e)
{
throw new InvalidRequestException(e.getMessage());
}
AbstractReplicationStrategy.createReplicationStrategy(name,
AbstractReplicationStrategy.getClass(strategyClass),
StorageService.instance.getTokenMetadata(),
DatabaseDescriptor.getEndpointSnitch(),
strategyOptions);
}
public void announceMigration() throws InvalidRequestException, ConfigurationException
{
KSMetaData ksm = KSMetaData.newKeyspace(name, strategyClass, strategyOptions);
ThriftValidation.validateKeyspaceNotYetExisting(name);
MigrationManager.announceNewKeyspace(ksm);
}
}

View File

@ -35,9 +35,8 @@ import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.db.marshal.CompositeType;
import org.apache.cassandra.db.marshal.ListType;
import org.apache.cassandra.db.marshal.MapType;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.UnavailableException;
import org.apache.cassandra.thrift.ThriftValidation;
import org.apache.cassandra.utils.Pair;
@ -63,7 +62,8 @@ public class DeleteStatement extends ModificationStatement
this.toRemove = new ArrayList<Pair<CFDefinition.Name, Term>>(columns.size());
}
public List<IMutation> getMutations(ClientState clientState, List<ByteBuffer> variables) throws UnavailableException, TimeoutException, InvalidRequestException
public List<IMutation> getMutations(ClientState clientState, List<ByteBuffer> variables)
throws RequestExecutionException, RequestValidationException
{
// keys
List<ByteBuffer> keys = UpdateStatement.buildKeyNames(cfDef, processedKeys, variables);

View File

@ -17,7 +17,7 @@
*/
package org.apache.cassandra.cql3.statements;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.cql3.CFName;
import org.apache.cassandra.service.MigrationManager;

View File

@ -20,8 +20,8 @@ package org.apache.cassandra.cql3.statements;
import org.apache.cassandra.cql3.*;
import org.apache.cassandra.config.*;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.MigrationManager;
import org.apache.cassandra.thrift.InvalidRequestException;
public class DropIndexStatement extends SchemaAlteringStatement
{

View File

@ -18,10 +18,10 @@
package org.apache.cassandra.cql3.statements;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.MigrationManager;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.ThriftValidation;
public class DropKeyspaceStatement extends SchemaAlteringStatement
@ -35,7 +35,7 @@ public class DropKeyspaceStatement extends SchemaAlteringStatement
}
@Override
public void validate(ClientState state) throws InvalidRequestException
public void validate(ClientState state) throws RequestValidationException
{
super.validate(state);
ThriftValidation.validateKeyspaceNotSystem(keyspace);

View File

@ -21,7 +21,6 @@ import java.io.IOError;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.TimeoutException;
import org.apache.cassandra.auth.Permission;
import org.apache.cassandra.cql3.*;
@ -29,14 +28,12 @@ import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.db.marshal.CompositeType;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.StorageProxy;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.thrift.RequestType;
import org.apache.cassandra.thrift.ThriftValidation;
import org.apache.cassandra.thrift.TimedOutException;
import org.apache.cassandra.thrift.UnavailableException;
/**
* Abstract class for statements that apply on a given column family.
@ -62,7 +59,7 @@ public abstract class ModificationStatement extends CFStatement implements CQLSt
this.timeToLive = timeToLive;
}
public void checkAccess(ClientState state) throws InvalidRequestException
public void checkAccess(ClientState state) throws InvalidRequestException, UnauthorizedException
{
state.hasColumnFamilyAccess(keyspace(), columnFamily(), Permission.WRITE);
}
@ -72,20 +69,13 @@ public abstract class ModificationStatement extends CFStatement implements CQLSt
if (timeToLive < 0)
throw new InvalidRequestException("A TTL must be greater or equal to 0");
ThriftValidation.validateConsistencyLevel(keyspace(), getConsistencyLevel(), RequestType.WRITE);
getConsistencyLevel().validateForWrite(keyspace());
}
public ResultMessage execute(ClientState state, List<ByteBuffer> variables) throws InvalidRequestException, UnavailableException, TimedOutException
public ResultMessage execute(ClientState state, List<ByteBuffer> variables) throws RequestExecutionException, RequestValidationException
{
try
{
StorageProxy.mutate(getMutations(state, variables), getConsistencyLevel());
return null;
}
catch (TimeoutException e)
{
throw new TimedOutException();
}
StorageProxy.mutate(getMutations(state, variables), getConsistencyLevel());
return null;
}
public ConsistencyLevel getConsistencyLevel()
@ -118,7 +108,8 @@ public abstract class ModificationStatement extends CFStatement implements CQLSt
return timeToLive;
}
public Map<ByteBuffer, ColumnGroupMap> readRows(List<ByteBuffer> keys, ColumnNameBuilder builder, CompositeType composite) throws UnavailableException, TimeoutException, InvalidRequestException
public Map<ByteBuffer, ColumnGroupMap> readRows(List<ByteBuffer> keys, ColumnNameBuilder builder, CompositeType composite)
throws RequestExecutionException, RequestValidationException
{
List<ReadCommand> commands = new ArrayList<ReadCommand>(keys.size());
for (ByteBuffer key : keys)
@ -167,7 +158,8 @@ public abstract class ModificationStatement extends CFStatement implements CQLSt
* @return list of the mutations
* @throws InvalidRequestException on invalid requests
*/
public abstract List<IMutation> getMutations(ClientState clientState, List<ByteBuffer> variables) throws UnavailableException, TimeoutException, InvalidRequestException;
public abstract List<IMutation> getMutations(ClientState clientState, List<ByteBuffer> variables)
throws RequestExecutionException, RequestValidationException;
public abstract ParsedStatement.Prepared prepare(CFDefinition.Name[] boundNames) throws InvalidRequestException;
}

View File

@ -21,7 +21,7 @@ import java.util.Collections;
import java.util.List;
import org.apache.cassandra.cql3.*;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.RequestValidationException;
public abstract class ParsedStatement
{
@ -38,7 +38,7 @@ public abstract class ParsedStatement
this.boundTerms = boundTerms;
}
public abstract Prepared prepare() throws InvalidRequestException;
public abstract Prepared prepare() throws RequestValidationException;
public static class Prepared
{

View File

@ -24,12 +24,14 @@ import java.util.Map;
import org.apache.cassandra.cql3.CQLStatement;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.auth.Permission;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.cql3.CFName;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.exceptions.UnauthorizedException;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.StorageProxy;
import org.apache.cassandra.thrift.InvalidRequestException;
import com.google.common.base.Predicates;
import com.google.common.collect.Maps;
@ -67,9 +69,9 @@ public abstract class SchemaAlteringStatement extends CFStatement implements CQL
return new Prepared(this);
}
public abstract void announceMigration() throws InvalidRequestException, ConfigurationException;
public abstract void announceMigration() throws RequestValidationException;
public void checkAccess(ClientState state) throws InvalidRequestException
public void checkAccess(ClientState state) throws UnauthorizedException, InvalidRequestException
{
if (isColumnFamilyLevel)
state.hasColumnFamilySchemaAccess(keyspace(), Permission.WRITE);
@ -78,10 +80,10 @@ public abstract class SchemaAlteringStatement extends CFStatement implements CQL
}
@Override
public void validate(ClientState state) throws InvalidRequestException
public void validate(ClientState state) throws RequestValidationException
{}
public ResultMessage execute(ClientState state, List<ByteBuffer> variables) throws InvalidRequestException
public ResultMessage execute(ClientState state, List<ByteBuffer> variables) throws RequestValidationException
{
try
{
@ -93,7 +95,6 @@ public abstract class SchemaAlteringStatement extends CFStatement implements CQL
ex.initCause(e);
throw ex;
}
return null;
}
}

View File

@ -20,7 +20,6 @@ package org.apache.cassandra.cql3.statements;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.TimeoutException;
import com.google.common.collect.AbstractIterator;
import org.slf4j.Logger;
@ -31,7 +30,7 @@ import org.apache.cassandra.cql3.*;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.context.CounterContext;
import org.apache.cassandra.db.filter.*;
@ -39,17 +38,15 @@ import org.apache.cassandra.db.index.SecondaryIndex;
import org.apache.cassandra.db.index.SecondaryIndexManager;
import org.apache.cassandra.db.marshal.*;
import org.apache.cassandra.dht.*;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.StorageProxy;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.thrift.IndexExpression;
import org.apache.cassandra.thrift.IndexOperator;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.RequestType;
import org.apache.cassandra.thrift.TimedOutException;
import org.apache.cassandra.thrift.ThriftValidation;
import org.apache.cassandra.thrift.UnavailableException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Pair;
@ -103,7 +100,7 @@ public class SelectStatement implements CQLStatement
return boundTerms;
}
public void checkAccess(ClientState state) throws InvalidRequestException
public void checkAccess(ClientState state) throws InvalidRequestException, UnauthorizedException
{
state.hasColumnFamilyAccess(keyspace(), columnFamily(), Permission.READ);
}
@ -113,34 +110,27 @@ public class SelectStatement implements CQLStatement
// Nothing to do, all validation has been done by RawStatement.prepare()
}
public ResultMessage.Rows execute(ClientState state, List<ByteBuffer> variables) throws InvalidRequestException, UnavailableException, TimedOutException
public ResultMessage.Rows execute(ClientState state, List<ByteBuffer> variables) throws RequestExecutionException, RequestValidationException
{
return new ResultMessage.Rows(executeInternal(state, variables));
}
public ResultSet executeInternal(ClientState state, List<ByteBuffer> variables) throws InvalidRequestException, UnavailableException, TimedOutException
public ResultSet executeInternal(ClientState state, List<ByteBuffer> variables) throws RequestExecutionException, RequestValidationException
{
try
List<Row> rows;
if (isKeyRange)
{
List<Row> rows;
if (isKeyRange)
{
rows = multiRangeSlice(variables);
}
else
{
rows = getSlice(variables);
}
rows = multiRangeSlice(variables);
}
else
{
rows = getSlice(variables);
}
// Even for count, we need to process the result as it'll group some column together in sparse column families
ResultSet rset = process(rows, variables);
rset = parameters.isCount ? rset.makeCountResult() : rset;
return rset;
}
catch (TimeoutException e)
{
throw new TimedOutException();
}
// Even for count, we need to process the result as it'll group some column together in sparse column families
ResultSet rset = process(rows, variables);
rset = parameters.isCount ? rset.makeCountResult() : rset;
return rset;
}
public ResultSet process(List<Row> rows) throws InvalidRequestException
@ -159,7 +149,7 @@ public class SelectStatement implements CQLStatement
return cfDef.cfm.cfName;
}
private List<Row> getSlice(List<ByteBuffer> variables) throws InvalidRequestException, TimeoutException, UnavailableException
private List<Row> getSlice(List<ByteBuffer> variables) throws RequestExecutionException, RequestValidationException
{
QueryPath queryPath = new QueryPath(columnFamily());
Collection<ByteBuffer> keys = getKeys(variables);
@ -198,7 +188,7 @@ public class SelectStatement implements CQLStatement
}
}
private List<Row> multiRangeSlice(List<ByteBuffer> variables) throws InvalidRequestException, TimeoutException, UnavailableException
private List<Row> multiRangeSlice(List<ByteBuffer> variables) throws RequestExecutionException, RequestValidationException
{
List<Row> rows;
IFilter filter = makeFilter(variables);
@ -896,7 +886,7 @@ public class SelectStatement implements CQLStatement
public ParsedStatement.Prepared prepare() throws InvalidRequestException
{
CFMetaData cfm = ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
ThriftValidation.validateConsistencyLevel(keyspace(), parameters.consistencyLevel, RequestType.READ);
parameters.consistencyLevel.validateForRead(keyspace());
if (parameters.limit <= 0)
throw new InvalidRequestException("LIMIT must be strictly positive");

View File

@ -24,12 +24,11 @@ import java.util.concurrent.TimeoutException;
import org.apache.cassandra.auth.Permission;
import org.apache.cassandra.cql3.*;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.StorageProxy;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.ThriftValidation;
import org.apache.cassandra.thrift.UnavailableException;
public class TruncateStatement extends CFStatement implements CQLStatement
{
@ -43,7 +42,7 @@ public class TruncateStatement extends CFStatement implements CQLStatement
return new Prepared(this);
}
public void checkAccess(ClientState state) throws InvalidRequestException
public void checkAccess(ClientState state) throws InvalidRequestException, UnauthorizedException
{
state.hasColumnFamilyAccess(keyspace(), columnFamily(), Permission.WRITE);
}
@ -53,19 +52,23 @@ public class TruncateStatement extends CFStatement implements CQLStatement
ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
}
public ResultMessage execute(ClientState state, List<ByteBuffer> variables) throws InvalidRequestException, UnavailableException
public ResultMessage execute(ClientState state, List<ByteBuffer> variables) throws InvalidRequestException, TruncateException
{
try
{
StorageProxy.truncateBlocking(keyspace(), columnFamily());
}
catch (UnavailableException e)
{
throw new TruncateException(e);
}
catch (TimeoutException e)
{
throw (UnavailableException) new UnavailableException().initCause(e);
throw new TruncateException(e);
}
catch (IOException e)
{
throw (UnavailableException) new UnavailableException().initCause(e);
throw new TruncateException(e);
}
return null;
}

View File

@ -29,16 +29,14 @@ import org.apache.cassandra.cql3.operations.ColumnOperation;
import org.apache.cassandra.cql3.operations.Operation;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.marshal.*;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.UnavailableException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.Pair;
import static org.apache.cassandra.cql.QueryProcessor.validateKey;
import static org.apache.cassandra.thrift.ThriftValidation.validateColumnFamily;
import static org.apache.cassandra.thrift.ThriftValidation.validateCommutativeForWrite;
/**
* An <code>UPDATE</code> statement parsed from a CQL query statement.
@ -102,7 +100,8 @@ public class UpdateStatement extends ModificationStatement
/** {@inheritDoc} */
public List<IMutation> getMutations(ClientState clientState, List<ByteBuffer> variables) throws UnavailableException, TimeoutException, InvalidRequestException
public List<IMutation> getMutations(ClientState clientState, List<ByteBuffer> variables)
throws RequestExecutionException, RequestValidationException
{
List<ByteBuffer> keys = buildKeyNames(cfDef, processedKeys, variables);
@ -305,7 +304,7 @@ public class UpdateStatement extends ModificationStatement
// Deal here with the keyspace overwrite thingy to avoid mistake
CFMetaData metadata = validateColumnFamily(keyspace(), columnFamily(), hasCommutativeOperation);
if (hasCommutativeOperation)
validateCommutativeForWrite(metadata, cLevel);
cLevel.validateCounterForWrite(metadata);
cfDef = metadata.getCfDef();

View File

@ -21,9 +21,9 @@ import java.nio.ByteBuffer;
import java.util.List;
import org.apache.cassandra.cql3.CQLStatement;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.InvalidRequestException;
public class UseStatement extends ParsedStatement implements CQLStatement
{

View File

@ -60,6 +60,7 @@ import org.apache.cassandra.db.index.SecondaryIndex;
import org.apache.cassandra.db.index.SecondaryIndexManager;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.dht.*;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.compress.CompressionParameters;
import org.apache.cassandra.io.sstable.*;
import org.apache.cassandra.io.sstable.Descriptor;

View File

@ -21,7 +21,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
/**
* The MBean interface for ColumnFamilyStore

View File

@ -0,0 +1,114 @@
/*
* 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.
*/
package org.apache.cassandra.db;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.locator.AbstractReplicationStrategy;
import org.apache.cassandra.locator.NetworkTopologyStrategy;
import org.apache.cassandra.utils.FBUtilities;
public enum ConsistencyLevel
{
ANY,
ONE,
TWO,
THREE,
QUORUM,
ALL,
LOCAL_QUORUM,
EACH_QUORUM;
private static final String LOCAL_DC = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress());
public int blockFor(String table)
{
NetworkTopologyStrategy strategy = null;
switch (this)
{
case ONE:
return 1;
case ANY:
return 1;
case TWO:
return 2;
case THREE:
return 3;
case QUORUM:
return (Table.open(table).getReplicationStrategy().getReplicationFactor() / 2) + 1;
case ALL:
return Table.open(table).getReplicationStrategy().getReplicationFactor();
case LOCAL_QUORUM:
strategy = (NetworkTopologyStrategy) Table.open(table).getReplicationStrategy();
return (strategy.getReplicationFactor(LOCAL_DC) / 2) + 1;
case EACH_QUORUM:
strategy = (NetworkTopologyStrategy) Table.open(table).getReplicationStrategy();
int n = 0;
for (String dc : strategy.getDatacenters())
n += (strategy.getReplicationFactor(dc) / 2) + 1;
return n;
default:
throw new UnsupportedOperationException("Invalid consistency level: " + toString());
}
}
public void validateForRead(String table) throws InvalidRequestException
{
switch (this)
{
case ANY:
throw new InvalidRequestException("ANY ConsistencyLevel is only supported for writes");
case LOCAL_QUORUM:
requireNetworkTopologyStrategy(table);
break;
case EACH_QUORUM:
throw new InvalidRequestException("EACH_QUORUM ConsistencyLevel is only supported for writes");
}
}
public void validateForWrite(String table) throws InvalidRequestException
{
switch (this)
{
case LOCAL_QUORUM:
case EACH_QUORUM:
requireNetworkTopologyStrategy(table);
break;
}
}
public void validateCounterForWrite(CFMetaData metadata) throws InvalidRequestException
{
if (this == ConsistencyLevel.ANY)
{
throw new InvalidRequestException("Consistency level ANY is not yet supported for counter columnfamily " + metadata.cfName);
}
else if (!metadata.getReplicateOnWrite() && this != ConsistencyLevel.ONE)
{
throw new InvalidRequestException("cannot achieve CL > CL.ONE without replicate_on_write on columnfamily " + metadata.cfName);
}
}
private void requireNetworkTopologyStrategy(String table) throws InvalidRequestException
{
AbstractReplicationStrategy strategy = Table.open(table).getReplicationStrategy();
if (!(strategy instanceof NetworkTopologyStrategy))
throw new InvalidRequestException(String.format("consistency level %s not compatible with replication strategy (%s)", this, strategy.getClass().getName()));
}
}

View File

@ -33,13 +33,14 @@ import org.apache.cassandra.db.context.CounterContext;
import org.apache.cassandra.db.context.IContext.ContextRelationship;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.MarshalException;
import org.apache.cassandra.exceptions.OverloadedException;
import org.apache.cassandra.exceptions.RequestExecutionException;
import org.apache.cassandra.io.IColumnSerializer;
import org.apache.cassandra.io.util.DataOutputBuffer;
import org.apache.cassandra.utils.Allocator;
import org.apache.cassandra.service.IWriteResponseHandler;
import org.apache.cassandra.service.StorageProxy;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.UnavailableException;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.utils.*;
/**
@ -357,7 +358,7 @@ public class CounterColumn extends Column
return new CounterColumn(name, contextManager.markDeltaToBeCleared(value), timestamp, timestampOfLastDelete);
}
private static void sendToOtherReplica(DecoratedKey key, ColumnFamily cf) throws UnavailableException, TimeoutException, IOException
private static void sendToOtherReplica(DecoratedKey key, ColumnFamily cf) throws RequestExecutionException, IOException
{
RowMutation rm = new RowMutation(cf.metadata().ksName, key.key);
rm.add(cf);
@ -368,7 +369,7 @@ public class CounterColumn extends Column
StorageProxy.performWrite(rm, ConsistencyLevel.ANY, localDataCenter, new StorageProxy.WritePerformer()
{
public void apply(IMutation mutation, Collection<InetAddress> targets, IWriteResponseHandler responseHandler, String localDataCenter, ConsistencyLevel consistency_level)
throws IOException, UnavailableException
throws IOException, OverloadedException
{
// We should only send to the remote replica, not the local one
targets.remove(local);

View File

@ -30,7 +30,7 @@ import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.io.IVersionedSerializer;
import org.apache.cassandra.net.MessageOut;
import org.apache.cassandra.net.MessagingService;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.HeapAllocator;

View File

@ -23,12 +23,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.exceptions.RequestExecutionException;
import org.apache.cassandra.net.IVerbHandler;
import org.apache.cassandra.net.MessageIn;
import org.apache.cassandra.net.MessagingService;
import org.apache.cassandra.service.StorageProxy;
import org.apache.cassandra.thrift.TimedOutException;
import org.apache.cassandra.thrift.UnavailableException;
import org.apache.cassandra.utils.FBUtilities;
public class CounterMutationVerbHandler implements IVerbHandler<CounterMutation>
@ -48,17 +47,10 @@ public class CounterMutationVerbHandler implements IVerbHandler<CounterMutation>
WriteResponse response = new WriteResponse();
MessagingService.instance().sendReply(response.createMessage(), id, message.from);
}
catch (UnavailableException e)
catch (RequestExecutionException e)
{
// We check for UnavailableException in the coordinator now. It is
// hence reasonable to let the coordinator timeout in the very
// unlikely case we arrive here
logger.debug("counter unavailable", e);
}
catch (TimedOutException e)
{
// The coordinator node will have timeout itself so we let that goes
logger.debug("counter timeout", e);
// The coordinator will timeout on itself, so let that go
logger.debug("counter error", e);
}
catch (IOException e)
{

View File

@ -41,6 +41,7 @@ import org.apache.cassandra.db.filter.QueryPath;
import org.apache.cassandra.db.marshal.AsciiType;
import org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.cassandra.db.migration.avro.KsDef;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;

View File

@ -44,6 +44,7 @@ import org.apache.cassandra.db.marshal.UUIDType;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.Range;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.exceptions.WriteTimeoutException;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.FailureDetector;
import org.apache.cassandra.gms.Gossiper;
@ -125,7 +126,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean
StorageService.optionalTasks.scheduleWithFixedDelay(runnable, 10, 10, TimeUnit.MINUTES);
}
private static void sendMutation(InetAddress endpoint, MessageOut<?> message) throws TimedOutException
private static void sendMutation(InetAddress endpoint, MessageOut<?> message) throws WriteTimeoutException
{
IWriteResponseHandler responseHandler = WriteResponseHandler.create(endpoint);
MessagingService.instance().sendRR(message, endpoint, responseHandler);
@ -364,7 +365,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean
}
deleteHint(hostIdBytes, hint.name(), hint.maxTimestamp());
}
catch (TimedOutException e)
catch (WriteTimeoutException e)
{
logger.info(String.format("Timed out replaying hints to %s; aborting further deliveries", endpoint));
break delivery;

View File

@ -17,7 +17,7 @@
*/
package org.apache.cassandra.db;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.exceptions.InvalidRequestException;
public class KeyspaceNotDefinedException extends InvalidRequestException
{

View File

@ -50,11 +50,19 @@ import org.apache.cassandra.db.filter.NamesQueryFilter;
import org.apache.cassandra.db.filter.SliceQueryFilter;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.dht.AbstractBounds;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.io.IVersionedSerializer;
import org.apache.cassandra.net.MessageOut;
import org.apache.cassandra.net.MessagingService;
import org.apache.cassandra.service.IReadCommand;
import org.apache.cassandra.thrift.*;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.IndexClause;
import org.apache.cassandra.thrift.IndexExpression;
import org.apache.cassandra.thrift.IndexOperator;
import org.apache.cassandra.thrift.SlicePredicate;
import org.apache.cassandra.thrift.SliceRange;
import org.apache.cassandra.thrift.TBinaryProtocol;
import org.apache.cassandra.thrift.ThriftValidation;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.thrift.TDeserializer;

View File

@ -28,7 +28,7 @@ import com.google.common.collect.Multimap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.cql3.QueryProcessor;
import org.apache.cassandra.cql3.UntypedResultSet;

View File

@ -37,6 +37,7 @@ import org.apache.cassandra.db.filter.ColumnSlice;
import org.apache.cassandra.db.filter.QueryFilter;
import org.apache.cassandra.db.index.SecondaryIndex;
import org.apache.cassandra.db.index.SecondaryIndexManager;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.sstable.SSTableReader;
import org.apache.cassandra.locator.AbstractReplicationStrategy;
import org.apache.cassandra.service.StorageService;

View File

@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.db.IColumn;

View File

@ -29,7 +29,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.compaction.CompactionManager;
import org.apache.cassandra.db.filter.IFilter;

View File

@ -21,12 +21,12 @@ import java.nio.ByteBuffer;
import java.util.Set;
import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.index.AbstractSimplePerColumnSecondaryIndex;
import org.apache.cassandra.db.index.SecondaryIndex;
import org.apache.cassandra.db.index.SecondaryIndexSearcher;
import org.apache.cassandra.db.marshal.*;
import org.apache.cassandra.exceptions.ConfigurationException;
/**
* Implements a secondary index for a column family using a second column family

View File

@ -23,7 +23,7 @@ import java.util.concurrent.ExecutionException;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.index.AbstractSimplePerColumnSecondaryIndex;
import org.apache.cassandra.db.index.SecondaryIndexSearcher;

View File

@ -22,7 +22,7 @@ import java.util.Collection;
import java.util.Comparator;
import java.util.Map;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.db.IColumn;
import org.apache.cassandra.db.OnDiskAtom;
import org.apache.cassandra.db.RangeTombstone;
@ -174,7 +174,7 @@ public abstract class AbstractType<T> implements Comparator<ByteBuffer>
return false;
}
public static AbstractType<?> parseDefaultParameters(AbstractType<?> baseType, TypeParser parser) throws ConfigurationException
public static AbstractType<?> parseDefaultParameters(AbstractType<?> baseType, TypeParser parser) throws SyntaxException
{
Map<String, String> parameters = parser.getKeyValueParameters();
String reversed = parameters.get("reversed");

View File

@ -23,7 +23,8 @@ import java.util.Map;
import com.google.common.collect.ImmutableMap;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.utils.ByteBufferUtil;
public class ColumnToCollectionType extends AbstractType<ByteBuffer>
@ -33,7 +34,7 @@ public class ColumnToCollectionType extends AbstractType<ByteBuffer>
public final Map<ByteBuffer, CollectionType> defined;
public static ColumnToCollectionType getInstance(TypeParser parser) throws ConfigurationException
public static ColumnToCollectionType getInstance(TypeParser parser) throws SyntaxException, ConfigurationException
{
return getInstance(parser.getCollectionsParameters());
}

View File

@ -27,12 +27,13 @@ import java.util.Map;
import com.google.common.collect.ImmutableList;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.cql3.ColumnNameBuilder;
import org.apache.cassandra.cql3.Relation;
import org.apache.cassandra.cql3.Term;
import org.apache.cassandra.io.util.DataOutputBuffer;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.utils.ByteBufferUtil;
/*
@ -62,7 +63,7 @@ public class CompositeType extends AbstractCompositeType
// interning instances
private static final Map<List<AbstractType<?>>, CompositeType> instances = new HashMap<List<AbstractType<?>>, CompositeType>();
public static CompositeType getInstance(TypeParser parser) throws ConfigurationException
public static CompositeType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
{
return getInstance(parser.getTypeParameters());
}

View File

@ -22,7 +22,8 @@ import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.utils.ByteBufferUtil;
/*
@ -51,7 +52,7 @@ public class DynamicCompositeType extends AbstractCompositeType
// interning instances
private static final Map<Map<Byte, AbstractType<?>>, DynamicCompositeType> instances = new HashMap<Map<Byte, AbstractType<?>>, DynamicCompositeType>();
public static synchronized DynamicCompositeType getInstance(TypeParser parser) throws ConfigurationException
public static synchronized DynamicCompositeType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
{
return getInstance(parser.getAliasParameters());
}
@ -95,6 +96,10 @@ public class DynamicCompositeType extends AbstractCompositeType
{
throw new RuntimeException(e);
}
catch (SyntaxException e)
{
throw new RuntimeException(e);
}
}
protected AbstractType<?> getComparator(int i, ByteBuffer bb)
@ -155,6 +160,10 @@ public class DynamicCompositeType extends AbstractCompositeType
{
throw new RuntimeException(e);
}
catch (SyntaxException e)
{
throw new RuntimeException(e);
}
}
protected ParsedComparator parseComparator(int i, String part)
@ -259,6 +268,10 @@ public class DynamicCompositeType extends AbstractCompositeType
}
type = t;
}
catch (SyntaxException e)
{
throw new IllegalArgumentException(e);
}
catch (ConfigurationException e)
{
throw new IllegalArgumentException(e);

View File

@ -21,7 +21,8 @@ import java.nio.ByteBuffer;
import java.util.*;
import org.apache.cassandra.db.IColumn;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Pair;
@ -33,7 +34,7 @@ public class ListType<T> extends CollectionType<List<T>>
public final AbstractType<T> elements;
public static ListType<?> getInstance(TypeParser parser) throws ConfigurationException
public static ListType<?> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
{
List<AbstractType<?>> l = parser.getTypeParameters();
if (l.size() != 1)

View File

@ -21,7 +21,8 @@ import java.nio.ByteBuffer;
import java.util.*;
import org.apache.cassandra.db.IColumn;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Pair;
@ -34,7 +35,7 @@ public class MapType<K, V> extends CollectionType<Map<K, V>>
public final AbstractType<K> keys;
public final AbstractType<V> values;
public static MapType<?, ?> getInstance(TypeParser parser) throws ConfigurationException
public static MapType<?, ?> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
{
List<AbstractType<?>> l = parser.getTypeParameters();
if (l.size() != 2)

View File

@ -22,7 +22,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.List;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.SyntaxException;
public class ReversedType<T> extends AbstractType<T>
{
@ -32,7 +33,7 @@ public class ReversedType<T> extends AbstractType<T>
// package protected for unit tests sake
final AbstractType<T> baseType;
public static <T> ReversedType<T> getInstance(TypeParser parser) throws ConfigurationException
public static <T> ReversedType<T> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
{
List<AbstractType<?>> types = parser.getTypeParameters();
if (types.size() != 1)

View File

@ -21,7 +21,8 @@ import java.nio.ByteBuffer;
import java.util.*;
import org.apache.cassandra.db.IColumn;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.SyntaxException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Pair;
@ -33,7 +34,7 @@ public class SetType<T> extends CollectionType<Set<T>>
public final AbstractType<T> elements;
public static SetType<?> getInstance(TypeParser parser) throws ConfigurationException
public static SetType<?> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
{
List<AbstractType<?>> l = parser.getTypeParameters();
if (l.size() != 1)

View File

@ -29,7 +29,7 @@ import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
@ -60,7 +60,7 @@ public class TypeParser
/**
* Parse a string containing an type definition.
*/
public static AbstractType<?> parse(String str) throws ConfigurationException
public static AbstractType<?> parse(String str) throws SyntaxException, ConfigurationException
{
if (str == null)
return BytesType.instance;
@ -93,7 +93,7 @@ public class TypeParser
return type;
}
public static AbstractType<?> parse(CharSequence compareWith) throws ConfigurationException
public static AbstractType<?> parse(CharSequence compareWith) throws SyntaxException, ConfigurationException
{
return parse(compareWith == null ? null : compareWith.toString());
}
@ -106,7 +106,7 @@ public class TypeParser
/**
* Parse an AbstractType from current position of this parser.
*/
public AbstractType<?> parse() throws ConfigurationException
public AbstractType<?> parse() throws SyntaxException, ConfigurationException
{
skipBlank();
String name = readNextIdentifier();
@ -118,7 +118,7 @@ public class TypeParser
return getAbstractType(name);
}
public Map<String, String> getKeyValueParameters() throws ConfigurationException
public Map<String, String> getKeyValueParameters() throws SyntaxException
{
Map<String, String> map = new HashMap<String, String>();
@ -153,10 +153,10 @@ public class TypeParser
}
map.put(k, v);
}
throw new ConfigurationException(String.format("Syntax error parsing '%s' at char %d: unexpected end of string", str, idx));
throw new SyntaxException(String.format("Syntax error parsing '%s' at char %d: unexpected end of string", str, idx));
}
public List<AbstractType<?>> getTypeParameters() throws ConfigurationException
public List<AbstractType<?>> getTypeParameters() throws SyntaxException, ConfigurationException
{
List<AbstractType<?>> list = new ArrayList<AbstractType<?>>();
@ -180,17 +180,17 @@ public class TypeParser
{
list.add(parse());
}
catch (ConfigurationException e)
catch (SyntaxException e)
{
ConfigurationException ex = new ConfigurationException(String.format("Exception while parsing '%s' around char %d", str, idx));
SyntaxException ex = new SyntaxException(String.format("Exception while parsing '%s' around char %d", str, idx));
ex.initCause(e);
throw ex;
}
}
throw new ConfigurationException(String.format("Syntax error parsing '%s' at char %d: unexpected end of string", str, idx));
throw new SyntaxException(String.format("Syntax error parsing '%s' at char %d: unexpected end of string", str, idx));
}
public Map<Byte, AbstractType<?>> getAliasParameters() throws ConfigurationException
public Map<Byte, AbstractType<?>> getAliasParameters() throws SyntaxException, ConfigurationException
{
Map<Byte, AbstractType<?>> map = new HashMap<Byte, AbstractType<?>>();
@ -228,17 +228,17 @@ public class TypeParser
{
map.put((byte)aliasChar, parse());
}
catch (ConfigurationException e)
catch (SyntaxException e)
{
ConfigurationException ex = new ConfigurationException(String.format("Exception while parsing '%s' around char %d", str, idx));
SyntaxException ex = new SyntaxException(String.format("Exception while parsing '%s' around char %d", str, idx));
ex.initCause(e);
throw ex;
}
}
throw new ConfigurationException(String.format("Syntax error parsing '%s' at char %d: unexpected end of string", str, idx));
throw new SyntaxException(String.format("Syntax error parsing '%s' at char %d: unexpected end of string", str, idx));
}
public Map<ByteBuffer, CollectionType> getCollectionsParameters() throws ConfigurationException
public Map<ByteBuffer, CollectionType> getCollectionsParameters() throws SyntaxException, ConfigurationException
{
Map<ByteBuffer, CollectionType> map = new HashMap<ByteBuffer, CollectionType>();
@ -279,17 +279,17 @@ public class TypeParser
{
AbstractType<?> type = parse();
if (!(type instanceof CollectionType))
throw new ConfigurationException(type.toString() + " is not a collection type");
throw new SyntaxException(type.toString() + " is not a collection type");
map.put(bb, (CollectionType)type);
}
catch (ConfigurationException e)
catch (SyntaxException e)
{
ConfigurationException ex = new ConfigurationException(String.format("Exception while parsing '%s' around char %d", str, idx));
SyntaxException ex = new SyntaxException(String.format("Exception while parsing '%s' around char %d", str, idx));
ex.initCause(e);
throw ex;
}
}
throw new ConfigurationException(String.format("Syntax error parsing '%s' at char %d: unexpected end of string", str, idx));
throw new SyntaxException(String.format("Syntax error parsing '%s' at char %d: unexpected end of string", str, idx));
}
private static AbstractType<?> getAbstractType(String compareWith) throws ConfigurationException
@ -313,7 +313,7 @@ public class TypeParser
}
}
private static AbstractType<?> getAbstractType(String compareWith, TypeParser parser) throws ConfigurationException
private static AbstractType<?> getAbstractType(String compareWith, TypeParser parser) throws SyntaxException, ConfigurationException
{
String className = compareWith.contains(".") ? compareWith : "org.apache.cassandra.db.marshal." + compareWith;
Class<? extends AbstractType<?>> typeClass = FBUtilities.<AbstractType<?>>classForName(className, "abstract-type");
@ -382,9 +382,9 @@ public class TypeParser
}
}
private void throwSyntaxError(String msg) throws ConfigurationException
private void throwSyntaxError(String msg) throws SyntaxException
{
throw new ConfigurationException(String.format("Syntax error parsing '%s' at char %d: %s", str, idx, msg));
throw new SyntaxException(String.format("Syntax error parsing '%s' at char %d: %s", str, idx, msg));
}
private boolean isEOS()

View File

@ -26,6 +26,7 @@ import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.commons.lang.ArrayUtils;
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Hex;

View File

@ -28,9 +28,8 @@ import java.util.concurrent.locks.Condition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.gms.*;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.Table;
import org.apache.cassandra.locator.AbstractReplicationStrategy;

View File

@ -24,8 +24,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.MurmurHash;

View File

@ -24,6 +24,7 @@ import java.util.*;
import org.apache.cassandra.config.*;
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.gms.VersionedValue;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.utils.ByteBufferUtil;

View File

@ -23,7 +23,7 @@ import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.util.*;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;

View File

@ -23,7 +23,7 @@ import java.io.IOException;
import java.io.Serializable;
import java.nio.ByteBuffer;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.db.TypeSizes;
import org.apache.cassandra.db.RowPosition;
import org.apache.cassandra.io.ISerializer;

View File

@ -0,0 +1,42 @@
/*
* 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.
*/
package org.apache.cassandra.exceptions;
public class AlreadyExistsException extends ConfigurationException
{
public final String ksName;
public final String cfName;
private AlreadyExistsException(String ksName, String cfName, String msg)
{
super(ExceptionCode.ALREADY_EXISTS, msg);
this.ksName = ksName;
this.cfName = cfName;
}
public AlreadyExistsException(String ksName, String cfName)
{
this(ksName, cfName, String.format("Cannot add already existing column family \"%s\" to keyspace \"%s\"", ksName, cfName));
}
public AlreadyExistsException(String ksName)
{
this(ksName, "", String.format("Cannot add existing keyspace \"%s\"", ksName));
}
}

View File

@ -0,0 +1,42 @@
/*
* 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.
*/
package org.apache.cassandra.exceptions;
import java.nio.ByteBuffer;
public abstract class CassandraException extends Exception implements TransportException
{
private final ExceptionCode code;
protected CassandraException(ExceptionCode code, String msg)
{
super(msg);
this.code = code;
}
protected CassandraException(ExceptionCode code, String msg, Throwable cause)
{
super(msg, cause);
this.code = code;
}
public ExceptionCode code()
{
return code;
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.
*/
package org.apache.cassandra.exceptions;
public class ConfigurationException extends RequestValidationException
{
public ConfigurationException(String msg)
{
super(ExceptionCode.CONFIG_ERROR, msg);
}
public ConfigurationException(String msg, Throwable e)
{
super(ExceptionCode.CONFIG_ERROR, msg, e);
}
protected ConfigurationException(ExceptionCode code, String msg)
{
super(code, msg);
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.
*/
package org.apache.cassandra.exceptions;
import java.util.HashMap;
import java.util.Map;
import org.apache.cassandra.transport.ProtocolException;
/**
* Exceptions code, as defined by the binary protocol.
*/
public enum ExceptionCode
{
SERVER_ERROR (0x0000),
PROTOCOL_ERROR (0x000A),
// 1xx: problem during request execution
UNAVAILABLE (0x1000),
OVERLOADED (0x1001),
IS_BOOTSTRAPPING(0x1002),
TRUNCATE_ERROR (0x1003),
WRITE_TIMEOUT (0x1100),
READ_TIMEOUT (0x1200),
// 2xx: problem validating the request
SYNTAX_ERROR (0x2000),
UNAUTHORIZED (0x2100),
INVALID (0x2200),
CONFIG_ERROR (0x2300),
ALREADY_EXISTS (0x2400);
public final int value;
private static final Map<Integer, ExceptionCode> valueToCode = new HashMap<Integer, ExceptionCode>(ExceptionCode.values().length);
static
{
for (ExceptionCode code : ExceptionCode.values())
valueToCode.put(code.value, code);
}
private ExceptionCode(int value)
{
this.value = value;
}
public static ExceptionCode fromValue(int value)
{
ExceptionCode code = valueToCode.get(value);
if (code == null)
throw new ProtocolException(String.format("Unknown error code %d", value));
return code;
}
}

View File

@ -15,17 +15,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.config;
package org.apache.cassandra.exceptions;
public class ConfigurationException extends Exception
public class InvalidRequestException extends RequestValidationException
{
public ConfigurationException(String message)
public InvalidRequestException(String msg)
{
super(message);
}
public ConfigurationException(String message, Exception e)
{
super(message, e);
super(ExceptionCode.INVALID, msg);
}
}

View File

@ -0,0 +1,26 @@
/*
* 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.
*/
package org.apache.cassandra.exceptions;
public class IsBootstrappingException extends RequestExecutionException
{
public IsBootstrappingException()
{
super(ExceptionCode.IS_BOOTSTRAPPING, "Cannot read from a bootstrapping node");
}
}

View File

@ -0,0 +1,26 @@
/*
* 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.
*/
package org.apache.cassandra.exceptions;
public class OverloadedException extends RequestExecutionException
{
public OverloadedException(String reason)
{
super(ExceptionCode.OVERLOADED, reason);
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.
*/
package org.apache.cassandra.exceptions;
import java.net.InetAddress;
import java.util.Set;
import java.nio.ByteBuffer;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.utils.ByteBufferUtil;
public class ReadTimeoutException extends RequestTimeoutException
{
public final boolean dataPresent;
public ReadTimeoutException(ConsistencyLevel consistency, int received, int blockFor, boolean dataPresent)
{
super(ExceptionCode.READ_TIMEOUT, consistency, received, blockFor);
this.dataPresent = dataPresent;
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.
*/
package org.apache.cassandra.exceptions;
import org.apache.cassandra.db.ConsistencyLevel;
public abstract class RequestExecutionException extends CassandraException
{
protected RequestExecutionException(ExceptionCode code, String msg)
{
super(code, msg);
}
protected RequestExecutionException(ExceptionCode code, String msg, Throwable e)
{
super(code, msg, e);
}
}

View File

@ -0,0 +1,40 @@
/*
* 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.
*/
package org.apache.cassandra.exceptions;
import java.net.InetAddress;
import java.util.Set;
import java.nio.ByteBuffer;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.utils.ByteBufferUtil;
public class RequestTimeoutException extends RequestExecutionException
{
public final ConsistencyLevel consistency;
public final int received;
public final int blockFor;
protected RequestTimeoutException(ExceptionCode code, ConsistencyLevel consistency, int received, int blockFor)
{
super(code, String.format("Operation timed out - received only %d responses.", received));
this.consistency = consistency;
this.received = received;
this.blockFor = blockFor;
}
}

Some files were not shown because too many files have changed in this diff Show More