diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java index fb2137d1066..f23089077cd 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityGroup.java @@ -292,7 +292,8 @@ public static Optional get(String url, Properties propert * * @param url The HA connection url optionally; empty optional if properties disables fallback * @param properties The client connection properties - * @return The connection url of the single cluster to fall back + * @return The connection url of the single cluster to fall back on, + * with a fully qualified JDBC protocol * @throws SQLException if fails to get HA information and/or invalid properties are seen */ static Optional getFallbackCluster(String url, Properties properties) throws SQLException { @@ -309,6 +310,13 @@ static Optional getFallbackCluster(String url, Properties properties) th if (StringUtils.isEmpty(fallbackCluster)) { fallbackCluster = haGroupInfo.getUrl1(); } + + // Ensure the fallback cluster URL includes the JDBC protocol prefix + if (!fallbackCluster.startsWith(PhoenixRuntime.JDBC_PROTOCOL_ZK)) { + fallbackCluster = PhoenixRuntime.JDBC_PROTOCOL_ZK + + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + fallbackCluster; + } + LOG.info("Falling back to single cluster '{}' for the HA group {} to serve HA connection " + "request against url '{}'.", fallbackCluster, haGroupInfo.getName(), url); diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixHAAdminTool.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixHAAdminTool.java index e7a9cd7a22f..5da3ea15933 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixHAAdminTool.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixHAAdminTool.java @@ -280,7 +280,7 @@ public static String getLocalZkUrl(Configuration conf) { } String portStr = conf.get(HConstants.ZOOKEEPER_CLIENT_PORT); - int port = HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT; + int port = HConstants.DEFAULT_ZOOKEEPER_CLIENT_PORT; if (portStr != null) { try { port = Integer.parseInt(portStr); diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/util/JDBCUtil.java b/phoenix-core-client/src/main/java/org/apache/phoenix/util/JDBCUtil.java index 6e72fc1940c..c4f64c47a2b 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/util/JDBCUtil.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/util/JDBCUtil.java @@ -26,6 +26,7 @@ import javax.annotation.Nullable; +import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.client.Consistency; import org.apache.phoenix.jdbc.ConnectionInfo; import org.apache.phoenix.jdbc.ZKConnectionInfo; @@ -219,7 +220,11 @@ public static String getSchema(String url, Properties info, String defaultValue) public static String formatZookeeperUrl(String jdbcUrl) { ConnectionInfo connInfo; try { - connInfo = ConnectionInfo.create(jdbcUrl, null, null); + Properties info = new Properties(); + // Make sure we use ZK on HBase 3.x + info.put(HConstants.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY, + ZKConnectionInfo.ZK_REGISTRY_NAME); + connInfo = ConnectionInfo.create(jdbcUrl, null, info); // TODO in theory we could support non-ZK registries for HA. // However, as HA already relies on ZK, this wouldn't be particularly useful, // and would require significant changes. diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionIT.java index 0eba0b8f517..ec643ca1fdd 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionIT.java @@ -36,6 +36,7 @@ import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.jdbc.PhoenixDriver; import org.apache.phoenix.jdbc.PhoenixTestDriver; +import org.apache.phoenix.jdbc.ZKConnectionInfo; import org.apache.phoenix.mapreduce.util.ConnectionUtil; import org.apache.phoenix.query.ConfigurationFactory; import org.apache.phoenix.util.InstanceResolver; @@ -58,6 +59,7 @@ public static synchronized void setUp() throws Exception { conf = hbaseTestUtil.getConfiguration(); setUpConfigForMiniCluster(conf); conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/hbase-test"); + conf.set("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); hbaseTestUtil.startMiniCluster(); Class.forName(PhoenixDriver.class.getName()); DriverManager.registerDriver(new PhoenixTestDriver()); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ContextClassloaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ContextClassloaderIT.java index ed0bd6cbb1a..9592e47498c 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ContextClassloaderIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ContextClassloaderIT.java @@ -17,7 +17,7 @@ */ package org.apache.phoenix.end2end; -import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL; +import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_ZK; import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR; import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR; import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM; @@ -60,7 +60,7 @@ public static synchronized void setUpBeforeClass() throws Exception { hbaseTestUtil = new HBaseTestingUtility(conf); hbaseTestUtil.startMiniCluster(); String clientPort = hbaseTestUtil.getConfiguration().get(QueryServices.ZOOKEEPER_PORT_ATTRIB); - String url = JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + LOCALHOST + JDBC_PROTOCOL_SEPARATOR + clientPort + String url = JDBC_PROTOCOL_ZK + JDBC_PROTOCOL_SEPARATOR + LOCALHOST + JDBC_PROTOCOL_SEPARATOR + clientPort + JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM; driver = initAndRegisterTestDriver(url, ReadOnlyProps.EMPTY_PROPS); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MigrateSystemTablesToSystemNamespaceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MigrateSystemTablesToSystemNamespaceIT.java index f9ceccfe653..6aaba958ffa 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MigrateSystemTablesToSystemNamespaceIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MigrateSystemTablesToSystemNamespaceIT.java @@ -421,7 +421,7 @@ private void verifySyscatData(Properties clientProps, String connName, Statement } private String getJdbcUrl() { - return "jdbc:phoenix:localhost:" + testUtil.getZkCluster().getClientPort() + ":/hbase"; + return "jdbc:phoenix+zk:localhost:" + testUtil.getZkCluster().getClientPort() + ":/hbase"; } } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PartialResultServerConfigurationIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PartialResultServerConfigurationIT.java index 2cc4629cd7e..b77231520e0 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PartialResultServerConfigurationIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PartialResultServerConfigurationIT.java @@ -75,7 +75,7 @@ public static synchronized void setUp() throws Exception { hbaseTestUtil.startMiniCluster(); zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort(); - url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; + url = PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; DriverManager.registerDriver(PhoenixDriver.INSTANCE); DriverManager.registerDriver(new PhoenixTestDriver()); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixDriverIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixDriverIT.java index d85df7e68b5..5a6f94c960a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixDriverIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixDriverIT.java @@ -40,6 +40,7 @@ import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.snapshot.SnapshotCreationException; +import org.apache.phoenix.jdbc.ConnectionInfo; import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.jdbc.PhoenixDriver; import org.apache.phoenix.jdbc.PhoenixStatement; @@ -75,7 +76,7 @@ public static synchronized void setUp() throws Exception { hbaseTestUtil.startMiniCluster(); // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort(); - url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; + url = PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; DriverManager.registerDriver(PhoenixDriver.INSTANCE); } @@ -85,12 +86,14 @@ public Connection createConnection(String tenantId, boolean isDifferentClient) t // force the use of ConnectionQueryServicesImpl instead of ConnectionQueryServicesTestImpl props.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS); - if (tenantId!=null) + if (tenantId!=null) { props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId); - StringBuilder sb = new StringBuilder(url); - if (isDifferentClient) - sb.append(PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + "Client2"); - return DriverManager.getConnection(sb.toString(), props); + } + if (isDifferentClient) { + ConnectionInfo info = ConnectionInfo.createNoLogin(url, null, props); + return DriverManager.getConnection(info.withPrincipal(tenantId).toUrl(), props); + } + return DriverManager.getConnection(url, props); } @Test diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RebuildIndexConnectionPropsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RebuildIndexConnectionPropsIT.java index 7fd66da08b2..a0b5ff1145a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RebuildIndexConnectionPropsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RebuildIndexConnectionPropsIT.java @@ -70,7 +70,7 @@ public static synchronized void doSetup() throws Exception { hbaseTestUtil.startMiniCluster(); // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort(); - url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; + url = PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; Properties driverProps = PropertiesUtil.deepCopy(TEST_PROPERTIES); DriverManager.registerDriver(PhoenixDriver.INSTANCE); try (PhoenixConnection phxConn = diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpdateCacheAcrossDifferentClientsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpdateCacheAcrossDifferentClientsIT.java index 76f5a701eb0..2669063df45 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpdateCacheAcrossDifferentClientsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpdateCacheAcrossDifferentClientsIT.java @@ -19,6 +19,7 @@ import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData; import org.apache.phoenix.jdbc.PhoenixDriver; +import org.apache.phoenix.jdbc.ZKConnectionInfo; import org.apache.phoenix.query.BaseTest; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesOptions; @@ -71,6 +72,8 @@ public void testUpdateCacheFrequencyWithAddAndDropTable() throws Exception { longRunningProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS); longRunningProps.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.TRUE.toString()); + longRunningProps.put("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); + Connection conn1 = DriverManager.getConnection(url, longRunningProps); String url2 = url + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + "LongRunningQueries"; Connection conn2 = DriverManager.getConnection(url2, longRunningProps); @@ -136,6 +139,7 @@ public void testTableSentWhenIndexStateChanges() throws Throwable { longRunningProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS); longRunningProps.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.TRUE.toString()); + longRunningProps.put("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); Connection conn1 = DriverManager.getConnection(url, longRunningProps); String url2 = url + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + "LongRunningQueries"; Connection conn2 = DriverManager.getConnection(url2, longRunningProps); @@ -171,6 +175,7 @@ public void testTableSentWhenIndexStateChanges() throws Throwable { public void testUpdateCacheFrequencyWithAddColumn() throws Exception { // Create connections 1 and 2 Properties longRunningProps = new Properties(); // Must update config before starting server + longRunningProps.put("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); Connection conn1 = DriverManager.getConnection(url, longRunningProps); Connection conn2 = DriverManager.getConnection(url, longRunningProps); conn1.setAutoCommit(true); @@ -218,6 +223,7 @@ public void testUpdateCacheFrequencyWithAddAndDropIndex() throws Exception { Properties longRunningProps = new Properties(); longRunningProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS); + longRunningProps.put("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); Connection conn1 = DriverManager.getConnection(url, longRunningProps); String url2 = url + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + "LongRunningQueries"; Connection conn2 = DriverManager.getConnection(url2, longRunningProps); @@ -269,6 +275,7 @@ public void testUpdateCacheFrequencyWithAddAndDropView() throws Exception { Properties longRunningProps = new Properties(); longRunningProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS); + longRunningProps.put("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); Connection conn1 = DriverManager.getConnection(url, longRunningProps); String url2 = url + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + "LongRunningQueries"; Connection conn2 = DriverManager.getConnection(url2, longRunningProps); @@ -316,6 +323,7 @@ public void testUpdateCacheFrequencyWithCreateTableAndViewOnDiffConns() throws E Properties longRunningProps = new Properties(); longRunningProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS); + longRunningProps.put("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); Connection conn1 = DriverManager.getConnection(url, longRunningProps); String url2 = url + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + "LongRunningQueries"; Connection conn2 = DriverManager.getConnection(url2, longRunningProps); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UserDefinedFunctionsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UserDefinedFunctionsIT.java index fa8c8ffe57e..624fda60e6d 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UserDefinedFunctionsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UserDefinedFunctionsIT.java @@ -20,7 +20,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_FUNCTION_TABLE; import static org.apache.phoenix.query.QueryServices.DYNAMIC_JARS_DIR_KEY; -import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL; +import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_ZK; import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR; import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR; import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM; @@ -289,7 +289,7 @@ public static synchronized void doSetup() throws Exception { String clientPort = util.getConfiguration().get(QueryServices.ZOOKEEPER_PORT_ATTRIB); url = - JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + LOCALHOST + JDBC_PROTOCOL_SEPARATOR + JDBC_PROTOCOL_ZK + JDBC_PROTOCOL_SEPARATOR + LOCALHOST + JDBC_PROTOCOL_SEPARATOR + clientPort + JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM; Map props = Maps.newHashMapWithExpectedSize(1); props.put(QueryServices.ALLOW_USER_DEFINED_FUNCTIONS_ATTRIB, "true"); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/iterate/ScannerLeaseRenewalIT.java b/phoenix-core/src/it/java/org/apache/phoenix/iterate/ScannerLeaseRenewalIT.java index 42876eae604..b332b070acc 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/iterate/ScannerLeaseRenewalIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/iterate/ScannerLeaseRenewalIT.java @@ -71,7 +71,7 @@ public static synchronized void setUp() throws Exception { hbaseTestUtil.startMiniCluster(); // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort(); - url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; + url = PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; Properties driverProps = PropertiesUtil.deepCopy(TEST_PROPERTIES); driverProps.put(RENEW_LEASE_THREAD_POOL_SIZE, Long.toString(4)); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/FailoverPhoenixConnectionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/FailoverPhoenixConnectionIT.java index 890529c68ea..7cc4f1b628a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/FailoverPhoenixConnectionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/FailoverPhoenixConnectionIT.java @@ -240,7 +240,7 @@ public void testStatementClosedAfterStandby() throws Exception { */ @Test(timeout = 300000) public void testNonHAConnectionNotClosedAfterFailover() throws Exception { - String firstUrl = String.format("jdbc:phoenix:%s", CLUSTERS.getUrl1()); + String firstUrl = String.format("jdbc:phoenix+zk:%s", CLUSTERS.getUrl1()); // This is a vanilla Phoenix connection without using high availability (HA) feature. Connection phoenixConn = DriverManager.getConnection(firstUrl, new Properties()); Connection failoverConn = createFailoverConnection(); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HighAvailabilityGroupIT.java b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HighAvailabilityGroupIT.java index f7a99ba92a8..83c906218bf 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HighAvailabilityGroupIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/HighAvailabilityGroupIT.java @@ -47,6 +47,7 @@ import org.apache.phoenix.exception.SQLExceptionCode; import org.apache.phoenix.jdbc.ClusterRoleRecord.ClusterRole; import org.apache.phoenix.jdbc.HighAvailabilityTestingUtility.HBaseTestingUtilityPair; +import org.apache.phoenix.util.PhoenixRuntime; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -611,7 +612,7 @@ public void testFallbackToSingleConnection() throws Exception { if (CLUSTERS.getUrl1().compareTo(CLUSTERS.getUrl2()) > 0) { firstClusterUrl = CLUSTERS.getUrl2(); } - assertEquals(firstClusterUrl, ((PhoenixConnection) conn).getURL()); + assertEquals(PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + firstClusterUrl, ((PhoenixConnection) conn).getURL()); doTestBasicOperationsWithConnection(conn, tableName, haGroupName2); } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/LoggingSingleConnectionLimiterIT.java b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/LoggingSingleConnectionLimiterIT.java index f5b1330defd..e81908cc872 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/LoggingSingleConnectionLimiterIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/LoggingSingleConnectionLimiterIT.java @@ -64,6 +64,7 @@ public static void doSetup() throws Exception { conf.set(QueryServices.INTERNAL_CONNECTION_MAX_ALLOWED_CONNECTIONS, String.valueOf(20)); conf.set(PhoenixHAExecutorServiceProvider.HA_MAX_POOL_SIZE, String.valueOf(5)); conf.set(PhoenixHAExecutorServiceProvider.HA_MAX_QUEUE_SIZE, String.valueOf(30)); + conf.set("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); return conf; } @@ -74,6 +75,7 @@ public static void doSetup() throws Exception { conf.set(QueryServices.INTERNAL_CONNECTION_MAX_ALLOWED_CONNECTIONS, String.valueOf(20)); conf.set(PhoenixHAExecutorServiceProvider.HA_MAX_POOL_SIZE, String.valueOf(5)); conf.set(PhoenixHAExecutorServiceProvider.HA_MAX_QUEUE_SIZE, String.valueOf(30)); + conf.set("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); Configuration copy = new Configuration(conf); copy.addResource(confToClone); return copy; @@ -90,9 +92,10 @@ public static void doSetup() throws Exception { DriverManager.registerDriver(PhoenixDriver.INSTANCE); DriverManager.registerDriver(new PhoenixTestDriver()); String profileName = "setup"; - final String urlWithPrinc = url + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + profileName - + PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR; Properties props = new Properties(); + final String urlWithPrinc = + ConnectionInfo.createNoLogin(url, null, props).withPrincipal("nocache") + .toUrl(); try (Connection connection = DriverManager.getConnection(urlWithPrinc, props)) { try (Statement statement = connection.createStatement()) { diff --git a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/SecureUserConnectionsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/SecureUserConnectionsIT.java index 47d7c0424be..8321c58efde 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/SecureUserConnectionsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/SecureUserConnectionsIT.java @@ -99,6 +99,7 @@ public static synchronized void setupKdc() throws Exception { conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); conf.set(User.HBASE_SECURITY_CONF_KEY, "kerberos"); conf.setBoolean(User.HBASE_SECURITY_AUTHORIZATION_CONF_KEY, true); + conf.set("hbase.client.registry.impl", ZKConnectionInfo.ZK_REGISTRY_NAME); UserGroupInformation.setConfiguration(conf); // Clear the cached singletons so we can inject our own. diff --git a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java index 8c007df082f..d603bed1d7e 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java @@ -1030,7 +1030,7 @@ public void change(long delta) { public void testGetConnectionsForSameUrlConcurrently() throws Exception { // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver String zkQuorum = "localhost:" + getUtility().getZkCluster().getClientPort(); - String url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; + String url = PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; ExecutorService exec = Executors.newFixedThreadPool(10); try { GLOBAL_HCONNECTIONS_COUNTER.getMetric().reset(); @@ -1064,7 +1064,7 @@ public void testGetConnectionsThrottledForSameUrl() throws Exception { int maxConnections = attemptedPhoenixConnections -1; List connections = Lists.newArrayList(); String zkQuorum = "localhost:" + getUtility().getZkCluster().getClientPort(); - String url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum + + String url = PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum + ':' + CUSTOM_URL_STRING + '=' + "throttletest"; Properties props = new Properties(); @@ -1118,7 +1118,7 @@ public void testGetConnectionsFailedCounter() throws Exception { int maxConnections = attemptedPhoenixConnections - 4; List connections = Lists.newArrayList(); String zkQuorum = "localhost:" + getUtility().getZkCluster().getClientPort(); - String url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum + + String url = PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum + ':' + CUSTOM_URL_STRING + '=' + "FailedCounterTest"; Properties props = new Properties(); props.setProperty(QueryServices.CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS, Integer.toString(maxConnections)); @@ -1170,7 +1170,7 @@ public void testGetConnectionsFailedCounter() throws Exception { props1.setProperty(HBASE_CLIENT_RETRIES_NUMBER, Integer.toString(2)); props1.setProperty("zookeeper.recovery.retry", Integer.toString(2)); try { - DriverManager.getConnection(PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + "jdbcthisIsBadZk", props1); + DriverManager.getConnection(PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + "jdbcthisIsBadZk", props1); } catch (Exception e) { assertEquals(4, GLOBAL_FAILED_PHOENIX_CONNECTIONS.getMetric().getValue()); assertEquals(attemptedPhoenixConnections + 1, GLOBAL_PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER.getMetric().getValue()); @@ -1183,7 +1183,7 @@ public void testGetConnectionsFailedCounter() throws Exception { public void testGetConnectionsForDifferentTenantsConcurrently() throws Exception { // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver String zkQuorum = "localhost:" + getUtility().getZkCluster().getClientPort(); - String url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; + String url = PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; ExecutorService exec = Executors.newFixedThreadPool(10); try { GLOBAL_HCONNECTIONS_COUNTER.getMetric().reset(); @@ -1218,7 +1218,7 @@ public void testGetConnectionsWithDifferentJDBCParamsConcurrently() throws Exce ExecutorService exec = Executors.newFixedThreadPool(4); // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver String zkQuorum = "localhost:" + getUtility().getZkCluster().getClientPort(); - String baseUrl = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; + String baseUrl = PhoenixRuntime.JDBC_PROTOCOL_ZK + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum; int numConnections = 20; List> callables = new ArrayList<>(numConnections); List> futures = new ArrayList<>(numConnections); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixTableLevelMetricsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixTableLevelMetricsIT.java index 0031957cfa3..9d1b33a2ba5 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixTableLevelMetricsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixTableLevelMetricsIT.java @@ -181,7 +181,7 @@ public class PhoenixTableLevelMetricsIT extends BaseTest { hbaseTestUtil.startMiniCluster(1, 1, null, null, DelayedOrFailingRegionServer.class); // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver String zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort(); - url = PhoenixRuntime.JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + zkQuorum; + url = PhoenixRuntime.JDBC_PROTOCOL_ZK + JDBC_PROTOCOL_SEPARATOR + zkQuorum; // Add our own driver Map props = Maps.newHashMapWithExpectedSize(1); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/query/MaxConcurrentConnectionsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/query/MaxConcurrentConnectionsIT.java index dacd07ee199..43065582ff8 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/query/MaxConcurrentConnectionsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/query/MaxConcurrentConnectionsIT.java @@ -67,7 +67,7 @@ public static void setUp() throws Exception { hbaseTestUtil.startMiniCluster(1,1,null,null,DelayedRegionServer.class); // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver String zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort(); - url = PhoenixRuntime.JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + zkQuorum + + url = PhoenixRuntime.JDBC_PROTOCOL_ZK + JDBC_PROTOCOL_SEPARATOR + zkQuorum + JDBC_PROTOCOL_SEPARATOR + "uniqueConn=A"; DriverManager.registerDriver(PhoenixDriver.INSTANCE); DriverManager.registerDriver(new PhoenixTestDriver()); diff --git a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriverTest.java b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriverTest.java index fe439d7462a..1c92c53ec6a 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriverTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriverTest.java @@ -41,6 +41,9 @@ public class PhoenixEmbeddedDriverTest { @Test public void testGetZKConnectionInfo() throws SQLException { Configuration config = HBaseFactoryProvider.getConfigurationFactory().getConfiguration(); + // Need to set explicitly for HBase 3.x + config.set("hbase.client.registry.impl", + "org.apache.hadoop.hbase.client.ZKConnectionRegistry"); String defaultQuorum = config.get(HConstants.ZOOKEEPER_QUORUM); for (String protocol : new String[] { "phoenix", "phoenix+zk" }) { @@ -130,7 +133,7 @@ public void testGetZKConnectionInfo() throws SQLException { int pos = 0; try { ZKConnectionInfo info = - (ZKConnectionInfo) ConnectionInfo.create(urls[i], null, null); + (ZKConnectionInfo) ConnectionInfo.create(urls[i], config, null, null); String[] parts = partsList[i]; if (parts.length > pos) { assertEquals(parts[pos], info.getZkHosts()); diff --git a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixHAAdminToolTest.java b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixHAAdminToolTest.java index 9b463551715..eeafec80ba6 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixHAAdminToolTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixHAAdminToolTest.java @@ -276,14 +276,14 @@ public void testGetZookeeperQuorum() { Configuration conf = HBaseConfiguration.create(); // default local ZK is 127.0.0.1:2181:/hbase final String localZk = String.format("127.0.0.1:%d:%s", - HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); + HConstants.DEFAULT_ZOOKEEPER_CLIENT_PORT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); assertEquals(localZk, getLocalZkUrl(conf)); // set host name only; use default port and znode parent final String host = "foobar"; conf.set(HConstants.ZOOKEEPER_QUORUM, "foobar"); final String expectedLocalZk = String.format("%s:%d:%s", host, - HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); + HConstants.DEFAULT_ZOOKEEPER_CLIENT_PORT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); assertEquals(expectedLocalZk, getLocalZkUrl(conf)); // set host name and port; use default znode parent