diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java index 40ad3b2..e603fee 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java @@ -146,16 +146,6 @@ public HiveConnection(String uri, Properties info) throws SQLException { fetchSize = Integer.parseInt(sessConfMap.get(JdbcConnectionParams.FETCH_SIZE)); } - if (isEmbeddedMode) { - EmbeddedThriftBinaryCLIService embeddedClient = new EmbeddedThriftBinaryCLIService(); - embeddedClient.init(null); - client = embeddedClient; - } else { - // open the client transport - openTransport(); - // set up the client - client = new TCLIService.Client(new TBinaryProtocol(transport)); - } // add supported protocols supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1); supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V2); @@ -166,35 +156,34 @@ public HiveConnection(String uri, Properties info) throws SQLException { supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V7); supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8); - // open client session - openSession(); + if (isEmbeddedMode) { + EmbeddedThriftBinaryCLIService embeddedClient = new EmbeddedThriftBinaryCLIService(); + embeddedClient.init(null); + client = embeddedClient; - // Wrap the client with a thread-safe proxy to serialize the RPC calls - client = newSynchronizedClient(client); - } - - private void openTransport() throws SQLException { - int maxRetries = 1; - try { - String strRetries = sessConfMap.get(JdbcConnectionParams.RETRIES); - if (StringUtils.isNotBlank(strRetries)) { - maxRetries = Integer.parseInt(strRetries); + // open client session + openSession(); + } else { + int maxRetries = 1; + try { + String strRetries = sessConfMap.get(JdbcConnectionParams.RETRIES); + if (StringUtils.isNotBlank(strRetries)) { + maxRetries = Integer.parseInt(strRetries); + } + } catch(NumberFormatException e) { // Ignore the exception } - } catch(NumberFormatException e) { // Ignore the exception - } - for (int numRetries = 0;;) { + for (int numRetries = 0;;) { try { - assumeSubject = - JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT.equals(sessConfMap - .get(JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE)); - transport = isHttpTransportMode() ? createHttpTransport() : createBinaryTransport(); - if (!transport.isOpen()) { - transport.open(); - logZkDiscoveryMessage("Connected to " + connParams.getHost() + ":" + connParams.getPort()); - } + // open the client transport + openTransport(); + // set up the client + client = new TCLIService.Client(new TBinaryProtocol(transport)); + // open client session + openSession(); + break; - } catch (TTransportException e) { + } catch (Exception e) { LOG.warn("Failed to connect to " + connParams.getHost() + ":" + connParams.getPort()); String errMsg = null; String warnMsg = "Could not open client transport with JDBC Uri: " + jdbcUriString + ": "; @@ -219,7 +208,22 @@ private void openTransport() throws SQLException { LOG.warn(warnMsg + e.getMessage() + " Retrying " + numRetries + " of " + maxRetries); } } + } } + + // Wrap the client with a thread-safe proxy to serialize the RPC calls + client = newSynchronizedClient(client); + } + + private void openTransport() throws Exception { + assumeSubject = + JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT.equals(sessConfMap + .get(JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE)); + transport = isHttpTransportMode() ? createHttpTransport() : createBinaryTransport(); + if (!transport.isOpen()) { + transport.open(); + logZkDiscoveryMessage("Connected to " + connParams.getHost() + ":" + connParams.getPort()); + } } public String getConnectedUrl() {