HDFS-5445. PacketReceiver populates the packetLen field in PacketHeader incorrectly (Jonathan Mace via Colin P. McCabe)

This commit is contained in:
Colin Patrick Mccabe 2015-01-12 17:11:03 -08:00
parent b3ddd7ee39
commit f761bd8fe4
3 changed files with 8 additions and 2 deletions

View File

@ -679,6 +679,9 @@ Release 2.7.0 - UNRELEASED
HDFS-7533. Datanode sometimes does not shutdown on receiving upgrade HDFS-7533. Datanode sometimes does not shutdown on receiving upgrade
shutdown command (Eric Payne via kihwal) shutdown command (Eric Payne via kihwal)
HDFS-5445. PacketReceiver populates the packetLen field in PacketHeader
incorrectly (Jonathan Mace via Colin P. McCabe)
Release 2.6.1 - UNRELEASED Release 2.6.1 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -178,7 +178,7 @@ public class PacketReceiver implements Closeable {
if (curHeader == null) { if (curHeader == null) {
curHeader = new PacketHeader(); curHeader = new PacketHeader();
} }
curHeader.setFieldsFromData(dataPlusChecksumLen, headerBuf); curHeader.setFieldsFromData(payloadLen, headerBuf);
// Compute the sub-slices of the packet // Compute the sub-slices of the packet
int checksumLen = dataPlusChecksumLen - curHeader.getDataLen(); int checksumLen = dataPlusChecksumLen - curHeader.getDataLen();

View File

@ -27,6 +27,8 @@ import org.apache.hadoop.hdfs.AppendTestUtil;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import com.google.common.primitives.Ints;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class TestPacketReceiver { public class TestPacketReceiver {
@ -38,7 +40,7 @@ public class TestPacketReceiver {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos); DataOutputStream dos = new DataOutputStream(baos);
int packetLen = data.length + sums.length + 4; int packetLen = data.length + sums.length + Ints.BYTES;
PacketHeader header = new PacketHeader( PacketHeader header = new PacketHeader(
packetLen, OFFSET_IN_BLOCK, SEQNO, false, data.length, false); packetLen, OFFSET_IN_BLOCK, SEQNO, false, data.length, false);
header.write(dos); header.write(dos);
@ -87,6 +89,7 @@ public class TestPacketReceiver {
PacketHeader header = pr.getHeader(); PacketHeader header = pr.getHeader();
assertEquals(SEQNO, header.getSeqno()); assertEquals(SEQNO, header.getSeqno());
assertEquals(OFFSET_IN_BLOCK, header.getOffsetInBlock()); assertEquals(OFFSET_IN_BLOCK, header.getOffsetInBlock());
assertEquals(dataLen + checksumsLen + Ints.BYTES, header.getPacketLen());
// Mirror the packet to an output stream and make sure it matches // Mirror the packet to an output stream and make sure it matches
// the packet we sent. // the packet we sent.