/** * Writes all operations in the given iterable to the given output stream including the size of the array * use {@link #readOperations(StreamInput, String)} to read it back. */ public static void writeOperations(StreamOutput outStream, List<Operation> toWrite) throws IOException { final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(BigArrays.NON_RECYCLING_INSTANCE); try { outStream.writeInt(toWrite.size()); final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out); for (Operation op : toWrite) { out.reset(); final long start = out.position(); out.skip(Integer.BYTES); writeOperationNoSize(checksumStreamOutput, op); long end = out.position(); int operationSize = (int) (out.position() - Integer.BYTES - start); out.seek(start); out.writeInt(operationSize); out.seek(end); ReleasablePagedBytesReference bytes = out.bytes(); bytes.writeTo(outStream); } } finally { Releasables.close(out); } }
@Override public BytesStreamOutput newBytesOutput() { return new ReleasableBytesStreamOutput(transport.bigArrays); }
boolean addedReleaseListener = false; try { bStream = new ReleasableBytesStreamOutput(transport.bigArrays); bStream.skip(NettyHeader.HEADER_SIZE); StreamOutput stream = bStream; if (options.compress()) { stream.close(); ReleasablePagedBytesReference bytes = bStream.bytes(); ChannelBuffer buffer = bytes.toChannelBuffer(); NettyHeader.writeHeader(buffer, requestId, status, version); } finally { if (!addedReleaseListener && bStream != null) { Releasables.close(bStream.bytes());
ReleasableBytesStreamOutput crazyStream = new ReleasableBytesStreamOutput(length, bigarrays); final int offset = randomIntBetween(0, crazyLength - length); for (int j = 0; j < offset; j++) { crazyStream.writeByte((byte) random().nextInt(1 << 8)); for (int j = crazyStream.size(); j < crazyLength; j++) { crazyStream.writeByte((byte) random().nextInt(1 << 8)); PagedBytesReference crazyReference = crazyStream.bytes();
/** * Serializes the given message into a bytes representation */ private BytesReference buildMessage(long requestId, byte status, Version nodeVersion, TransportMessage message, StreamOutput stream, ReleasableBytesStreamOutput writtenBytes) throws IOException { final BytesReference zeroCopyBuffer; if (message instanceof BytesTransportRequest) { // what a shitty optimization - we should use a direct send method instead BytesTransportRequest bRequest = (BytesTransportRequest) message; assert nodeVersion.equals(bRequest.version()); bRequest.writeThin(stream); zeroCopyBuffer = bRequest.bytes; } else { message.writeTo(stream); zeroCopyBuffer = BytesArray.EMPTY; } // we have to close the stream here - flush is not enough since we might be compressing the content // and if we do that the close method will write some marker bytes (EOS marker) and otherwise // we barf on the decompressing end when we read past EOF on purpose in the #validateRequest method. // this might be a problem in deflate after all but it's important to close it for now. stream.close(); final BytesReference messageBody = writtenBytes.bytes(); final BytesReference header = buildHeader(requestId, status, stream.getVersion(), messageBody.length() + zeroCopyBuffer.length()); return new CompositeBytesReference(header, messageBody, zeroCopyBuffer); }
@Override protected BytesStreamOutput newBytesOutput() { return new ReleasableBytesStreamOutput(transport.bigArrays); }
status = TransportStatus.setRequest(status); ReleasableBytesStreamOutput bStream = new ReleasableBytesStreamOutput(bigArrays); boolean addedReleaseListener = false; try { bStream.skip(NettyHeader.HEADER_SIZE); StreamOutput stream = bStream; bRequest.writeThin(stream); stream.close(); bytes = bStream.bytes(); ChannelBuffer headerBuffer = bytes.toChannelBuffer(); ChannelBuffer contentBuffer = bRequest.bytes().toChannelBuffer(); request.writeTo(stream); stream.close(); bytes = bStream.bytes(); buffer = bytes.toChannelBuffer(); } finally { if (!addedReleaseListener) { Releasables.close(bStream.bytes());
final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays); try { final long start = out.position(); out.skip(Integer.BYTES); writeOperationNoSize(new BufferedChecksumStreamOutput(out), operation); final long end = out.position(); final int operationSize = (int) (end - Integer.BYTES - start); out.seek(start); out.writeInt(operationSize); out.seek(end); final ReleasablePagedBytesReference bytes = out.bytes(); try (ReleasableLock ignored = readLock.acquire()) { ensureOpen();
@Override protected BytesStreamOutput newBytesOutput() { return new ReleasableBytesStreamOutput(transport.bigArrays); }
/** * Writes all operations in the given iterable to the given output stream including the size of the array * use {@link #readOperations(StreamInput)} to read it back. */ public static void writeOperations(StreamOutput outStream, List<Operation> toWrite) throws IOException { final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(BigArrays.NON_RECYCLING_INSTANCE); try { outStream.writeInt(toWrite.size()); final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out); for (Operation op : toWrite) { out.reset(); final long start = out.position(); out.skip(RamUsageEstimator.NUM_BYTES_INT); writeOperationNoSize(checksumStreamOutput, op); long end = out.position(); int operationSize = (int) (out.position() - RamUsageEstimator.NUM_BYTES_INT - start); out.seek(start); out.writeInt(operationSize); out.seek(end); ReleasablePagedBytesReference bytes = out.bytes(); bytes.writeTo(outStream); } } finally { Releasables.close(out.bytes()); } }
@Override protected BytesStreamOutput newBytesOutput() { return new ReleasableBytesStreamOutput(transport.bigArrays); }
/** * Writes all operations in the given iterable to the given output stream including the size of the array * use {@link #readOperations(StreamInput)} to read it back. */ public static void writeOperations(StreamOutput outStream, List<Operation> toWrite) throws IOException { final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(BigArrays.NON_RECYCLING_INSTANCE); try { outStream.writeInt(toWrite.size()); final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out); for (Operation op : toWrite) { out.reset(); final long start = out.position(); out.skip(Integer.BYTES); writeOperationNoSize(checksumStreamOutput, op); long end = out.position(); int operationSize = (int) (out.position() - Integer.BYTES - start); out.seek(start); out.writeInt(operationSize); out.seek(end); ReleasablePagedBytesReference bytes = out.bytes(); bytes.writeTo(outStream); } } finally { Releasables.close(out); } }
@Override public org.elasticsearch.common.io.stream.BytesStreamOutput newBytesOutput() { return new org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput(transport.bigArrays); }
/** * Writes all operations in the given iterable to the given output stream including the size of the array * use {@link #readOperations(StreamInput, String)} to read it back. */ public static void writeOperations(StreamOutput outStream, List<Operation> toWrite) throws IOException { final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(BigArrays.NON_RECYCLING_INSTANCE); try { outStream.writeInt(toWrite.size()); final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out); for (Operation op : toWrite) { out.reset(); final long start = out.position(); out.skip(Integer.BYTES); writeOperationNoSize(checksumStreamOutput, op); long end = out.position(); int operationSize = (int) (out.position() - Integer.BYTES - start); out.seek(start); out.writeInt(operationSize); out.seek(end); ReleasablePagedBytesReference bytes = out.bytes(); bytes.writeTo(outStream); } } finally { Releasables.close(out); } }
@Override protected BytesStreamOutput newBytesOutput() { return new ReleasableBytesStreamOutput(transport.bigArrays); }
final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays); try { final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out); final long start = out.position(); out.skip(RamUsageEstimator.NUM_BYTES_INT); writeOperationNoSize(checksumStreamOutput, operation); final long end = out.position(); final int operationSize = (int) (end - RamUsageEstimator.NUM_BYTES_INT - start); out.seek(start); out.writeInt(operationSize); out.seek(end); final ReleasablePagedBytesReference bytes = out.bytes(); try (ReleasableLock lock = readLock.acquire()) { ensureOpen(); throw new TranslogException(shardId, "Failed to write operation [" + operation + "]", e); } finally { Releasables.close(out.bytes());
@Override public BytesStreamOutput newBytesOutput() { return new ReleasableBytesStreamOutput(transport.bigArrays); }
final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays); try { final long start = out.position(); out.skip(Integer.BYTES); writeOperationNoSize(new BufferedChecksumStreamOutput(out), operation); final long end = out.position(); final int operationSize = (int) (end - Integer.BYTES - start); out.seek(start); out.writeInt(operationSize); out.seek(end); final ReleasablePagedBytesReference bytes = out.bytes(); try (ReleasableLock ignored = readLock.acquire()) { ensureOpen();
ReleasableBytesStreamOutput bStream = new ReleasableBytesStreamOutput(bigArrays); CompressibleBytesOutputStream stream = new CompressibleBytesOutputStream(bStream, compressMessage); boolean addedReleaseListener = false;
final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays); try { final long start = out.position(); out.skip(Integer.BYTES); writeOperationNoSize(new BufferedChecksumStreamOutput(out), operation); final long end = out.position(); final int operationSize = (int) (end - Integer.BYTES - start); out.seek(start); out.writeInt(operationSize); out.seek(end); final ReleasablePagedBytesReference bytes = out.bytes(); try (ReleasableLock ignored = readLock.acquire()) { ensureOpen();