Search in sources :

Example 1 with MarshalException

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;
    }
}
Also used : MarshalException(org.apache.cassandra.serializers.MarshalException) ByteBuffer(java.nio.ByteBuffer)

Example 2 with MarshalException

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;
        });
    }
}
Also used : InetAddress(java.net.InetAddress) MessagingService(org.apache.cassandra.net.MessagingService) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Logger(org.slf4j.Logger) StorageProxy(org.apache.cassandra.service.StorageProxy) LoggerFactory(org.slf4j.LoggerFactory) StorageService(org.apache.cassandra.service.StorageService) MessageIn(org.apache.cassandra.net.MessageIn) UUID(java.util.UUID) IVerbHandler(org.apache.cassandra.net.IVerbHandler) MarshalException(org.apache.cassandra.serializers.MarshalException) MarshalException(org.apache.cassandra.serializers.MarshalException) UUID(java.util.UUID) InetAddress(java.net.InetAddress) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 3 with MarshalException

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));
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) MessagingService(org.apache.cassandra.net.MessagingService) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Logger(org.slf4j.Logger) StorageProxy(org.apache.cassandra.service.StorageProxy) LoggerFactory(org.slf4j.LoggerFactory) StorageService(org.apache.cassandra.service.StorageService) Message(org.apache.cassandra.net.Message) UUID(java.util.UUID) IVerbHandler(org.apache.cassandra.net.IVerbHandler) MarshalException(org.apache.cassandra.serializers.MarshalException) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) MarshalException(org.apache.cassandra.serializers.MarshalException) UUID(java.util.UUID) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 4 with MarshalException

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);
    }
}
Also used : MarshalException(org.apache.cassandra.serializers.MarshalException) Config(org.apache.cassandra.config.Config) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException)

Example 5 with MarshalException

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;
}
Also used : MarshalException(org.apache.cassandra.serializers.MarshalException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

MarshalException (org.apache.cassandra.serializers.MarshalException)24 ByteBuffer (java.nio.ByteBuffer)10 CharacterCodingException (java.nio.charset.CharacterCodingException)3 Term (org.apache.cassandra.cql3.Term)3 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2 SyntaxException (org.apache.cassandra.exceptions.SyntaxException)2 IVerbHandler (org.apache.cassandra.net.IVerbHandler)2 MessagingService (org.apache.cassandra.net.MessagingService)2 StorageProxy (org.apache.cassandra.service.StorageProxy)2 StorageService (org.apache.cassandra.service.StorageService)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Objects (com.google.common.base.Objects)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.concat (com.google.common.collect.Iterables.concat)1 Iterables.transform (com.google.common.collect.Iterables.transform)1