Java Code Examples for org.apache.cassandra.transport.Frame

Following code examples demonstrate how to use org.apache.cassandra.transport.Frame from cassandra. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.apache.cassandra.transport.Frame and various code implementation of this class.
Example 1
Project : cassandra Source File : ModificationStatement.java View Source Code on GitHub

    }

    public ResultMessage executeInternal(QueryState queryState, QueryOptions options) throws RequestValidationException, RequestExecutionException
    {
        if (hasConditions())
            throw new UnsupportedOperationException();

        for (IMutation mutation : getMutations(options, true, queryState.getTimestamp(), queryState.getSourceFrame()))
        {
            assert mutation instanceof Mutation;

            ((Mutation) mutation).apply();
        }
        return null;
    }
			
Example 2
Project : cassandra Source File : ModificationStatement.java View Source Code on GitHub

    }

    private ResultMessage executeWithoutCondition(QueryState queryState, QueryOptions options)
    throws RequestExecutionException, RequestValidationException
    {
        ConsistencyLevel cl = options.getConsistency();
        if (isCounter())
            cl.validateCounterForWrite(cfm);
        else
            cl.validateForWrite(cfm.ksName);

        Collection<? extends IMutation> mutations = getMutations(options, false, options.getTimestamp(queryState), queryState.getSourceFrame());
        if (!mutations.isEmpty())
            StorageProxy.mutateWithTriggers(mutations, cl, false);

        return null;
    }
			
Example 3
Project : cassandra Source File : ModificationStatement.java View Source Code on GitHub

    
    private Collection<? extends IMutation> getMutations(QueryOptions options, boolean local, long now, Frame sourceFrame)
    throws RequestExecutionException, RequestValidationException
    {
        List<ByteBuffer> keys = buildPartitionKeyNames(options);
        Composite clusteringPrefix = createClusteringPrefix(options);

        UpdateParameters params = makeUpdateParameters(keys, clusteringPrefix, options, local, now);

        Collection<IMutation> mutations = new ArrayList<IMutation>(keys.size());
        for (ByteBuffer key: keys)
        {
            ThriftValidation.validateKey(cfm, key);
            ColumnFamily cf = ArrayBackedSortedColumns.factory.create(cfm);
            addUpdateForKey(cf, key, clusteringPrefix, params);
            Mutation mut = new Mutation(cfm.ksName, key, cf);
            mut.setSourceFrame(sourceFrame);

            mutations.add(isCounter() ? new CounterMutation(mut, options.getConsistency()) : mut);
        }
        return mutations;
    }
			
Example 4
Project : cassandra Source File : ContinuousPagingService.java View Source Code on GitHub

         static <M extends Message.Response> Frame makeFrame(M response, Message.Codec codec, ProtocolVersion version, int streamId) {
            response.setStreamId(streamId);
            int messageSize = codec.encodedSize(response, version);
            Frame frame = Message.ProtocolEncoder.makeFrame(response, messageSize, version);
            codec.encode(response, frame.body, version);
            return frame;
         }
			
Example 5
Project : cassandra Source File : Mutation.java View Source Code on GitHub

    }

    public Mutation copy()
    {
        Mutation copy = new Mutation(keyspaceName, key, new HashMap<>(modifications));
        copy.setSourceFrame(getSourceFrame());

        return copy;
    }
			
Example 6
Project : cassandra Source File : Mutation.java View Source Code on GitHub

    
    public void apply()
    {
        assert sourceFrame == null || sourceFrame.body.refCnt() > 0;

        Keyspace ks = Keyspace.open(keyspaceName);
        ks.apply(this, ks.metadata.durableWrites);
    }
			
Example 7
Project : cassandra Source File : BatchStatement.java View Source Code on GitHub

    }

    private Collection<? extends IMutation> getMutations(BatchQueryOptions options, boolean local, long now, Frame sourceFrame)
    throws RequestExecutionException, RequestValidationException
    {
        Map<String, Map<ByteBuffer, IMutation>> mutations = new HashMap<>();
        for (int i = 0; i < statements.size(); i++)
        {
            ModificationStatement statement = statements.get(i);
            QueryOptions statementOptions = options.forStatement(i);
            long timestamp = attrs.getTimestamp(now, statementOptions);
            addStatementMutations(statement, statementOptions, local, timestamp, mutations, sourceFrame);
        }
        return unzipMutations(mutations);
    }
			
Example 8
Project : cassandra Source File : BatchStatement.java View Source Code on GitHub

    }

    public ResultMessage executeInternal(QueryState queryState, QueryOptions options) throws RequestValidationException, RequestExecutionException
    {
        assert !hasConditions;
        for (IMutation mutation : getMutations(BatchQueryOptions.withoutPerStatementVariables(options), true, queryState.getTimestamp(), queryState.getSourceFrame()))
        {
            assert mutation instanceof Mutation;
            ((Mutation) mutation).apply();
        }
        return null;
    }
			
Example 9
Project : cassandra Source File : BatchStatement.java View Source Code on GitHub

    }

    private ResultMessage execute(QueryState queryState, BatchQueryOptions options, boolean local, long now)
    throws RequestExecutionException, RequestValidationException
    {
        if (options.getConsistency() == null)
            throw new InvalidRequestException("Invalid empty consistency level");
        if (options.getSerialConsistency() == null)
            throw new InvalidRequestException("Invalid empty serial consistency level");

        if (hasConditions)
            return executeWithConditions(options, now);

        executeWithoutConditions(getMutations(options, local, now, queryState.getSourceFrame()), options.getConsistency());
        return new ResultMessage.Void();
    }
			
Example 10
Project : cassandra Source File : BatchStatement.java View Source Code on GitHub

    }

    private void addStatementMutations(ModificationStatement statement,
                                       QueryOptions options,
                                       boolean local,
                                       long now,
                                       Map<String, Map<ByteBuffer, IMutation>> mutations,
                                       Frame sourceFrame)
    throws RequestExecutionException, RequestValidationException
    {
        String ksName = statement.keyspace();
        Map<ByteBuffer, IMutation> ksMap = mutations.get(ksName);
        if (ksMap == null)
        {
            ksMap = new HashMap<>();
            mutations.put(ksName, ksMap);
        }

        List<ByteBuffer> keys = statement.buildPartitionKeyNames(options);
        Composite clusteringPrefix = statement.createClusteringPrefix(options);
        UpdateParameters params = statement.makeUpdateParameters(keys, clusteringPrefix, options, local, now);

        for (ByteBuffer key : keys)
        {
            IMutation mutation = ksMap.get(key);
            Mutation mut;
            if (mutation == null)
            {
                mut = new Mutation(ksName, key);
                mut.setSourceFrame(sourceFrame);
                mutation = statement.cfm.isCounter() ? new CounterMutation(mut, options.getConsistency()) : mut;
                ksMap.put(key, mutation);
            }
            else
            {
                mut = statement.cfm.isCounter() ? ((CounterMutation)mutation).getMutation() : (Mutation)mutation;
            }

            statement.addUpdateForKey(mut.addOrGet(statement.cfm), key, clusteringPrefix, params);
        }
    }
			
Example 11
Project : cassandra Source File : ContinuousPageWriter.java View Source Code on GitHub

      private void processPage(Frame frame) {
         if(this.aborted()) {
            frame.release();
         } else {
            this.channel.write(frame);
            this.channel.flush();
         }

      }
			
Example 12
Project : cassandra Source File : ContinuousPageWriter.java View Source Code on GitHub

   void sendPage(Frame frame, boolean hasMorePages) {
      if(this.writer.canceled) {
         logger.trace("Discarding page because writer was cancelled");
         frame.release();
      } else {
         assert !this.writer.completed() : "Received unexpected page when writer was already completed";

         try {
            this.pages.add(frame);
         } catch (Throwable var4) {
            logger.warn("Failed to add continuous paging result to queue: {}", var4.getMessage());
            frame.release();
            throw var4;
         }

         if(!hasMorePages) {
            this.writer.complete();
         } else {
            this.writer.schedule(0L);
         }

      }
   }
			
Example 13
Project : cassandra Source File : ChecksummingTransformer.java View Source Code on GitHub

    }

    public ByteBuf transformInbound(ByteBuf inputBuf, EnumSet<Frame.Header.Flag> flags)
    {
        int numChunks = readUnsignedShort(inputBuf);

        int currentPosition = 0;
        int decompressedLength;
        int lengthsChecksum;

        byte[] buf = null;
        byte[] retBuf = new byte[inputBuf.readableBytes()];
        byte[] chunkLengths = new byte[8];
        for (int i = 0; i < numChunks; i++)
        {
            int compressedLength = inputBuf.readInt();
            decompressedLength = compressedLength >= 0 ? inputBuf.readInt() : Math.abs(compressedLength);

            putInt(compressedLength, chunkLengths, 0);
            putInt(decompressedLength, chunkLengths, 4);
            lengthsChecksum = inputBuf.readInt();
            int calculatedLengthsChecksum = (int) checksum.of(chunkLengths, 0, chunkLengths.length);
            if (lengthsChecksum != calculatedLengthsChecksum)
            {
                throw new ProtocolException(String.format("Checksum invalid on chunk bytes lengths. Deserialized compressed " +
                                                          "length: %d decompressed length: %d. %d != %d", compressedLength,
                                                          decompressedLength, lengthsChecksum, calculatedLengthsChecksum));
            }

            if (currentPosition + decompressedLength > retBuf.length)
            {
                byte[] resizedBuf = new byte[retBuf.length + decompressedLength * 3 / 2];
                System.arraycopy(retBuf, 0, resizedBuf, 0, retBuf.length);
                retBuf = resizedBuf;
            }

            int toRead = Math.abs(compressedLength);
            if (buf == null || buf.length < toRead)
                buf = new byte[toRead];

            inputBuf.readBytes(buf, 0, toRead);

            byte[] decompressedChunk = maybeDecompress(buf, compressedLength, decompressedLength, flags);

            System.arraycopy(decompressedChunk, 0, retBuf, currentPosition, decompressedLength);
            currentPosition += decompressedLength;

            int expectedDecompressedChecksum = inputBuf.readInt();
            int calculatedDecompressedChecksum = (int) checksum.of(decompressedChunk, 0, decompressedLength);
            if (expectedDecompressedChecksum != calculatedDecompressedChecksum)
            {
                throw new ProtocolException("Decompressed checksum for chunk does not match expected checksum");
            }
        }

        ByteBuf ret = Unpooled.wrappedBuffer(retBuf, 0, currentPosition);
        ret.writerIndex(currentPosition);
        return ret;
    }