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);
}
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());
}
}
Aggregations