use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.
the class Attributes method getTimeToLive.
public int getTimeToLive(QueryOptions options, int defaultTimeToLive) throws InvalidRequestException {
if (timeToLive == null)
return defaultTimeToLive;
ByteBuffer tval = timeToLive.bindAndGet(options);
if (tval == null)
return 0;
if (tval == ByteBufferUtil.UNSET_BYTE_BUFFER)
return defaultTimeToLive;
try {
Int32Type.instance.validate(tval);
} catch (MarshalException e) {
throw new InvalidRequestException("Invalid timestamp value: " + tval);
}
int ttl = Int32Type.instance.compose(tval);
if (ttl < 0)
throw new InvalidRequestException("A TTL must be greater or equal to 0, but was " + ttl);
if (ttl > MAX_TTL)
throw new InvalidRequestException(String.format("ttl is too large. requested (%d) maximum (%d)", ttl, MAX_TTL));
if (defaultTimeToLive != LivenessInfo.NO_TTL && ttl == LivenessInfo.NO_TTL)
return LivenessInfo.NO_TTL;
return ttl;
}
use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.
the class CQLSSTableWriter method rawAddRow.
/**
* Adds a new row to the writer given already serialized values.
* <p>
* This is a shortcut for {@code rawAddRow(Arrays.asList(values))}.
*
* @param values the row values (corresponding to the bind variables of the
* insertion statement used when creating by this writer) as binary.
* @return this writer.
*/
public CQLSSTableWriter rawAddRow(List<ByteBuffer> values) throws InvalidRequestException, IOException {
if (values.size() != boundNames.size())
throw new InvalidRequestException(String.format("Invalid number of arguments, expecting %d values but got %d", boundNames.size(), values.size()));
QueryOptions options = QueryOptions.forInternalCalls(null, values);
List<ByteBuffer> keys = insert.buildPartitionKeyNames(options);
SortedSet<Clustering> clusterings = insert.createClustering(options);
long now = System.currentTimeMillis() * 1000;
// Note that we asks indexes to not validate values (the last 'false' arg below) because that triggers a 'Keyspace.open'
// and that forces a lot of initialization that we don't want.
UpdateParameters params = new UpdateParameters(insert.metadata, insert.updatedColumns(), options, insert.getTimestamp(now, options), insert.getTimeToLive(options), Collections.<DecoratedKey, Partition>emptyMap());
try {
for (ByteBuffer key : keys) {
for (Clustering clustering : clusterings) insert.addUpdateForKey(writer.getUpdateFor(key), clustering, params);
}
return this;
} catch (SSTableSimpleUnsortedWriter.SyncException e) {
// wrapped in a SyncException (see BufferedWriter below). We want to extract that IOE.
throw (IOException) e.getCause();
}
}
use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.
the class TriggerExecutor method execute.
/**
* Takes a collection of mutations and possibly augments it by adding extra mutations
* generated by configured triggers. If no additional mutations are created
* this returns null, signalling to the caller that only the initial set of
* mutations should be applied. If additional mutations <i>are</i> generated,
* the total set (i.e. the original plus the additional mutations) are applied
* together in a logged batch. Should this not be possible because the initial
* mutations contain counter updates, InvalidRequestException is thrown.
*
* @param mutations initial collection of mutations
* @return augmented mutations. Either the union of the initial and additional
* mutations or null if no additional mutations were generated
* @throws InvalidRequestException if additional mutations were generated, but
* the initial mutations contains counter updates
*/
public Collection<Mutation> execute(Collection<? extends IMutation> mutations) throws InvalidRequestException {
boolean hasCounters = false;
List<Mutation> augmentedMutations = null;
for (IMutation mutation : mutations) {
if (mutation instanceof CounterMutation)
hasCounters = true;
for (PartitionUpdate upd : mutation.getPartitionUpdates()) {
List<Mutation> augmentations = executeInternal(upd);
if (augmentations == null || augmentations.isEmpty())
continue;
validate(augmentations);
if (augmentedMutations == null)
augmentedMutations = new LinkedList<>();
augmentedMutations.addAll(augmentations);
}
}
if (augmentedMutations == null)
return null;
if (hasCounters)
throw new InvalidRequestException("Counter mutations and trigger mutations cannot be applied together atomically.");
@SuppressWarnings("unchecked") Collection<Mutation> originalMutations = (Collection<Mutation>) mutations;
return mergeMutations(Iterables.concat(originalMutations, augmentedMutations));
}
use of org.apache.cassandra.exceptions.InvalidRequestException in project cassandra by apache.
the class AggregationTest method testBrokenAggregate.
@Test
public void testBrokenAggregate() throws Throwable {
createTable("CREATE TABLE %s (key int primary key, val int)");
execute("INSERT INTO %s (key, val) VALUES (?, ?)", 1, 1);
String fState = createFunction(KEYSPACE, "int, int", "CREATE FUNCTION %s(a int, b int) " + "CALLED ON NULL INPUT " + "RETURNS int " + "LANGUAGE javascript " + "AS 'a + b;'");
String a = createAggregate(KEYSPACE, "int", "CREATE AGGREGATE %s(int) " + "SFUNC " + shortFunctionName(fState) + " " + "STYPE int ");
KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace());
UDAggregate f = (UDAggregate) ksm.functions.get(parseFunctionName(a)).iterator().next();
UDAggregate broken = UDAggregate.createBroken(f.name(), f.argTypes(), f.returnType(), null, new InvalidRequestException("foo bar is broken"));
Schema.instance.load(ksm.withSwapped(ksm.functions.without(f.name(), f.argTypes()).with(broken)));
assertInvalidThrowMessage("foo bar is broken", InvalidRequestException.class, "SELECT " + a + "(val) FROM %s");
}
Aggregations