/** * Used in test only. */ @VisibleForTesting void setBytesCurBlock(final long bytesCurBlock) { getStreamer().setBytesCurBlock(bytesCurBlock); }
/** * Used in test only. */ @VisibleForTesting void setAppendChunk(final boolean appendChunk) { getStreamer().setAppendChunk(appendChunk); }
/** * Returns the access token currently used by streamer, for testing only */ synchronized Token<BlockTokenIdentifier> getBlockToken() { return getStreamer().getBlockToken(); }
@VisibleForTesting ExtendedBlock getBlock() { return getStreamer().getBlock(); }
@VisibleForTesting public synchronized DatanodeInfo[] getPipeline() { if (getStreamer().streamerClosed()) { return null; } DatanodeInfo[] currentNodes = getStreamer().getNodes(); if (currentNodes == null) { return null; } DatanodeInfo[] value = new DatanodeInfo[currentNodes.length]; System.arraycopy(currentNodes, 0, value, 0, currentNodes.length); return value; }
@VisibleForTesting public void setArtificialSlowdown(long period) { getStreamer().setArtificialSlowdown(period); }
void enqueueCurrentPacket() throws IOException { getStreamer().waitAndQueuePacket(currentPacket); currentPacket = null; }
protected void closeThreads(boolean force) throws IOException { try { getStreamer().close(force); getStreamer().join(); getStreamer().closeSocket(); } catch (InterruptedException e) { throw new IOException("Failed to shutdown streamer"); } finally { getStreamer().setSocketToNull(); setClosed(); } }
protected synchronized void start() { getStreamer().start(); }
boolean isClosed() { return closed || getStreamer().streamerClosed(); }
synchronized void enqueueCurrentPacketFull() throws IOException { LOG.debug("enqueue full {}, src={}, bytesCurBlock={}, blockSize={}," + " appendChunk={}, {}", currentPacket, src, getStreamer() .getBytesCurBlock(), blockSize, getStreamer().getAppendChunk(), getStreamer()); enqueueCurrentPacket(); adjustChunkBoundary(); endBlock(); }
/** create an empty packet to mark the end of the block. */ void setCurrentPacketToEmpty() throws InterruptedIOException { currentPacket = createPacket(0, 0, getStreamer().getBytesCurBlock(), getStreamer().getAndIncCurrentSeqno(), true); currentPacket.setSyncBlock(shouldSyncBlock); }
/** * Waits till all existing data is flushed and confirmations * received from datanodes. */ protected void flushInternal() throws IOException { long toWaitFor = flushInternalWithoutWaitingAck(); getStreamer().waitForAckedSeqno(toWaitFor); }
void setClosed() { closed = true; dfsClient.endFileLease(fileId); getStreamer().release(); }
/** * if encountering a block boundary, send an empty packet to * indicate the end of block and reset bytesCurBlock. * * @throws IOException */ void endBlock() throws IOException { if (getStreamer().getBytesCurBlock() == blockSize) { setCurrentPacketToEmpty(); enqueueCurrentPacket(); getStreamer().setBytesCurBlock(0); lastFlushOffset = 0; } }
protected long flushInternalWithoutWaitingAck() throws IOException { long toWaitFor; synchronized (this) { dfsClient.checkOpen(); checkClosed(); // // If there is data in the current buffer, send it across // getStreamer().queuePacket(currentPacket); currentPacket = null; toWaitFor = getStreamer().getLastQueuedSeqno(); } return toWaitFor; }
@Override protected void checkClosed() throws IOException { if (isClosed()) { getStreamer().getLastException().throwException4Close(); } }
public static void setPipeline(DFSOutputStream out, LocatedBlock lastBlock) throws IOException { out.getStreamer().setPipelineInConstruction(lastBlock); }
private void completeFile() throws IOException { // get last block before destroying the streamer ExtendedBlock lastBlock = getStreamer().getBlock(); try (TraceScope ignored = dfsClient.getTracer().newScope("completeFile")) { completeFile(lastBlock); } }
protected synchronized void writeChunk(ByteBuffer buffer, int len, byte[] checksum, int ckoff, int cklen) throws IOException { writeChunkPrepare(len, ckoff, cklen); currentPacket.writeChecksum(checksum, ckoff, cklen); currentPacket.writeData(buffer, len); currentPacket.incNumChunks(); getStreamer().incBytesCurBlock(len); // If packet is full, enqueue it for transmission if (currentPacket.getNumChunks() == currentPacket.getMaxChunks() || getStreamer().getBytesCurBlock() == blockSize) { enqueueCurrentPacketFull(); } }