Class Reader


  • public class Reader
    extends java.lang.Object
    Packet reader
    • Field Detail

      • REUSABLE_BUFFER_LENGTH

        private static final int REUSABLE_BUFFER_LENGTH
        See Also:
        Constant Field Values
      • logger

        private static final Logger logger
      • header

        private final byte[] header
      • reusableArray

        private final byte[] reusableArray
      • inputStream

        private final java.io.InputStream inputStream
      • maxQuerySizeToLog

        private final int maxQuerySizeToLog
      • serverThreadLog

        private java.lang.String serverThreadLog
      • DEFAULT_MAX_RECEIVE_PACKET

        private static final int DEFAULT_MAX_RECEIVE_PACKET
        Server-independent ceiling applied to received packets once authentication completes when no maxAllowedPacket is configured. Set to a quarter of the JVM max heap, clamped between 16Mb and 1Gb
      • maxAllowedPacket

        private java.lang.Integer maxAllowedPacket
        Maximum packet size accepted (1Mb before authentication completes).
    • Constructor Detail

      • Reader

        public Reader​(java.io.InputStream in,
                      Configuration conf,
                      MutableByte sequence)
        Constructor of standard socket MySQL packet stream reader.
        Parameters:
        in - stream
        conf - connection options
        sequence - current increment sequence
    • Method Detail

      • readableBufFromArray

        public ReadableByteBuf readableBufFromArray​(byte[] buf)
      • readReusablePacket

        public ReadableByteBuf readReusablePacket()
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readReusablePacket

        public ReadableByteBuf readReusablePacket​(boolean traceEnable)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readPacket

        public byte[] readPacket​(boolean traceEnable)
                          throws java.io.IOException
        Get the next MySQL packet. If the packet is more than 16M, read as many packets needed to finish reading MySQL packet. (first that has no length = 16Mb)
        Parameters:
        traceEnable - must trace packet.
        Returns:
        array packet.
        Throws:
        java.io.IOException - if socket exception occur.
      • readMultiPacket

        private byte[] readMultiPacket​(byte[] firstFragment,
                                       boolean traceEnable)
                                throws java.io.IOException
        Reassemble a MySQL packet split over several 16Mb fragments. Fragments are buffered as they arrive and copied once into the final array: growing and copying the accumulated content for every fragment would copy O(n²/16Mb) bytes for an n-byte packet.
        Parameters:
        firstFragment - first (full 16Mb) fragment, already read
        traceEnable - must trace packet
        Returns:
        complete packet content
        Throws:
        java.io.IOException - if socket exception occur
      • readFully

        private void readFully​(byte[] dest,
                               int length)
                        throws java.io.IOException
        Read exactly length bytes from the socket into the beginning of dest.
        Parameters:
        dest - destination array
        length - number of bytes to read
        Throws:
        java.io.IOException - if socket exception occur or the stream ends early
      • setMaxAllowedPacket

        public void setMaxAllowedPacket​(java.lang.Integer maxAllowedPacket)
        Set the maximum size (in bytes) of a packet the reader will accept. Called once the handshake/authentication phase is over to raise the limit from the 1Mb connection-phase cap to the configured maxAllowedPacket.
        Parameters:
        maxAllowedPacket - maximum received packet size, or null to use the default heap-relative ceiling
      • close

        public void close()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • setServerThreadId

        public void setServerThreadId​(java.lang.Long serverThreadId,
                                      HostAddress hostAddress)
        Set server thread id.
        Parameters:
        serverThreadId - current server thread id.
        hostAddress - host information
      • readHeader

        private int readHeader()
                        throws java.io.IOException
        Throws:
        java.io.IOException