Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public class BlockDataStreamOutput implements ByteBufferStreamOutput {
private long syncPosition = 0;
private StreamBuffer currentBuffer;
private XceiverClientMetrics metrics;
// buffers for which putBlock is yet to be executed
private List<StreamBuffer> buffersForPutBlock;
/**
* Creates a new BlockDataStreamOutput.
*
Expand Down Expand Up @@ -287,6 +289,10 @@ private void writeChunkIfNeeded() throws IOException {

private void writeChunk(StreamBuffer sb) throws IOException {
bufferList.add(sb);
if (buffersForPutBlock == null) {
buffersForPutBlock = new ArrayList<>();
}
buffersForPutBlock.add(sb);
ByteBuffer dup = sb.duplicate();
dup.position(0);
dup.limit(sb.position());
Expand Down Expand Up @@ -392,7 +398,8 @@ private void executePutBlock(boolean close,
final List<StreamBuffer> byteBufferList;
if (!force) {
Preconditions.checkNotNull(bufferList);
byteBufferList = bufferList;
byteBufferList = buffersForPutBlock;
buffersForPutBlock = null;
Preconditions.checkNotNull(byteBufferList);
} else {
byteBufferList = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ long getWrittenDataLength() {
}
}

long getTotalAckDataLength() {
public long getTotalAckDataLength() {
if (byteBufferStreamOutput != null) {
BlockDataStreamOutput out =
(BlockDataStreamOutput) this.byteBufferStreamOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.hadoop.ozone.client.ObjectStore;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneClientFactory;
import org.apache.hadoop.ozone.client.io.BlockDataStreamOutputEntry;
import org.apache.hadoop.ozone.client.io.KeyDataStreamOutput;
import org.apache.hadoop.ozone.client.io.OzoneDataStreamOutput;
import org.apache.hadoop.ozone.container.ContainerTestHelper;
Expand Down Expand Up @@ -256,4 +257,22 @@ public void testMinPacketSize() throws Exception {
validateData(keyName, dataString.concat(dataString).getBytes(UTF_8));
}

@Test
public void testTotalAckDataLength() throws Exception {
int dataLength = 400;
String keyName = getKeyName();
OzoneDataStreamOutput key = createKey(
keyName, ReplicationType.RATIS, 0);
byte[] data =
ContainerTestHelper.getFixedLengthString(keyString, dataLength)
.getBytes(UTF_8);
KeyDataStreamOutput keyDataStreamOutput =
(KeyDataStreamOutput) key.getByteBufStreamOutput();
BlockDataStreamOutputEntry stream =
keyDataStreamOutput.getStreamEntries().get(0);
key.write(ByteBuffer.wrap(data));
key.close();
Assert.assertEquals(dataLength, stream.getTotalAckDataLength());
}

}