@Override public boolean hasSerializedData() { return serializationBuffer.length() > 0 || subSerializationBuffer != null || subSerializer.hasSerializedData(); } }
public void flush() throws IOException { if (recordSerializer.hasSerializedData()) { flushInternalSerializer(); } checkState(!recordSerializer.hasSerializedData(), "All data should be written at once"); tryFinishCurrentBufferBuilder(); }
@Override public void finishWriting() throws IOException { if (isWritingFinished) { return; } if (recordSerializer.hasSerializedData()) { flushInternalSerializer(); } checkState(!recordSerializer.hasSerializedData(), "All data should be written at once"); tryFinishCurrentBufferBuilder(); streamFileWriter.close(); isWritingFinished = true; }
private void copyToTargetFile(int partition) throws IOException, InterruptedException { recordSerializer.reset(); BufferBuilder bufferBuilder = getCurrentBufferBuilder(partition); RecordSerializer.SerializationResult result = recordSerializer.copyToBufferBuilder(bufferBuilder); while (result.isFullBuffer()) { tryFinishCurrentBufferBuilder(partition); if (result.isFullRecord()) { break; } bufferBuilder = getCurrentBufferBuilder(partition); result = recordSerializer.copyToBufferBuilder(bufferBuilder); } checkState(!recordSerializer.hasSerializedData(), "All data should be written at once"); }
result = serializer.copyToBufferBuilder(bufferBuilder); checkState(!serializer.hasSerializedData(), "All data should be written at once");
result = serializer.copyToBufferBuilder(bufferBuilder); checkState(!serializer.hasSerializedData(), "All data should be written at once");
private boolean copyFromSerializerToTargetChannel(int targetChannel, boolean isBroadcast, boolean flushAlways) throws IOException, InterruptedException { // We should reset the initial position of the intermediate serialization data buffer before // copying, so the serialization results can be copied to many different target buffers. serializer.reset(); boolean pruneTriggered = false; BufferBuilder bufferBuilder = getBufferBuilder(targetChannel, isBroadcast); RecordSerializer.SerializationResult result = serializer.copyToBufferBuilder(bufferBuilder); while (result.isFullBuffer()) { updateMetrics(bufferBuilder, isBroadcast); // If this was a full record, we are done. Not breaking // out of the loop at this point will lead to another // buffer request before breaking out (that would not be // a problem per se, but it can lead to stalls in the pipeline). if (result.isFullRecord()) { pruneTriggered = true; break; } bufferBuilder = requestNewBufferBuilder(targetChannel, isBroadcast); result = serializer.copyToBufferBuilder(bufferBuilder); } checkState(!serializer.hasSerializedData(), "All data should be written at once"); if (flushAlways) { if (isBroadcast) { flushAll(); } else { flush(targetChannel); } } return pruneTriggered; }