Java Code Examples for org.apache.cassandra.utils.FBUtilities#MAX_UNSIGNED_SHORT

The following examples show how to use org.apache.cassandra.utils.FBUtilities#MAX_UNSIGNED_SHORT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Sets.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public Value bind(QueryOptions options) throws InvalidRequestException
{
    SortedSet<ByteBuffer> buffers = new TreeSet<>(comparator);
    for (Term t : elements)
    {
        ByteBuffer bytes = t.bindAndGet(options);

        if (bytes == null)
            throw new InvalidRequestException("null is not supported inside collections");

        // We don't support value > 64K because the serialization format encode the length as an unsigned short.
        if (bytes.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
            throw new InvalidRequestException(String.format("Set value is too long. Set values are limited to %d bytes but %d bytes value provided",
                                                            FBUtilities.MAX_UNSIGNED_SHORT,
                                                            bytes.remaining()));

        buffers.add(bytes);
    }
    return new Value(buffers);
}
 
Example 2
Source File: Lists.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public Value bind(QueryOptions options) throws InvalidRequestException
{
    List<ByteBuffer> buffers = new ArrayList<ByteBuffer>(elements.size());
    for (Term t : elements)
    {
        ByteBuffer bytes = t.bindAndGet(options);

        if (bytes == null)
            throw new InvalidRequestException("null is not supported inside collections");

        // We don't support value > 64K because the serialization format encode the length as an unsigned short.
        if (bytes.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
            throw new InvalidRequestException(String.format("List value is too long. List values are limited to %d bytes but %d bytes value provided",
                                                            FBUtilities.MAX_UNSIGNED_SHORT,
                                                            bytes.remaining()));

        buffers.add(bytes);
    }
    return new Value(buffers);
}
 
Example 3
Source File: Maps.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public Value bind(QueryOptions options) throws InvalidRequestException
{
    Map<ByteBuffer, ByteBuffer> buffers = new TreeMap<ByteBuffer, ByteBuffer>(comparator);
    for (Map.Entry<Term, Term> entry : elements.entrySet())
    {
        // We don't support values > 64K because the serialization format encode the length as an unsigned short.
        ByteBuffer keyBytes = entry.getKey().bindAndGet(options);
        if (keyBytes == null)
            throw new InvalidRequestException("null is not supported inside collections");
        if (keyBytes.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
            throw new InvalidRequestException(String.format("Map key is too long. Map keys are limited to %d bytes but %d bytes keys provided",
                                                            FBUtilities.MAX_UNSIGNED_SHORT,
                                                            keyBytes.remaining()));

        ByteBuffer valueBytes = entry.getValue().bindAndGet(options);
        if (valueBytes == null)
            throw new InvalidRequestException("null is not supported inside collections");
        if (valueBytes.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
            throw new InvalidRequestException(String.format("Map value is too long. Map values are limited to %d bytes but %d bytes value provided",
                                                            FBUtilities.MAX_UNSIGNED_SHORT,
                                                            valueBytes.remaining()));

        buffers.put(keyBytes, valueBytes);
    }
    return new Value(buffers);
}
 
Example 4
Source File: CacheService.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public Future<Pair<KeyCacheKey, RowIndexEntry>> deserialize(DataInputStream input, ColumnFamilyStore cfs) throws IOException
{
    int keyLength = input.readInt();
    if (keyLength > FBUtilities.MAX_UNSIGNED_SHORT)
    {
        throw new IOException(String.format("Corrupted key cache. Key length of %d is longer than maximum of %d",
                                            keyLength, FBUtilities.MAX_UNSIGNED_SHORT));
    }
    ByteBuffer key = ByteBufferUtil.read(input, keyLength);
    int generation = input.readInt();
    SSTableReader reader = findDesc(generation, cfs.getSSTables());
    input.readBoolean(); // backwards compatibility for "promoted indexes" boolean
    if (reader == null)
    {
        RowIndexEntry.Serializer.skipPromotedIndex(input);
        return null;
    }
    RowIndexEntry entry = reader.metadata.comparator.rowIndexEntrySerializer().deserialize(input, reader.descriptor.version);
    return Futures.immediateFuture(Pair.create(new KeyCacheKey(cfs.metadata.cfId, reader.descriptor, key), entry));
}
 
Example 5
Source File: ThriftValidation.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static void validateKey(CFMetaData metadata, ByteBuffer key) throws org.apache.cassandra.exceptions.InvalidRequestException
{
    if (key == null || key.remaining() == 0)
    {
        throw new org.apache.cassandra.exceptions.InvalidRequestException("Key may not be empty");
    }

    // check that key can be handled by FBUtilities.writeShortByteArray
    if (key.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
    {
        throw new org.apache.cassandra.exceptions.InvalidRequestException("Key length of " + key.remaining() +
                                                                          " is longer than maximum of " +
                                                                          FBUtilities.MAX_UNSIGNED_SHORT);
    }

    try
    {
        metadata.getKeyValidator().validate(key);
    }
    catch (MarshalException e)
    {
        throw new org.apache.cassandra.exceptions.InvalidRequestException(e.getMessage());
    }
}
 
Example 6
Source File: SSTableWriter.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public void append(DecoratedKey decoratedKey, ColumnFamily cf)
{
    if (decoratedKey.getKey().remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
    {
        logger.error("Key size {} exceeds maximum of {}, skipping row",
                     decoratedKey.getKey().remaining(),
                     FBUtilities.MAX_UNSIGNED_SHORT);
        return;
    }

    long startPosition = beforeAppend(decoratedKey);
    long endPosition;
    try
    {
        RowIndexEntry entry = rawAppend(cf, startPosition, decoratedKey, dataFile.stream);
        endPosition = dataFile.getFilePointer();
        afterAppend(decoratedKey, endPosition, entry);
    }
    catch (IOException e)
    {
        throw new FSWriteError(e, dataFile.getPath());
    }
    sstableMetadataCollector.update(endPosition - startPosition, cf.getColumnStats());
}
 
Example 7
Source File: QueryProcessor.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static void validateKey(ByteBuffer key) throws InvalidRequestException
{
    if (key == null || key.remaining() == 0)
    {
        throw new InvalidRequestException("Key may not be empty");
    }

    // check that key can be handled by FBUtilities.writeShortByteArray
    if (key.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
    {
        throw new InvalidRequestException("Key length of " + key.remaining() +
                                          " is longer than maximum of " + FBUtilities.MAX_UNSIGNED_SHORT);
    }
}
 
Example 8
Source File: QueryProcessor.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static void validateKey(ByteBuffer key) throws InvalidRequestException
{
    if (key == null || key.remaining() == 0)
    {
        throw new InvalidRequestException("Key may not be empty");
    }

    // check that key can be handled by FBUtilities.writeShortByteArray
    if (key.remaining() > FBUtilities.MAX_UNSIGNED_SHORT)
    {
        throw new InvalidRequestException("Key length of " + key.remaining() +
                                          " is longer than maximum of " + FBUtilities.MAX_UNSIGNED_SHORT);
    }
}
 
Example 9
Source File: PerColumnSecondaryIndex.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public boolean validate(Cell cell)
{
    return cell.value().remaining() < FBUtilities.MAX_UNSIGNED_SHORT;
}