This is an automated email from the ASF dual-hosted git repository. shahrs87 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push: new 22b0b346e6 PHOENIX-7243 : Add connectionType property to ConnectionInfo (#1839) 22b0b346e6 is described below commit 22b0b346e6de3f78997ad030eb88306d5c75be1d Author: palash <palashc...@gmail.com> AuthorDate: Thu Mar 7 11:11:49 2024 -0800 PHOENIX-7243 : Add connectionType property to ConnectionInfo (#1839) --- .../phoenix/jdbc/AbstractRPCConnectionInfo.java | 4 ++-- .../java/org/apache/phoenix/jdbc/ConnectionInfo.java | 19 ++++++++++++++++++- .../org/apache/phoenix/jdbc/MasterConnectionInfo.java | 8 ++++---- .../org/apache/phoenix/jdbc/RPCConnectionInfo.java | 9 ++++----- .../org/apache/phoenix/jdbc/ZKConnectionInfo.java | 9 +++++---- .../org/apache/phoenix/end2end/PhoenixDriverIT.java | 17 ++++++++++++++++- .../org/apache/phoenix/jdbc/PhoenixTestDriverIT.java | 19 +++++++++++++++++++ 7 files changed, 68 insertions(+), 17 deletions(-) diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/AbstractRPCConnectionInfo.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/AbstractRPCConnectionInfo.java index 0e4920c4c9..1a62c69fbb 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/AbstractRPCConnectionInfo.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/AbstractRPCConnectionInfo.java @@ -45,8 +45,8 @@ public abstract class AbstractRPCConnectionInfo extends ConnectionInfo { } protected AbstractRPCConnectionInfo(boolean isConnectionless, String principal, String keytab, - User user, String haGroup) { - super(isConnectionless, principal, keytab, user, haGroup); + User user, String haGroup, ConnectionType connectionType) { + super(isConnectionless, principal, keytab, user, haGroup, connectionType); } @Override diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ConnectionInfo.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ConnectionInfo.java index 3acdfa8f6a..945060c153 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ConnectionInfo.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ConnectionInfo.java @@ -36,6 +36,7 @@ import org.apache.phoenix.exception.SQLExceptionInfo; import org.apache.phoenix.query.HBaseFactoryProvider; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.util.PhoenixRuntime; +import org.apache.phoenix.util.QueryUtil; import org.apache.phoenix.util.ReadOnlyProps; import org.slf4j.LoggerFactory; @@ -87,15 +88,17 @@ public abstract class ConnectionInfo { protected final String keytab; protected final User user; protected final String haGroup; + protected final ConnectionType connectionType; protected ConnectionInfo(boolean isConnectionless, String principal, String keytab, User user, - String haGroup) { + String haGroup, ConnectionType connectionType) { super(); this.isConnectionless = isConnectionless; this.principal = principal; this.keytab = keytab; this.user = user; this.haGroup = haGroup; + this.connectionType = connectionType; } protected static String unescape(String escaped) { @@ -330,6 +333,9 @@ public abstract class ConnectionInfo { if (haGroup == null) { if (other.haGroup != null) return false; } else if (!haGroup.equals(other.haGroup)) return false; + if (!connectionType.equals(other.connectionType)) { + return false; + } return true; } @@ -342,6 +348,7 @@ public abstract class ConnectionInfo { result = prime * result + ((haGroup == null) ? 0 : haGroup.hashCode()); // `user` is guaranteed to be non-null result = prime * result + user.hashCode(); + result = prime * result + connectionType.hashCode(); return result; } @@ -369,6 +376,7 @@ public abstract class ConnectionInfo { protected User user; protected String haGroup; protected boolean doNotLogin = false; + protected ConnectionType connectionType; // Only used for building, not part of ConnectionInfo protected final String url; @@ -381,6 +389,10 @@ public abstract class ConnectionInfo { this.url = url; this.props = props; this.info = info; + this.connectionType = ConnectionType.CLIENT; + if (info != null && Boolean.valueOf(info.getProperty(QueryUtil.IS_SERVER_CONNECTION))) { + this.connectionType = ConnectionType.SERVER; + } } protected abstract ConnectionInfo create() throws SQLException; @@ -561,4 +573,9 @@ public abstract class ConnectionInfo { return result; } } + + public enum ConnectionType { + CLIENT, + SERVER + } } diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/MasterConnectionInfo.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/MasterConnectionInfo.java index 9b74a265a8..aaf409819d 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/MasterConnectionInfo.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/MasterConnectionInfo.java @@ -37,8 +37,8 @@ public class MasterConnectionInfo extends AbstractRPCConnectionInfo { "org.apache.hadoop.hbase.client.MasterRegistry"; protected MasterConnectionInfo(boolean isConnectionless, String principal, String keytab, - User user, String haGroup, String bootstrapServers) { - super(isConnectionless, principal, keytab, user, haGroup); + User user, String haGroup, String bootstrapServers, ConnectionType connectionType) { + super(isConnectionless, principal, keytab, user, haGroup, connectionType); this.bootstrapServers = bootstrapServers; } @@ -71,7 +71,7 @@ public class MasterConnectionInfo extends AbstractRPCConnectionInfo { @Override public ConnectionInfo withPrincipal(String principal) { return new MasterConnectionInfo(isConnectionless, principal, keytab, user, - haGroup, bootstrapServers); + haGroup, bootstrapServers, connectionType); } /** @@ -98,7 +98,7 @@ public class MasterConnectionInfo extends AbstractRPCConnectionInfo { @Override protected ConnectionInfo build() { return new MasterConnectionInfo(isConnectionless, principal, keytab, user, haGroup, - hostsList); + hostsList, connectionType); } public static boolean isMaster(Configuration config, ReadOnlyProps props, Properties info) { diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/RPCConnectionInfo.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/RPCConnectionInfo.java index 80d7269ac3..1744fbfd92 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/RPCConnectionInfo.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/RPCConnectionInfo.java @@ -22,7 +22,6 @@ import java.util.Map; import java.util.Properties; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.security.User; import org.apache.hbase.thirdparty.com.google.common.base.Strings; import org.apache.phoenix.util.PhoenixRuntime; @@ -41,8 +40,8 @@ public class RPCConnectionInfo extends AbstractRPCConnectionInfo { "org.apache.hadoop.hbase.client.RpcConnectionRegistry"; protected RPCConnectionInfo(boolean isConnectionless, String principal, String keytab, - User user, String haGroup, String bootstrapServers) { - super(isConnectionless, principal, keytab, user, haGroup); + User user, String haGroup, String bootstrapServers, ConnectionType connectionType) { + super(isConnectionless, principal, keytab, user, haGroup, connectionType); this.bootstrapServers = bootstrapServers; } @@ -101,7 +100,7 @@ public class RPCConnectionInfo extends AbstractRPCConnectionInfo { @Override public ConnectionInfo withPrincipal(String principal) { return new RPCConnectionInfo(isConnectionless, principal, keytab, user, - haGroup, bootstrapServers); + haGroup, bootstrapServers, connectionType); } /** @@ -183,7 +182,7 @@ public class RPCConnectionInfo extends AbstractRPCConnectionInfo { @Override protected ConnectionInfo build() { return new RPCConnectionInfo(isConnectionless, principal, keytab, user, haGroup, - hostsList); + hostsList, connectionType); } public static boolean isRPC(Configuration config, ReadOnlyProps props, Properties info) { diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ZKConnectionInfo.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ZKConnectionInfo.java index 3d9f5f3c62..2ebdee7185 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ZKConnectionInfo.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ZKConnectionInfo.java @@ -43,8 +43,9 @@ public class ZKConnectionInfo extends ConnectionInfo { private final String zkHosts; private ZKConnectionInfo(boolean isConnectionless, String principal, String keytab, User user, - String haGroup, String zkHosts, Integer zkPort, String zkRootNode) { - super(isConnectionless, principal, keytab, user, haGroup); + String haGroup, String zkHosts, Integer zkPort, String zkRootNode, + ConnectionType connectionType) { + super(isConnectionless, principal, keytab, user, haGroup, connectionType); this.zkPort = zkPort; this.zkRootNode = zkRootNode; this.zkHosts = zkHosts; @@ -153,7 +154,7 @@ public class ZKConnectionInfo extends ConnectionInfo { @Override public ConnectionInfo withPrincipal(String principal) { return new ZKConnectionInfo(isConnectionless, principal, keytab, user, - haGroup, zkHosts, zkPort, zkRootNode); + haGroup, zkHosts, zkPort, zkRootNode, connectionType); } /** @@ -277,7 +278,7 @@ public class ZKConnectionInfo extends ConnectionInfo { protected ConnectionInfo build() { return new ZKConnectionInfo(isConnectionless, principal, keytab, user, haGroup, zkHosts, - zkPort, zkRootNode); + zkPort, zkRootNode, connectionType); } @Override 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 71d30eac5e..d85df7e68b 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 @@ -25,6 +25,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM; import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TENANT_ID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -43,12 +44,14 @@ import org.apache.phoenix.jdbc.PhoenixConnection; import org.apache.phoenix.jdbc.PhoenixDriver; import org.apache.phoenix.jdbc.PhoenixStatement; import org.apache.phoenix.query.BaseTest; +import org.apache.phoenix.query.ConnectionQueryServices; import org.apache.phoenix.query.QueryConstants; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesOptions; import org.apache.phoenix.schema.PTable; import org.apache.phoenix.schema.PTable.LinkType; import org.apache.phoenix.util.PhoenixRuntime; +import org.apache.phoenix.util.QueryUtil; import org.apache.phoenix.util.SchemaUtil; import org.apache.phoenix.util.UpgradeUtil; import org.junit.BeforeClass; @@ -60,10 +63,12 @@ public class PhoenixDriverIT extends BaseTest { private static HBaseTestingUtility hbaseTestUtil; private static String zkQuorum; + + private static Configuration conf; @BeforeClass public static synchronized void setUp() throws Exception { - Configuration conf = HBaseConfiguration.create(); + conf = HBaseConfiguration.create(); hbaseTestUtil = new HBaseTestingUtility(conf); setUpConfigForMiniCluster(conf); conf.set(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS); @@ -234,4 +239,14 @@ public class PhoenixDriverIT extends BaseTest { assertFalse(rs.next()); return physicalTableName; } + + @Test + public void testDifferentQueryServiceForServerConnection() throws Exception { + Properties props = new Properties(); + Connection conn = DriverManager.getConnection(QueryUtil.getConnectionUrl(props, conf), props); + Connection serverConn = QueryUtil.getConnectionOnServer(props, conf); + ConnectionQueryServices cqs = conn.unwrap(PhoenixConnection.class).getQueryServices(); + ConnectionQueryServices serverCqs = serverConn.unwrap(PhoenixConnection.class).getQueryServices(); + assertNotSame(cqs, serverCqs); + } } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/PhoenixTestDriverIT.java b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/PhoenixTestDriverIT.java index 9dd0d741d9..18052e3549 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/PhoenixTestDriverIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/PhoenixTestDriverIT.java @@ -17,6 +17,7 @@ */ package org.apache.phoenix.jdbc; +import org.apache.phoenix.end2end.ConnectionQueryServicesTestImpl; import org.apache.phoenix.end2end.NeedsOwnMiniClusterTest; import org.apache.phoenix.query.BaseTest; import org.apache.phoenix.query.ConnectionQueryServices; @@ -121,4 +122,22 @@ public class PhoenixTestDriverIT extends BaseTest { // expected since this connection was created using a different CQSI. } } + + /** + * Create 2 connections with same url and properties but one is a server connection. + * Verify that the connections are from different CQS objects. + */ + @Test + public void testDifferentCQSForServerConnection() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + String url = QueryUtil.getConnectionUrl(props, config); + try (Connection conn1 = DriverManager.getConnection(url); + Connection conn2 = QueryUtil.getConnectionOnServer(props, config)) { + ConnectionQueryServices cqs1 = conn1.unwrap(PhoenixConnection.class).getQueryServices(); + ConnectionQueryServices cqs2 = conn2.unwrap(PhoenixConnection.class).getQueryServices(); + Assert.assertTrue(cqs1 instanceof ConnectionQueryServicesTestImpl); + Assert.assertTrue(cqs2 instanceof ConnectionQueryServicesTestImpl); + Assert.assertNotEquals("Server connection should have a different CQS.", cqs1, cqs2); + } + } }