private void verifyChunks( byte[] dataBuf, int dataOff, int len, 
                             byte[] checksumBuf, int checksumOff,
                             int firstChunkOffset, int packetVersion) 
                             throws IOException {
    int chunkOffset = firstChunkOffset;
    while (len > 0) {
      int chunkLen = Math.min(len, bytesPerChecksum - chunkOffset);
      chunkOffset = 0;
      
      checksum.update(dataBuf, dataOff, chunkLen);
      dataOff += chunkLen;

      boolean checksumCorrect;
      if (packetVersion == DataTransferProtocol.PACKET_VERSION_CHECKSUM_FIRST) {
        checksumCorrect = checksum.compare(checksumBuf, checksumOff);
        checksumOff += checksumSize;
      } else {
        // Expect packetVersion == DataTransferProtocol.PACKET_VERSION_CHECKSUM_INLINE
        checksumCorrect = checksum.compare(dataBuf, dataOff);
        dataOff += checksumSize;
      }

      if (!checksumCorrect) {
        if (srcDataNode != null) {
          try {
            LOG.info("report corrupt block " + block + " from datanode " +
                      srcDataNode + " to namenode");
            LocatedBlock lb = new LocatedBlock(block, 
                                            new DatanodeInfo[] {srcDataNode});
            datanode.reportBadBlocks(namespaceId, new LocatedBlock[] {lb});
          } catch (IOException e) {
            LOG.warn("Failed to report bad block " + block + 
                      " from datanode " + srcDataNode + " to namenode");
          }
        }
        throw new IOException("Unexpected checksum mismatch " + 
                              "while writing " + block + " from " + inAddr);
      }

      checksum.reset();
      len -= chunkLen;
    }
  }
private void verifyChunks ( byte [ ] dataBuf , int dataOff , int len , byte [ ] checksumBuf , int checksumOff , int firstChunkOffset , int packetVersion ) throws IOException { int chunkOffset = firstChunkOffset ; while ( len > 0 ) { int chunkLen = Math . min ( len , bytesPerChecksum - chunkOffset ) ; chunkOffset = 0 ; checksum . update ( dataBuf , dataOff , chunkLen ) ; dataOff += chunkLen ; boolean checksumCorrect ; if ( packetVersion == DataTransferProtocol . PACKET_VERSION_CHECKSUM_FIRST ) { checksumCorrect = checksum . compare ( checksumBuf , checksumOff ) ; checksumOff += checksumSize ; } else { checksumCorrect = checksum . compare ( dataBuf , dataOff ) ; dataOff += checksumSize ; } if ( ! checksumCorrect ) { if ( srcDataNode != null ) { try { LOG . info ( "report corrupt block " + block + " from datanode " + srcDataNode + " to namenode" ) ; LocatedBlock lb = new LocatedBlock ( block , new DatanodeInfo [ ] { srcDataNode } ) ; datanode . reportBadBlocks ( namespaceId , new LocatedBlock [ ] { lb } ) ; } catch ( IOException e ) { LOG . warn ( "Failed to report bad block " + block + " from datanode " + srcDataNode + " to namenode" ) ; } } throw new IOException ( "Unexpected checksum mismatch " + "while writing " + block + " from " + inAddr ) ; } checksum . reset ( ) ; len -= chunkLen ; } }
Verify multiple CRC chunks.