amansinha100 commented on code in PR #3674:
URL: https://github.com/apache/hive/pull/3674#discussion_r998868796
##########
common/src/java/org/apache/hadoop/hive/common/auth/HiveAuthUtils.java:
##########
@@ -50,45 +49,108 @@
public class HiveAuthUtils {
private static final Logger LOG =
LoggerFactory.getLogger(HiveAuthUtils.class);
+ /**
+ * Configure the provided T transport's max message size.
+ * @param transport Transport to configure maxMessage for
+ * @param maxMessageSize Maximum allowed message size in bytes, less than or
equal to 0 means use the Thrift library
+ * default.
+ * @return The passed in T transport configured with desired max message
size. The same object passed in is returned.
+ */
+ public static <T extends TTransport> T configureThriftMaxMessageSize(T
transport, int maxMessageSize) {
+ if (maxMessageSize > 0) {
+ if (transport.getConfiguration() == null) {
+ LOG.warn("TTransport {} is returning a null Configuration, Thrift max
message size is not getting configured",
+ transport.getClass().getName());
+ return transport;
+ }
+ transport.getConfiguration().setMaxMessageSize(maxMessageSize);
+ }
+ return transport;
+ }
+
+ /**
+ * Create a TSocket for the provided host and port with specified
loginTimeout. Thrift maxMessageSize
+ * will default to Thrift library default.
+ * @param host Host to connect to.
+ * @param port Port to connect to.
+ * @param loginTimeout Socket timeout (0 means no timeout).
+ * @return TTransport TSocket for host/port.
+ */
public static TTransport getSocketTransport(String host, int port, int
loginTimeout) throws TTransportException {
- return new TSocket(new TConfiguration(),host, port, loginTimeout);
+ return getSocketTransport(host, port, loginTimeout, -1);
+ }
+
+ /**
+ * Create a TSocket for the provided host and port with specified
loginTimeout and maxMessageSize.
+ * will default to Thrift library default.
+ * @param host Host to connect to.
+ * @param port Port to connect to.
+ * @param loginTimeout Socket timeout (0 means no timeout).
+ * @param maxMessageSize Size in bytes for max allowable Thrift message
size, less than or equal to 0
+ * results in using the Thrift library default.
+ * @return TTransport TSocket for host/port
+ */
+ public static TTransport getSocketTransport(String host, int port, int
loginTimeout, int maxMessageSize)
+ throws TTransportException {
+ TSocket tSocket = new TSocket(host, port, loginTimeout);
+ return configureThriftMaxMessageSize(tSocket, maxMessageSize);
+ }
+
+ public static TTransport getSSLSocket(String host, int port, int
loginTimeout, TSSLTransportParameters params,
+ int maxMessageSize) throws TTransportException {
+ // The underlying SSLSocket object is bound to host:port with the given
SO_TIMEOUT and
+ // SSLContext created with the given params
+ TSocket tSSLSocket = null;
+ if (params != null) {
+ tSSLSocket = TSSLTransportFactory.getClientSocket(host, port,
loginTimeout, params);
+ } else {
+ tSSLSocket = TSSLTransportFactory.getClientSocket(host, port,
loginTimeout);
+ }
+ configureThriftMaxMessageSize(tSSLSocket, maxMessageSize);
Review Comment:
It is little odd that the return value of this is not being used. Is this
a spurious call ? Considering that the next statement getSSLSocketWithHttps()
does the same thing.
##########
common/src/java/org/apache/hadoop/hive/common/auth/HiveAuthUtils.java:
##########
@@ -50,45 +49,108 @@
public class HiveAuthUtils {
private static final Logger LOG =
LoggerFactory.getLogger(HiveAuthUtils.class);
+ /**
+ * Configure the provided T transport's max message size.
+ * @param transport Transport to configure maxMessage for
+ * @param maxMessageSize Maximum allowed message size in bytes, less than or
equal to 0 means use the Thrift library
+ * default.
+ * @return The passed in T transport configured with desired max message
size. The same object passed in is returned.
+ */
+ public static <T extends TTransport> T configureThriftMaxMessageSize(T
transport, int maxMessageSize) {
+ if (maxMessageSize > 0) {
+ if (transport.getConfiguration() == null) {
+ LOG.warn("TTransport {} is returning a null Configuration, Thrift max
message size is not getting configured",
+ transport.getClass().getName());
+ return transport;
+ }
+ transport.getConfiguration().setMaxMessageSize(maxMessageSize);
+ }
+ return transport;
+ }
+
+ /**
+ * Create a TSocket for the provided host and port with specified
loginTimeout. Thrift maxMessageSize
+ * will default to Thrift library default.
+ * @param host Host to connect to.
+ * @param port Port to connect to.
+ * @param loginTimeout Socket timeout (0 means no timeout).
+ * @return TTransport TSocket for host/port.
+ */
public static TTransport getSocketTransport(String host, int port, int
loginTimeout) throws TTransportException {
- return new TSocket(new TConfiguration(),host, port, loginTimeout);
+ return getSocketTransport(host, port, loginTimeout, -1);
+ }
+
+ /**
+ * Create a TSocket for the provided host and port with specified
loginTimeout and maxMessageSize.
+ * will default to Thrift library default.
+ * @param host Host to connect to.
+ * @param port Port to connect to.
+ * @param loginTimeout Socket timeout (0 means no timeout).
+ * @param maxMessageSize Size in bytes for max allowable Thrift message
size, less than or equal to 0
+ * results in using the Thrift library default.
+ * @return TTransport TSocket for host/port
+ */
+ public static TTransport getSocketTransport(String host, int port, int
loginTimeout, int maxMessageSize)
+ throws TTransportException {
+ TSocket tSocket = new TSocket(host, port, loginTimeout);
+ return configureThriftMaxMessageSize(tSocket, maxMessageSize);
+ }
+
+ public static TTransport getSSLSocket(String host, int port, int
loginTimeout, TSSLTransportParameters params,
+ int maxMessageSize) throws TTransportException {
+ // The underlying SSLSocket object is bound to host:port with the given
SO_TIMEOUT and
+ // SSLContext created with the given params
+ TSocket tSSLSocket = null;
+ if (params != null) {
+ tSSLSocket = TSSLTransportFactory.getClientSocket(host, port,
loginTimeout, params);
+ } else {
+ tSSLSocket = TSSLTransportFactory.getClientSocket(host, port,
loginTimeout);
+ }
+ configureThriftMaxMessageSize(tSSLSocket, maxMessageSize);
+ return getSSLSocketWithHttps(tSSLSocket, maxMessageSize);
+ }
+
+ public static TTransport getSSLSocket(String host, int port, int
loginTimeout, String trustStorePath,
+ String trustStorePassWord, String trustStoreType, String
trustStoreAlgorithm) throws TTransportException {
+ return getSSLSocket(host, port, loginTimeout, trustStorePath,
trustStorePassWord, trustStoreType,
+ trustStoreAlgorithm, -1);
}
- public static TTransport getSSLSocket(String host, int port, int
loginTimeout)
- throws TTransportException {
- // The underlying SSLSocket object is bound to host:port with the given
SO_TIMEOUT
- TSocket tSSLSocket = TSSLTransportFactory.getClientSocket(host, port,
loginTimeout);
- return getSSLSocketWithHttps(tSSLSocket);
+ public static TTransport getSSLSocket(String host, int port, int
loginTimeout) throws TTransportException {
+ return getSSLSocket(host, port, loginTimeout, -1);
}
- public static TTransport getSSLSocket(String host, int port, int
loginTimeout,
- String trustStorePath, String trustStorePassWord, String trustStoreType,
- String trustStoreAlgorithm) throws TTransportException {
- TSSLTransportFactory.TSSLTransportParameters params =
- new TSSLTransportFactory.TSSLTransportParameters();
+ public static TTransport getSSLSocket(String host, int port, int
loginTimeout, int maxMessageSize)
+ throws TTransportException {
+ return getSSLSocket(host, port, loginTimeout, null, maxMessageSize);
Review Comment:
For the default values being passed (e.g null) or -1 etc. could you add a
/* param name */
##########
common/src/java/org/apache/hadoop/hive/common/auth/HiveAuthUtils.java:
##########
@@ -50,45 +49,108 @@
public class HiveAuthUtils {
private static final Logger LOG =
LoggerFactory.getLogger(HiveAuthUtils.class);
+ /**
+ * Configure the provided T transport's max message size.
+ * @param transport Transport to configure maxMessage for
+ * @param maxMessageSize Maximum allowed message size in bytes, les than or
equal to 0 means use the Thrift library
+ * default.
+ * @return The passed in T transport configured with desired max message
size. The same object passed in is returned.
+ */
+ public static <T extends TTransport> T configureThriftMaxMessageSize(T
transport, int maxMessageSize) {
+ if (maxMessageSize > 0) {
+ if (transport.getConfiguration() == null) {
+ LOG.warn("TTransport {} is returning a null Configuration, Thrift max
message size is not getting configured",
Review Comment:
makes sense
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]