Search in sources :

Example 6 with BufferedDataOutputStreamPlus

use of org.apache.cassandra.io.util.BufferedDataOutputStreamPlus in project cassandra by apache.

the class VIntCodingBench method getBufferedDataOutput.

private DataOutputPlus getBufferedDataOutput(Blackhole bh, ByteBuffer buffer) {
    WritableByteChannel wbc = new WritableByteChannel() {

        @Override
        public boolean isOpen() {
            return true;
        }

        @Override
        public void close() throws IOException {
        }

        @Override
        public int write(ByteBuffer src) throws IOException {
            bh.consume(src);
            int remaining = src.remaining();
            src.position(src.limit());
            return remaining;
        }
    };
    return new BufferedDataOutputStreamPlus(wbc, buffer);
}
Also used : WritableByteChannel(java.nio.channels.WritableByteChannel) BufferedDataOutputStreamPlus(org.apache.cassandra.io.util.BufferedDataOutputStreamPlus) ByteBuffer(java.nio.ByteBuffer)

Example 7 with BufferedDataOutputStreamPlus

use of org.apache.cassandra.io.util.BufferedDataOutputStreamPlus in project cassandra by apache.

the class CommitLog method add.

/**
 * Add a Mutation to the commit log. If CDC is enabled, this can fail.
 *
 * @param mutation the Mutation to add to the log
 * @throws CDCWriteException
 */
public CommitLogPosition add(Mutation mutation) throws CDCWriteException {
    assert mutation != null;
    mutation.validateSize(MessagingService.current_version, ENTRY_OVERHEAD_SIZE);
    try (DataOutputBuffer dob = DataOutputBuffer.scratchBuffer.get()) {
        Mutation.serializer.serialize(mutation, dob, MessagingService.current_version);
        int size = dob.getLength();
        int totalSize = size + ENTRY_OVERHEAD_SIZE;
        Allocation alloc = segmentManager.allocate(mutation, totalSize);
        CRC32 checksum = new CRC32();
        final ByteBuffer buffer = alloc.getBuffer();
        try (BufferedDataOutputStreamPlus dos = new DataOutputBufferFixed(buffer)) {
            // checksummed length
            dos.writeInt(size);
            updateChecksumInt(checksum, size);
            buffer.putInt((int) checksum.getValue());
            // checksummed mutation
            dos.write(dob.getData(), 0, size);
            updateChecksum(checksum, buffer, buffer.position() - size, size);
            buffer.putInt((int) checksum.getValue());
        } catch (IOException e) {
            throw new FSWriteError(e, alloc.getSegment().getPath());
        } finally {
            alloc.markWritten();
        }
        executor.finishWriteFor(alloc);
        return alloc.getCommitLogPosition();
    } catch (IOException e) {
        throw new FSWriteError(e, segmentManager.allocatingFrom().getPath());
    }
}
Also used : Allocation(org.apache.cassandra.db.commitlog.CommitLogSegment.Allocation) CRC32(java.util.zip.CRC32) FSWriteError(org.apache.cassandra.io.FSWriteError) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) IOException(java.io.IOException) BufferedDataOutputStreamPlus(org.apache.cassandra.io.util.BufferedDataOutputStreamPlus) ByteBuffer(java.nio.ByteBuffer) DataOutputBufferFixed(org.apache.cassandra.io.util.DataOutputBufferFixed)

Aggregations

BufferedDataOutputStreamPlus (org.apache.cassandra.io.util.BufferedDataOutputStreamPlus)7 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 WritableByteChannel (java.nio.channels.WritableByteChannel)3 WrappedDataOutputStreamPlus (org.apache.cassandra.io.util.WrappedDataOutputStreamPlus)2 ByteBuf (io.netty.buffer.ByteBuf)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 SocketException (java.net.SocketException)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 CRC32 (java.util.zip.CRC32)1 Checksum (java.util.zip.Checksum)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1