use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class AbstractCompositeType method validate.
@Override
public void validate(ByteBuffer bytes) throws MarshalException {
ByteBuffer bb = bytes.duplicate();
readIsStatic(bb);
int i = 0;
ByteBuffer previous = null;
while (bb.remaining() > 0) {
AbstractType<?> comparator = validateComparator(i, bb);
if (bb.remaining() < 2)
throw new MarshalException("Not enough bytes to read value size of component " + i);
int length = ByteBufferUtil.readShortLength(bb);
if (bb.remaining() < length)
throw new MarshalException("Not enough bytes to read value of component " + i);
ByteBuffer value = ByteBufferUtil.readBytes(bb, length);
comparator.validateCollectionMember(value, previous);
if (bb.remaining() == 0)
throw new MarshalException("Not enough bytes to read the end-of-component byte of component" + i);
byte b = bb.get();
if (b != 0 && bb.remaining() != 0)
throw new MarshalException("Invalid bytes remaining after an end-of-component at component" + i);
previous = value;
++i;
}
}
use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class HintVerbHandler method doVerb.
public void doVerb(MessageIn<HintMessage> message, int id) {
UUID hostId = message.payload.hostId;
Hint hint = message.payload.hint;
InetAddress address = StorageService.instance.getEndpointForHostId(hostId);
// is schema agreement between the sender and the receiver.
if (hint == null) {
logger.trace("Failed to decode and apply a hint for {}: {} - table with id {} is unknown", address, hostId, message.payload.unknownTableID);
reply(id, message.from);
return;
}
// We must perform validation before applying the hint, and there is no other place to do it other than here.
try {
hint.mutation.getPartitionUpdates().forEach(PartitionUpdate::validate);
} catch (MarshalException e) {
logger.warn("Failed to validate a hint for {}: {} - skipped", address, hostId);
reply(id, message.from);
return;
}
if (!hostId.equals(StorageService.instance.getLocalHostUUID())) {
// the node is not the final destination of the hint (must have gotten it from a decommissioning node),
// so just store it locally, to be delivered later.
HintsService.instance.write(hostId, hint);
reply(id, message.from);
} else if (!StorageProxy.instance.appliesLocally(hint.mutation)) {
// the topology has changed, and we are no longer a replica of the mutation - since we don't know which node(s)
// it has been handed over to, re-address the hint to all replicas; see CASSANDRA-5902.
HintsService.instance.writeForAllReplicas(hint);
reply(id, message.from);
} else {
// the common path - the node is both the destination and a valid replica for the hint.
hint.applyFuture().thenAccept(o -> reply(id, message.from)).exceptionally(e -> {
logger.debug("Failed to apply hint", e);
return null;
});
}
}
use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class HintVerbHandler method doVerb.
public void doVerb(Message<HintMessage> message) {
UUID hostId = message.payload.hostId;
Hint hint = message.payload.hint;
InetAddressAndPort address = StorageService.instance.getEndpointForHostId(hostId);
// is schema agreement between the sender and the receiver.
if (hint == null) {
logger.trace("Failed to decode and apply a hint for {}: {} - table with id {} is unknown", address, hostId, message.payload.unknownTableID);
respond(message);
return;
}
// We must perform validation before applying the hint, and there is no other place to do it other than here.
try {
hint.mutation.getPartitionUpdates().forEach(PartitionUpdate::validate);
} catch (MarshalException e) {
logger.warn("Failed to validate a hint for {}: {} - skipped", address, hostId);
respond(message);
return;
}
if (!hostId.equals(StorageService.instance.getLocalHostUUID())) {
// the node is not the final destination of the hint (must have gotten it from a decommissioning node),
// so just store it locally, to be delivered later.
HintsService.instance.write(hostId, hint);
respond(message);
} else if (!StorageProxy.instance.appliesLocally(hint.mutation)) {
// the topology has changed, and we are no longer a replica of the mutation - since we don't know which node(s)
// it has been handed over to, re-address the hint to all replicas; see CASSANDRA-5902.
HintsService.instance.writeForAllReplicas(hint);
respond(message);
} else {
// the common path - the node is both the destination and a valid replica for the hint.
hint.applyFuture().addCallback(o -> respond(message), e -> logger.debug("Failed to apply hint", e));
}
}
use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class UnfilteredValidation method handleInvalid.
public static void handleInvalid(TableMetadata metadata, DecoratedKey key, SSTableReader sstable, String invalidContent) {
Config.CorruptedTombstoneStrategy strat = DatabaseDescriptor.getCorruptedTombstoneStrategy();
String keyString;
try {
keyString = metadata.partitionKeyType.getString(key.getKey());
} catch (Throwable t) {
keyString = "[corrupt token=" + key.getToken() + "]";
}
if (strat == Config.CorruptedTombstoneStrategy.exception) {
String msg = String.format("Key %s in %s.%s is invalid in %s: %s", keyString, metadata.keyspace, metadata.name, sstable, invalidContent);
// we mark suspect to make sure this sstable is not included in future compactions - it would just keep
// throwing exceptions
sstable.markSuspect();
throw new CorruptSSTableException(new MarshalException(msg), sstable.getFilename());
} else if (strat == Config.CorruptedTombstoneStrategy.warn) {
String msgTemplate = String.format("Key {} in %s.%s is invalid in %s: {}", metadata.keyspace, metadata.name, sstable);
nospam1m.warn(msgTemplate, keyString, invalidContent);
}
}
use of org.apache.cassandra.serializers.MarshalException in project cassandra by apache.
the class SelectStatement method getLimit.
private int getLimit(Term limit, QueryOptions options) {
int userLimit = DataLimits.NO_LIMIT;
if (limit != null) {
ByteBuffer b = checkNotNull(limit.bindAndGet(options), "Invalid null value of limit");
// treat UNSET limit value as 'unlimited'
if (b != UNSET_BYTE_BUFFER) {
try {
Int32Type.instance.validate(b);
userLimit = Int32Type.instance.compose(b);
checkTrue(userLimit > 0, "LIMIT must be strictly positive");
} catch (MarshalException e) {
throw new InvalidRequestException("Invalid limit value");
}
}
}
return userLimit;
}
Aggregations