From 3c54c863e617a9bd89fe52f747f319c469389cca Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Fri, 1 Aug 2025 20:52:57 +0530 Subject: [PATCH 1/7] connection creation time --- .../apache/phoenix/jdbc/PhoenixDriver.java | 4 +- .../phoenix/jdbc/PhoenixEmbeddedDriver.java | 69 ++++++++++++++----- .../apache/phoenix/monitoring/MetricType.java | 2 + .../ConnectionQueryServicesMetrics.java | 9 ++- .../ConnectionQueryServicesMetricsIT.java | 33 ++++++--- ...ectionQueryServicesMetricsManagerTest.java | 27 +++++++- 6 files changed, 107 insertions(+), 37 deletions(-) diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java index 953bbc5bd57..f3784183555 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java @@ -41,6 +41,7 @@ import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesImpl; import org.apache.phoenix.query.QueryServicesOptions; +import org.apache.phoenix.util.EnvironmentEdgeManager; import org.apache.phoenix.util.PropertiesUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -205,6 +206,7 @@ public boolean acceptsURL(String url) throws SQLException { @Override public Connection connect(String url, Properties info) throws SQLException { + long connectionStartTime = EnvironmentEdgeManager.currentTimeMillis(); GLOBAL_PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER.increment(); if (!acceptsURL(url)) { GLOBAL_FAILED_PHOENIX_CONNECTIONS.increment(); @@ -213,7 +215,7 @@ public Connection connect(String url, Properties info) throws SQLException { lockInterruptibly(LockMode.READ); try { checkClosed(); - return createConnection(url, info); + return createConnection(url, info, connectionStartTime); } catch (SQLException sqlException) { if (sqlException.getErrorCode() != SQLExceptionCode.NEW_CONNECTION_THROTTLED.getErrorCode()) { GLOBAL_FAILED_PHOENIX_CONNECTIONS.increment(); diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java index b5bbe2ea552..ea1d416fd8a 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java @@ -17,6 +17,8 @@ */ package org.apache.phoenix.jdbc; +import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTION_CREATION_TIME_MS; +import static org.apache.phoenix.query.QueryServices.QUERY_SERVICES_NAME; import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM; import java.sql.Connection; @@ -24,17 +26,18 @@ import java.sql.DriverPropertyInfo; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; +import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.logging.Logger; import javax.annotation.concurrent.Immutable; import org.apache.phoenix.coprocessorclient.MetaDataProtocol; +import org.apache.phoenix.monitoring.ConnectionQueryServicesMetric; +import org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesMetricsManager; import org.apache.phoenix.query.ConnectionQueryServices; import org.apache.phoenix.query.QueryServices; -import org.apache.phoenix.util.PhoenixRuntime; -import org.apache.phoenix.util.PropertiesUtil; -import org.apache.phoenix.util.ReadOnlyProps; -import org.apache.phoenix.util.SQLCloseable; +import org.apache.phoenix.util.*; import org.apache.phoenix.thirdparty.com.google.common.collect.ImmutableMap; @@ -119,31 +122,59 @@ public boolean acceptsURL(String url) throws SQLException { @Override public Connection connect(String url, Properties info) throws SQLException { + long connectionStartTime = EnvironmentEdgeManager.currentTimeMillis(); if (!acceptsURL(url)) { return null; } - return createConnection(url, info); + return createConnection(url, info, connectionStartTime); } - protected final Connection createConnection(String url, Properties info) throws SQLException { + protected final Connection createConnection(String url, Properties info, + long connectionCreationTime) throws SQLException { Properties augmentedInfo = PropertiesUtil.deepCopy(info); augmentedInfo.putAll(getDefaultProps().asMap()); - if (url.contains("|")) { - // Get HAURLInfo to pass it to connection creation - HAURLInfo haurlInfo = HighAvailabilityGroup.getUrlInfo(url, augmentedInfo); - // High availability connection using two clusters - Optional haGroup = HighAvailabilityGroup.get(url, augmentedInfo); - if (haGroup.isPresent()) { - return haGroup.get().connect(augmentedInfo, haurlInfo); - } else { - // If empty HA group is returned, fall back to single cluster. - url = HighAvailabilityGroup.getFallbackCluster(url, info).orElseThrow( - () -> new SQLException("HA group can not be initialized, fallback to single cluster")); + Connection connection = null; + try { + if (url.contains("|")) { + // Get HAURLInfo to pass it to connection creation + HAURLInfo haurlInfo = HighAvailabilityGroup.getUrlInfo(url, augmentedInfo); + // High availability connection using two clusters + Optional haGroup = HighAvailabilityGroup.get(url, augmentedInfo); + if (haGroup.isPresent()) { + connection = haGroup.get().connect(augmentedInfo, haurlInfo); + setPhoenixConnectionTime(connectionCreationTime, connection); + return connection; + } else { + // If empty HA group is returned, fall back to single cluster. + url = HighAvailabilityGroup.getFallbackCluster(url, info).orElseThrow( + () -> new SQLException( + "HA group can not be initialized, fallback to single cluster")); + } + } + ConnectionQueryServices cqs = getConnectionQueryServices(url, augmentedInfo); + connection = cqs.connect(url, augmentedInfo); + setPhoenixConnectionTime(connectionCreationTime, connection); + Map> metrics = + ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); + if (!metrics.isEmpty()) { + List serviceMetrics = metrics.get("DEFAULT_CQSN"); + } + return connection; + } catch (SQLException e) { + if (connection != null) { + connection.close(); } + throw e; } - ConnectionQueryServices cqs = getConnectionQueryServices(url, augmentedInfo); - return cqs.connect(url, augmentedInfo); + } + + private void setPhoenixConnectionTime(long connectionCreationTime, Connection connection) { + String connectionQueryServiceName = + ((PhoenixConnection) connection).getQueryServices().getConfiguration() + .get(QUERY_SERVICES_NAME); + ConnectionQueryServicesMetricsManager.updateMetrics(connectionQueryServiceName, + PHOENIX_CONNECTION_CREATION_TIME_MS, connectionCreationTime); } /** diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java index 8ee8de69718..aaf6883223d 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java @@ -228,6 +228,8 @@ public enum MetricType { PHOENIX_CONNECTIONS_FAILED_COUNTER("cf", "Number of client Phoenix Connections Failed to open" + ", not including throttled connections", LogLevel.OFF, PLong.INSTANCE), + PHOENIX_CONNECTION_CREATION_TIME_MS("cct", + "Time spent in creating Phoenix connections in milliseconds", LogLevel.OFF, PLong.INSTANCE), CLIENT_METADATA_CACHE_MISS_COUNTER("cmcm", "Number of cache misses for the CQSI cache.", LogLevel.DEBUG, PLong.INSTANCE), CLIENT_METADATA_CACHE_HIT_COUNTER("cmch", "Number of cache hits for the CQSI cache.", diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java index 575d38530eb..8c3ac719d27 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java @@ -17,10 +17,6 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; -import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -30,6 +26,8 @@ import org.apache.phoenix.monitoring.ConnectionQueryServicesMetricImpl; import org.apache.phoenix.monitoring.MetricType; +import static org.apache.phoenix.monitoring.MetricType.*; + /** * Class for Connection Query Service Metrics. */ @@ -42,7 +40,8 @@ public enum QueryServiceMetrics { CONNECTION_QUERY_SERVICE_OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER( OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER), CONNECTION_QUERY_SERVICE_PHOENIX_CONNECTIONS_THROTTLED_COUNTER( - PHOENIX_CONNECTIONS_THROTTLED_COUNTER); + PHOENIX_CONNECTIONS_THROTTLED_COUNTER), + CONNECTION_QUERY_SERVICE_CREATION_TIME(PHOENIX_CONNECTION_CREATION_TIME_MS); private MetricType metricType; private ConnectionQueryServicesMetric metric; diff --git a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java index 54d53afdf6d..d9f752bc17c 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java @@ -17,21 +17,15 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; -import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.*; import static org.apache.phoenix.query.QueryServices.CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS; import static org.apache.phoenix.query.QueryServices.CONNECTION_QUERY_SERVICE_METRICS_ENABLED; import static org.apache.phoenix.query.QueryServices.INTERNAL_CONNECTION_MAX_ALLOWED_CONNECTIONS; import static org.apache.phoenix.query.QueryServices.QUERY_SERVICES_NAME; import static org.apache.phoenix.util.PhoenixRuntime.clearAllConnectionQueryServiceMetrics; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -222,6 +216,27 @@ public void testMultipleCQSIMetricsInParallel() throws Exception { assertEquals("Number of passing CSQI Metrics check should be : ", 4, counter.get()); } + @Test + public void testConnectionTime() { + Map> metrics = + ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); + List serviceMetrics = metrics.get("DEFAULT_CQSN"); + assertNotNull("No metrics found for service: DEFAULT_CQSN", serviceMetrics); + + // Find connection creation time metric + boolean foundMetric = false; + for (ConnectionQueryServicesMetric metric : serviceMetrics) { + System.out.println("Found metric: " + metric.getMetricType() + " = " + metric.getValue()); + if (metric.getMetricType() == PHOENIX_CONNECTION_CREATION_TIME_MS) { + assertTrue("Connection creation time should be >= 0", metric.getValue() >= 0); + foundMetric = true; + break; + } + } + assertTrue("Connection creation time metric not found", foundMetric); + + } + private void checkConnectionQueryServiceMetricsValues(String queryServiceName) throws Exception { String CREATE_TABLE_DDL = "CREATE TABLE IF NOT EXISTS %s (K VARCHAR(10) NOT NULL" + " PRIMARY KEY, V VARCHAR)"; diff --git a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java index 86fc007b906..039b7be051f 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java @@ -17,13 +17,12 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; -import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.*; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.connectionQueryServiceNames; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.openInternalPhoenixConnCounter; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.openPhoenixConnCounter; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.phoenixConnThrottledCounter; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; @@ -32,6 +31,7 @@ import org.apache.phoenix.monitoring.ConnectionQueryServicesMetric; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesOptions; +import org.apache.phoenix.util.PhoenixRuntime; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; @@ -101,6 +101,27 @@ public void testHistogramMetricsForOpenPhoenixConnectionCounter() { } } + @Test + public void testConnectionTime() { + Map> metrics = + ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); + List serviceMetrics = metrics.get("DEFAULT_CQSN"); + assertNotNull("No metrics found for service: DEFAULT_CQSN", serviceMetrics); + + // Find connection creation time metric + boolean foundMetric = false; + for (ConnectionQueryServicesMetric metric : serviceMetrics) { + System.out.println("Found metric: " + metric.getMetricType() + " = " + metric.getValue()); + if (metric.getMetricType() == PHOENIX_CONNECTION_CREATION_TIME_MS) { + assertTrue("Connection creation time should be >= 0", metric.getValue() >= 0); + foundMetric = true; + break; + } + } + assertTrue("Connection creation time metric not found", foundMetric); + + } + private void updateMetricsAndHistogram(long counter, String connectionQueryServiceName) { ConnectionQueryServicesMetricsManager.updateMetrics(connectionQueryServiceName, OPEN_PHOENIX_CONNECTIONS_COUNTER, counter); From c97f7e024c9faf8ebcac38a37d0749572a795be8 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Fri, 1 Aug 2025 20:53:22 +0530 Subject: [PATCH 2/7] Revert "connection creation time" This reverts commit 3c54c863e617a9bd89fe52f747f319c469389cca. --- .../apache/phoenix/jdbc/PhoenixDriver.java | 4 +- .../phoenix/jdbc/PhoenixEmbeddedDriver.java | 69 +++++-------------- .../apache/phoenix/monitoring/MetricType.java | 2 - .../ConnectionQueryServicesMetrics.java | 9 +-- .../ConnectionQueryServicesMetricsIT.java | 33 +++------ ...ectionQueryServicesMetricsManagerTest.java | 27 +------- 6 files changed, 37 insertions(+), 107 deletions(-) diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java index f3784183555..953bbc5bd57 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java @@ -41,7 +41,6 @@ import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesImpl; import org.apache.phoenix.query.QueryServicesOptions; -import org.apache.phoenix.util.EnvironmentEdgeManager; import org.apache.phoenix.util.PropertiesUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -206,7 +205,6 @@ public boolean acceptsURL(String url) throws SQLException { @Override public Connection connect(String url, Properties info) throws SQLException { - long connectionStartTime = EnvironmentEdgeManager.currentTimeMillis(); GLOBAL_PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER.increment(); if (!acceptsURL(url)) { GLOBAL_FAILED_PHOENIX_CONNECTIONS.increment(); @@ -215,7 +213,7 @@ public Connection connect(String url, Properties info) throws SQLException { lockInterruptibly(LockMode.READ); try { checkClosed(); - return createConnection(url, info, connectionStartTime); + return createConnection(url, info); } catch (SQLException sqlException) { if (sqlException.getErrorCode() != SQLExceptionCode.NEW_CONNECTION_THROTTLED.getErrorCode()) { GLOBAL_FAILED_PHOENIX_CONNECTIONS.increment(); diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java index ea1d416fd8a..b5bbe2ea552 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java @@ -17,8 +17,6 @@ */ package org.apache.phoenix.jdbc; -import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTION_CREATION_TIME_MS; -import static org.apache.phoenix.query.QueryServices.QUERY_SERVICES_NAME; import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM; import java.sql.Connection; @@ -26,18 +24,17 @@ import java.sql.DriverPropertyInfo; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; -import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.logging.Logger; import javax.annotation.concurrent.Immutable; import org.apache.phoenix.coprocessorclient.MetaDataProtocol; -import org.apache.phoenix.monitoring.ConnectionQueryServicesMetric; -import org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesMetricsManager; import org.apache.phoenix.query.ConnectionQueryServices; import org.apache.phoenix.query.QueryServices; -import org.apache.phoenix.util.*; +import org.apache.phoenix.util.PhoenixRuntime; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SQLCloseable; import org.apache.phoenix.thirdparty.com.google.common.collect.ImmutableMap; @@ -122,59 +119,31 @@ public boolean acceptsURL(String url) throws SQLException { @Override public Connection connect(String url, Properties info) throws SQLException { - long connectionStartTime = EnvironmentEdgeManager.currentTimeMillis(); if (!acceptsURL(url)) { return null; } - return createConnection(url, info, connectionStartTime); + return createConnection(url, info); } - protected final Connection createConnection(String url, Properties info, - long connectionCreationTime) throws SQLException { + protected final Connection createConnection(String url, Properties info) throws SQLException { Properties augmentedInfo = PropertiesUtil.deepCopy(info); augmentedInfo.putAll(getDefaultProps().asMap()); - Connection connection = null; - try { - if (url.contains("|")) { - // Get HAURLInfo to pass it to connection creation - HAURLInfo haurlInfo = HighAvailabilityGroup.getUrlInfo(url, augmentedInfo); - // High availability connection using two clusters - Optional haGroup = HighAvailabilityGroup.get(url, augmentedInfo); - if (haGroup.isPresent()) { - connection = haGroup.get().connect(augmentedInfo, haurlInfo); - setPhoenixConnectionTime(connectionCreationTime, connection); - return connection; - } else { - // If empty HA group is returned, fall back to single cluster. - url = HighAvailabilityGroup.getFallbackCluster(url, info).orElseThrow( - () -> new SQLException( - "HA group can not be initialized, fallback to single cluster")); - } - } - ConnectionQueryServices cqs = getConnectionQueryServices(url, augmentedInfo); - connection = cqs.connect(url, augmentedInfo); - setPhoenixConnectionTime(connectionCreationTime, connection); - Map> metrics = - ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); - if (!metrics.isEmpty()) { - List serviceMetrics = metrics.get("DEFAULT_CQSN"); - } - return connection; - } catch (SQLException e) { - if (connection != null) { - connection.close(); + if (url.contains("|")) { + // Get HAURLInfo to pass it to connection creation + HAURLInfo haurlInfo = HighAvailabilityGroup.getUrlInfo(url, augmentedInfo); + // High availability connection using two clusters + Optional haGroup = HighAvailabilityGroup.get(url, augmentedInfo); + if (haGroup.isPresent()) { + return haGroup.get().connect(augmentedInfo, haurlInfo); + } else { + // If empty HA group is returned, fall back to single cluster. + url = HighAvailabilityGroup.getFallbackCluster(url, info).orElseThrow( + () -> new SQLException("HA group can not be initialized, fallback to single cluster")); } - throw e; } - } - - private void setPhoenixConnectionTime(long connectionCreationTime, Connection connection) { - String connectionQueryServiceName = - ((PhoenixConnection) connection).getQueryServices().getConfiguration() - .get(QUERY_SERVICES_NAME); - ConnectionQueryServicesMetricsManager.updateMetrics(connectionQueryServiceName, - PHOENIX_CONNECTION_CREATION_TIME_MS, connectionCreationTime); + ConnectionQueryServices cqs = getConnectionQueryServices(url, augmentedInfo); + return cqs.connect(url, augmentedInfo); } /** diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java index aaf6883223d..8ee8de69718 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java @@ -228,8 +228,6 @@ public enum MetricType { PHOENIX_CONNECTIONS_FAILED_COUNTER("cf", "Number of client Phoenix Connections Failed to open" + ", not including throttled connections", LogLevel.OFF, PLong.INSTANCE), - PHOENIX_CONNECTION_CREATION_TIME_MS("cct", - "Time spent in creating Phoenix connections in milliseconds", LogLevel.OFF, PLong.INSTANCE), CLIENT_METADATA_CACHE_MISS_COUNTER("cmcm", "Number of cache misses for the CQSI cache.", LogLevel.DEBUG, PLong.INSTANCE), CLIENT_METADATA_CACHE_HIT_COUNTER("cmch", "Number of cache hits for the CQSI cache.", diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java index 8c3ac719d27..575d38530eb 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java @@ -17,6 +17,10 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; +import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -26,8 +30,6 @@ import org.apache.phoenix.monitoring.ConnectionQueryServicesMetricImpl; import org.apache.phoenix.monitoring.MetricType; -import static org.apache.phoenix.monitoring.MetricType.*; - /** * Class for Connection Query Service Metrics. */ @@ -40,8 +42,7 @@ public enum QueryServiceMetrics { CONNECTION_QUERY_SERVICE_OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER( OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER), CONNECTION_QUERY_SERVICE_PHOENIX_CONNECTIONS_THROTTLED_COUNTER( - PHOENIX_CONNECTIONS_THROTTLED_COUNTER), - CONNECTION_QUERY_SERVICE_CREATION_TIME(PHOENIX_CONNECTION_CREATION_TIME_MS); + PHOENIX_CONNECTIONS_THROTTLED_COUNTER); private MetricType metricType; private ConnectionQueryServicesMetric metric; diff --git a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java index d9f752bc17c..54d53afdf6d 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java @@ -17,15 +17,21 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; -import static org.apache.phoenix.monitoring.MetricType.*; +import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; import static org.apache.phoenix.query.QueryServices.CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS; import static org.apache.phoenix.query.QueryServices.CONNECTION_QUERY_SERVICE_METRICS_ENABLED; import static org.apache.phoenix.query.QueryServices.INTERNAL_CONNECTION_MAX_ALLOWED_CONNECTIONS; import static org.apache.phoenix.query.QueryServices.QUERY_SERVICES_NAME; import static org.apache.phoenix.util.PhoenixRuntime.clearAllConnectionQueryServiceMetrics; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -216,27 +222,6 @@ public void testMultipleCQSIMetricsInParallel() throws Exception { assertEquals("Number of passing CSQI Metrics check should be : ", 4, counter.get()); } - @Test - public void testConnectionTime() { - Map> metrics = - ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); - List serviceMetrics = metrics.get("DEFAULT_CQSN"); - assertNotNull("No metrics found for service: DEFAULT_CQSN", serviceMetrics); - - // Find connection creation time metric - boolean foundMetric = false; - for (ConnectionQueryServicesMetric metric : serviceMetrics) { - System.out.println("Found metric: " + metric.getMetricType() + " = " + metric.getValue()); - if (metric.getMetricType() == PHOENIX_CONNECTION_CREATION_TIME_MS) { - assertTrue("Connection creation time should be >= 0", metric.getValue() >= 0); - foundMetric = true; - break; - } - } - assertTrue("Connection creation time metric not found", foundMetric); - - } - private void checkConnectionQueryServiceMetricsValues(String queryServiceName) throws Exception { String CREATE_TABLE_DDL = "CREATE TABLE IF NOT EXISTS %s (K VARCHAR(10) NOT NULL" + " PRIMARY KEY, V VARCHAR)"; diff --git a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java index 039b7be051f..86fc007b906 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java @@ -17,12 +17,13 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; -import static org.apache.phoenix.monitoring.MetricType.*; +import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.connectionQueryServiceNames; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.openInternalPhoenixConnCounter; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.openPhoenixConnCounter; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.phoenixConnThrottledCounter; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; @@ -31,7 +32,6 @@ import org.apache.phoenix.monitoring.ConnectionQueryServicesMetric; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesOptions; -import org.apache.phoenix.util.PhoenixRuntime; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; @@ -101,27 +101,6 @@ public void testHistogramMetricsForOpenPhoenixConnectionCounter() { } } - @Test - public void testConnectionTime() { - Map> metrics = - ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); - List serviceMetrics = metrics.get("DEFAULT_CQSN"); - assertNotNull("No metrics found for service: DEFAULT_CQSN", serviceMetrics); - - // Find connection creation time metric - boolean foundMetric = false; - for (ConnectionQueryServicesMetric metric : serviceMetrics) { - System.out.println("Found metric: " + metric.getMetricType() + " = " + metric.getValue()); - if (metric.getMetricType() == PHOENIX_CONNECTION_CREATION_TIME_MS) { - assertTrue("Connection creation time should be >= 0", metric.getValue() >= 0); - foundMetric = true; - break; - } - } - assertTrue("Connection creation time metric not found", foundMetric); - - } - private void updateMetricsAndHistogram(long counter, String connectionQueryServiceName) { ConnectionQueryServicesMetricsManager.updateMetrics(connectionQueryServiceName, OPEN_PHOENIX_CONNECTIONS_COUNTER, counter); From 53e9a3bfca8dd7e265846cb6080d3ea70058b5be Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Fri, 1 Aug 2025 20:54:52 +0530 Subject: [PATCH 3/7] Revert "Revert "connection creation time"" This reverts commit c97f7e024c9faf8ebcac38a37d0749572a795be8. --- .../apache/phoenix/jdbc/PhoenixDriver.java | 4 +- .../phoenix/jdbc/PhoenixEmbeddedDriver.java | 69 ++++++++++++++----- .../apache/phoenix/monitoring/MetricType.java | 2 + .../ConnectionQueryServicesMetrics.java | 9 ++- .../ConnectionQueryServicesMetricsIT.java | 33 ++++++--- ...ectionQueryServicesMetricsManagerTest.java | 27 +++++++- 6 files changed, 107 insertions(+), 37 deletions(-) diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java index 953bbc5bd57..f3784183555 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java @@ -41,6 +41,7 @@ import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesImpl; import org.apache.phoenix.query.QueryServicesOptions; +import org.apache.phoenix.util.EnvironmentEdgeManager; import org.apache.phoenix.util.PropertiesUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -205,6 +206,7 @@ public boolean acceptsURL(String url) throws SQLException { @Override public Connection connect(String url, Properties info) throws SQLException { + long connectionStartTime = EnvironmentEdgeManager.currentTimeMillis(); GLOBAL_PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER.increment(); if (!acceptsURL(url)) { GLOBAL_FAILED_PHOENIX_CONNECTIONS.increment(); @@ -213,7 +215,7 @@ public Connection connect(String url, Properties info) throws SQLException { lockInterruptibly(LockMode.READ); try { checkClosed(); - return createConnection(url, info); + return createConnection(url, info, connectionStartTime); } catch (SQLException sqlException) { if (sqlException.getErrorCode() != SQLExceptionCode.NEW_CONNECTION_THROTTLED.getErrorCode()) { GLOBAL_FAILED_PHOENIX_CONNECTIONS.increment(); diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java index b5bbe2ea552..ea1d416fd8a 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java @@ -17,6 +17,8 @@ */ package org.apache.phoenix.jdbc; +import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTION_CREATION_TIME_MS; +import static org.apache.phoenix.query.QueryServices.QUERY_SERVICES_NAME; import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM; import java.sql.Connection; @@ -24,17 +26,18 @@ import java.sql.DriverPropertyInfo; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; +import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.logging.Logger; import javax.annotation.concurrent.Immutable; import org.apache.phoenix.coprocessorclient.MetaDataProtocol; +import org.apache.phoenix.monitoring.ConnectionQueryServicesMetric; +import org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesMetricsManager; import org.apache.phoenix.query.ConnectionQueryServices; import org.apache.phoenix.query.QueryServices; -import org.apache.phoenix.util.PhoenixRuntime; -import org.apache.phoenix.util.PropertiesUtil; -import org.apache.phoenix.util.ReadOnlyProps; -import org.apache.phoenix.util.SQLCloseable; +import org.apache.phoenix.util.*; import org.apache.phoenix.thirdparty.com.google.common.collect.ImmutableMap; @@ -119,31 +122,59 @@ public boolean acceptsURL(String url) throws SQLException { @Override public Connection connect(String url, Properties info) throws SQLException { + long connectionStartTime = EnvironmentEdgeManager.currentTimeMillis(); if (!acceptsURL(url)) { return null; } - return createConnection(url, info); + return createConnection(url, info, connectionStartTime); } - protected final Connection createConnection(String url, Properties info) throws SQLException { + protected final Connection createConnection(String url, Properties info, + long connectionCreationTime) throws SQLException { Properties augmentedInfo = PropertiesUtil.deepCopy(info); augmentedInfo.putAll(getDefaultProps().asMap()); - if (url.contains("|")) { - // Get HAURLInfo to pass it to connection creation - HAURLInfo haurlInfo = HighAvailabilityGroup.getUrlInfo(url, augmentedInfo); - // High availability connection using two clusters - Optional haGroup = HighAvailabilityGroup.get(url, augmentedInfo); - if (haGroup.isPresent()) { - return haGroup.get().connect(augmentedInfo, haurlInfo); - } else { - // If empty HA group is returned, fall back to single cluster. - url = HighAvailabilityGroup.getFallbackCluster(url, info).orElseThrow( - () -> new SQLException("HA group can not be initialized, fallback to single cluster")); + Connection connection = null; + try { + if (url.contains("|")) { + // Get HAURLInfo to pass it to connection creation + HAURLInfo haurlInfo = HighAvailabilityGroup.getUrlInfo(url, augmentedInfo); + // High availability connection using two clusters + Optional haGroup = HighAvailabilityGroup.get(url, augmentedInfo); + if (haGroup.isPresent()) { + connection = haGroup.get().connect(augmentedInfo, haurlInfo); + setPhoenixConnectionTime(connectionCreationTime, connection); + return connection; + } else { + // If empty HA group is returned, fall back to single cluster. + url = HighAvailabilityGroup.getFallbackCluster(url, info).orElseThrow( + () -> new SQLException( + "HA group can not be initialized, fallback to single cluster")); + } + } + ConnectionQueryServices cqs = getConnectionQueryServices(url, augmentedInfo); + connection = cqs.connect(url, augmentedInfo); + setPhoenixConnectionTime(connectionCreationTime, connection); + Map> metrics = + ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); + if (!metrics.isEmpty()) { + List serviceMetrics = metrics.get("DEFAULT_CQSN"); + } + return connection; + } catch (SQLException e) { + if (connection != null) { + connection.close(); } + throw e; } - ConnectionQueryServices cqs = getConnectionQueryServices(url, augmentedInfo); - return cqs.connect(url, augmentedInfo); + } + + private void setPhoenixConnectionTime(long connectionCreationTime, Connection connection) { + String connectionQueryServiceName = + ((PhoenixConnection) connection).getQueryServices().getConfiguration() + .get(QUERY_SERVICES_NAME); + ConnectionQueryServicesMetricsManager.updateMetrics(connectionQueryServiceName, + PHOENIX_CONNECTION_CREATION_TIME_MS, connectionCreationTime); } /** diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java index 8ee8de69718..aaf6883223d 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java @@ -228,6 +228,8 @@ public enum MetricType { PHOENIX_CONNECTIONS_FAILED_COUNTER("cf", "Number of client Phoenix Connections Failed to open" + ", not including throttled connections", LogLevel.OFF, PLong.INSTANCE), + PHOENIX_CONNECTION_CREATION_TIME_MS("cct", + "Time spent in creating Phoenix connections in milliseconds", LogLevel.OFF, PLong.INSTANCE), CLIENT_METADATA_CACHE_MISS_COUNTER("cmcm", "Number of cache misses for the CQSI cache.", LogLevel.DEBUG, PLong.INSTANCE), CLIENT_METADATA_CACHE_HIT_COUNTER("cmch", "Number of cache hits for the CQSI cache.", diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java index 575d38530eb..8c3ac719d27 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java @@ -17,10 +17,6 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; -import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -30,6 +26,8 @@ import org.apache.phoenix.monitoring.ConnectionQueryServicesMetricImpl; import org.apache.phoenix.monitoring.MetricType; +import static org.apache.phoenix.monitoring.MetricType.*; + /** * Class for Connection Query Service Metrics. */ @@ -42,7 +40,8 @@ public enum QueryServiceMetrics { CONNECTION_QUERY_SERVICE_OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER( OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER), CONNECTION_QUERY_SERVICE_PHOENIX_CONNECTIONS_THROTTLED_COUNTER( - PHOENIX_CONNECTIONS_THROTTLED_COUNTER); + PHOENIX_CONNECTIONS_THROTTLED_COUNTER), + CONNECTION_QUERY_SERVICE_CREATION_TIME(PHOENIX_CONNECTION_CREATION_TIME_MS); private MetricType metricType; private ConnectionQueryServicesMetric metric; diff --git a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java index 54d53afdf6d..d9f752bc17c 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java @@ -17,21 +17,15 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; -import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.*; import static org.apache.phoenix.query.QueryServices.CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS; import static org.apache.phoenix.query.QueryServices.CONNECTION_QUERY_SERVICE_METRICS_ENABLED; import static org.apache.phoenix.query.QueryServices.INTERNAL_CONNECTION_MAX_ALLOWED_CONNECTIONS; import static org.apache.phoenix.query.QueryServices.QUERY_SERVICES_NAME; import static org.apache.phoenix.util.PhoenixRuntime.clearAllConnectionQueryServiceMetrics; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -222,6 +216,27 @@ public void testMultipleCQSIMetricsInParallel() throws Exception { assertEquals("Number of passing CSQI Metrics check should be : ", 4, counter.get()); } + @Test + public void testConnectionTime() { + Map> metrics = + ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); + List serviceMetrics = metrics.get("DEFAULT_CQSN"); + assertNotNull("No metrics found for service: DEFAULT_CQSN", serviceMetrics); + + // Find connection creation time metric + boolean foundMetric = false; + for (ConnectionQueryServicesMetric metric : serviceMetrics) { + System.out.println("Found metric: " + metric.getMetricType() + " = " + metric.getValue()); + if (metric.getMetricType() == PHOENIX_CONNECTION_CREATION_TIME_MS) { + assertTrue("Connection creation time should be >= 0", metric.getValue() >= 0); + foundMetric = true; + break; + } + } + assertTrue("Connection creation time metric not found", foundMetric); + + } + private void checkConnectionQueryServiceMetricsValues(String queryServiceName) throws Exception { String CREATE_TABLE_DDL = "CREATE TABLE IF NOT EXISTS %s (K VARCHAR(10) NOT NULL" + " PRIMARY KEY, V VARCHAR)"; diff --git a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java index 86fc007b906..039b7be051f 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java @@ -17,13 +17,12 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; -import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; -import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.*; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.connectionQueryServiceNames; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.openInternalPhoenixConnCounter; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.openPhoenixConnCounter; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.phoenixConnThrottledCounter; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; @@ -32,6 +31,7 @@ import org.apache.phoenix.monitoring.ConnectionQueryServicesMetric; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesOptions; +import org.apache.phoenix.util.PhoenixRuntime; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; @@ -101,6 +101,27 @@ public void testHistogramMetricsForOpenPhoenixConnectionCounter() { } } + @Test + public void testConnectionTime() { + Map> metrics = + ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); + List serviceMetrics = metrics.get("DEFAULT_CQSN"); + assertNotNull("No metrics found for service: DEFAULT_CQSN", serviceMetrics); + + // Find connection creation time metric + boolean foundMetric = false; + for (ConnectionQueryServicesMetric metric : serviceMetrics) { + System.out.println("Found metric: " + metric.getMetricType() + " = " + metric.getValue()); + if (metric.getMetricType() == PHOENIX_CONNECTION_CREATION_TIME_MS) { + assertTrue("Connection creation time should be >= 0", metric.getValue() >= 0); + foundMetric = true; + break; + } + } + assertTrue("Connection creation time metric not found", foundMetric); + + } + private void updateMetricsAndHistogram(long counter, String connectionQueryServiceName) { ConnectionQueryServicesMetricsManager.updateMetrics(connectionQueryServiceName, OPEN_PHOENIX_CONNECTIONS_COUNTER, counter); From fd464043167ffe1a007f495f5c3ecb72ad62232a Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Tue, 6 Jan 2026 14:32:09 +0530 Subject: [PATCH 4/7] ITs changes --- .../org/apache/phoenix/end2end/QueryIT.java | 579 +++++++++++++++++- .../phoenix/compile/QueryCompilerTest.java | 4 +- .../phoenix/compile/WhereOptimizerTest.java | 22 +- pom.xml | 2 +- 4 files changed, 587 insertions(+), 20 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java index 1ce36c241a7..b57a58fecf7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java @@ -27,15 +27,17 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; +import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; +import java.util.List; import java.util.Properties; +import java.util.Set; import org.apache.phoenix.exception.SQLExceptionCode; +import org.apache.phoenix.thirdparty.com.google.common.collect.Lists; import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.QueryUtil; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runners.Parameterized.Parameters; @@ -48,7 +50,14 @@ public class QueryIT extends BaseQueryIT { @Parameters(name = "QueryIT_{index}") // name is used by failsafe as file name in reports public static synchronized Collection data() { - return BaseQueryIT.allIndexes(); + // Return only one parameter set to run a single iteration + // Parameters: indexDDL, columnEncoded, keepDeletedCells + List testCases = Lists.newArrayList(); + testCases.add(new Object[] { NO_INDEX, false, false }); // No index, no column encoding + return testCases; + + // Original code that runs all iterations: + // return BaseQueryIT.allIndexes(); } public QueryIT(String indexDDL, boolean columnEncoded, boolean keepDeletedCells) { @@ -169,4 +178,562 @@ public void testDistinctLimitScan() throws Exception { conn.close(); } } + + @Test + public void testExplosion() throws Exception { + String tableName = generateUniqueName(); + String indexName = generateUniqueName(); + try (Connection conn = DriverManager.getConnection(getUrl()); + Statement stmt = conn.createStatement()) { + stmt.execute("create table " + tableName + " (id varchar primary key, ts timestamp)"); + // stmt.execute("create table " + tableName + "(id varchar NOT NULL, ts timestamp NOT NULL CONSTRAINT PK PRIMARY KEY (id, ts DESC))"); + stmt.execute("create index " + indexName + " on " + tableName + "(ts desc)"); + + String query = "select id, ts from " + tableName + + " where ts >= TIMESTAMP '2023-02-23 13:30:00' and ts < TIMESTAMP '2023-02-23 13:40:00'"; + ResultSet rs = stmt.executeQuery("EXPLAIN " + query); + String explainPlan = QueryUtil.getExplainPlan(rs); + System.out.println("EXPLAIN PLAN: " + explainPlan); + PreparedStatement statement = conn.prepareStatement(query); + rs = statement.executeQuery(); + int rowCount = 0; + while (rs.next()) { + rowCount++; + } + // ResultSet rs = stmt.executeQuery("EXPLAIN " + query); + // String explainPlan = QueryUtil.getExplainPlan(rs); + // assertEquals( + // "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + indexName + // + " [~1,677,159,600,000] - [~1,677,159,000,000]\n SERVER FILTER BY FIRST KEY ONLY", + // explainPlan); + } + } + + + + @Test + public void testKeyExplosion() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + String testTable = generateUniqueName(); + try { + // Create table with DESC ordering on NUMBER column + String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" + + "ID CHAR(15) NOT NULL, " + + "NUMBER VARCHAR NOT NULL, " + + "ENTITY_ID VARCHAR NOT NULL, " + + "CREATED_BY VARCHAR, " + + "DATA VARCHAR " + + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; + conn.createStatement().execute(createTableDDL); + + // Insert test data + String upsert = "UPSERT INTO " + testTable + + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; + PreparedStatement ps = conn.prepareStatement(upsert); + + // Insert first row + ps.setString(1, "id_1"); + ps.setString(2, "20251012"); + ps.setString(3, "entity_1"); + ps.setString(4, "user1"); + ps.setString(5, "data1"); + ps.executeUpdate(); + + // Insert second row + ps.setString(1, "id_2"); + ps.setString(2, "20250912"); + ps.setString(3, "entity_2"); + ps.setString(4, "user2"); + ps.setString(5, "data2"); + ps.executeUpdate(); + + ps.setString(1, "id_3"); + ps.setString(2, "20250913"); + ps.setString(3, "entity_3"); + ps.setString(4, "user3"); + ps.setString(5, "data3"); + ps.executeUpdate(); + +// +// ps.setString(1, "id_1"); +// ps.setString(2, "20250910"); +// ps.setString(3, "entity_3"); +// ps.setString(4, "user22"); +// ps.setString(5, "data22"); +// ps.executeUpdate(); +// +// ps.setString(1, "id_3"); +// ps.setString(2, "20250911"); +// ps.setString(3, "entity_11"); +// ps.setString(4, "user21"); +// ps.setString(5, "data21"); +// ps.executeUpdate(); + + conn.commit(); + + // Run the query with IN clause + String query = "SELECT * FROM " + testTable + + " WHERE (ID, NUMBER, ENTITY_ID) IN (('id_1', '20251012', 'entity_1'), ('id_2', '20250912', 'entity_2'))"; + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + + // Verify we get exactly 2 rows back + int rowCount = 0; + while (rs.next()) { + rowCount++; + String id = rs.getString("ID"); + String number = rs.getString("NUMBER"); + String entityId = rs.getString("ENTITY_ID"); + + // Verify the data matches what we inserted + if (rowCount == 1) { + assertEquals("id_1", id); + assertEquals("20251012", number); + assertEquals("entity_1", entityId); + } else if (rowCount == 2) { + assertEquals("id_2", id); + assertEquals("20250912", number); + assertEquals("entity_2", entityId); + } + } + + assertEquals("Expected 2 rows", 2, rowCount); + } finally { + conn.close(); + } + } + + @Test + public void testKeyExplosionInteger() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + String testTable = generateUniqueName(); + // Create table with DESC ordering on NUMBER column + String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" + + "ID CHAR(15) NOT NULL, " + + "NUMBER INTEGER NOT NULL, " + + "ENTITY_ID VARCHAR NOT NULL, " + + "CREATED_BY VARCHAR, " + + "DATA VARCHAR " + + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; + conn.createStatement().execute(createTableDDL); + + // Insert test data + String upsert = "UPSERT INTO " + testTable + + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; + PreparedStatement ps = conn.prepareStatement(upsert); + + // Insert first row + ps.setString(1, "id_1"); + ps.setInt(2, 20251012); + ps.setString(3, "entity_1"); + ps.setString(4, "user1"); + ps.setString(5, "data1"); + ps.executeUpdate(); + + // Insert second row + ps.setString(1, "id_2"); + ps.setInt(2, 20250912); + ps.setString(3, "entity_2"); + ps.setString(4, "user2"); + ps.setString(5, "data2"); + ps.executeUpdate(); + + ps.setString(1, "id_3"); + ps.setInt(2, 20250910); + ps.setString(3, "entity_3"); + ps.setString(4, "user3"); + ps.setString(5, "data3"); + ps.executeUpdate(); + conn.commit(); + + // Run the query with IN clause + String query = "SELECT * FROM " + testTable + + " WHERE (ID, NUMBER, ENTITY_ID) IN (('id_1', 20251012, 'entity_1'), ('id_2', 20250912, 'entity_2'))"; + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + + // Verify we get exactly 2 rows back + int rowCount = 0; + while (rs.next()) { + rowCount++; + String id = rs.getString("ID"); + String number = rs.getString("NUMBER"); + String entityId = rs.getString("ENTITY_ID"); + + // Verify the data matches what we inserted + if (rowCount == 1) { + assertEquals("id_1", id); + assertEquals("20251012", number); + assertEquals("entity_1", entityId); + } else if (rowCount == 2) { + assertEquals("id_2", id); + assertEquals("20250912", number); + assertEquals("entity_2", entityId); + } + } + + assertEquals("Expected 2 rows", 2, rowCount); + } + + + @Test + public void testExplosionIntegerIndex() throws Exception { + String tableName = generateUniqueName(); + String indexName = generateUniqueName(); + System.out.println(tableName); + System.out.println(indexName); + try (Connection conn = DriverManager.getConnection(getUrl()); + Statement stmt = conn.createStatement()) { + stmt.execute("create table " + tableName + " (id varchar primary key, ts integer)"); + stmt.execute("create index " + indexName + " on " + tableName + "(ts desc)"); + + // Insert test data + String upsert = "UPSERT INTO " + tableName + + " (id, ts) VALUES (?, ?)"; + PreparedStatement ps = conn.prepareStatement(upsert); + + // Insert first row + ps.setString(1, "id_1"); + ps.setInt(2, 20251012); + ps.executeUpdate(); + + // Insert second row + ps.setString(1, "id_2"); + ps.setInt(2, 20250912); + ps.executeUpdate(); + + ps.setString(1, "id_3"); + ps.setInt(2, 20250910); + ps.executeUpdate(); + conn.commit(); + + String query = "select * from " + tableName + + " where ts > 20250911"; + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + String explainPlan = QueryUtil.getExplainPlan(rs); + System.out.println("EXPLAIN PLAN: " + explainPlan); + statement = conn.prepareStatement(query); + rs = statement.executeQuery(); + int rowCount = 0; + while (rs.next()) { + rowCount++; + } + // ResultSet rs = stmt.executeQuery("EXPLAIN " + query); + // String explainPlan = QueryUtil.getExplainPlan(rs); + // assertEquals( + // "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + indexName + // + " [~1,677,159,600,000] - [~1,677,159,000,000]\n SERVER FILTER BY FIRST KEY ONLY", + // explainPlan); + } + } + + @Test + public void testKeyExplosionPartialCompositeIn() throws Exception { + // Variation 6: Partial composite key IN + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + String testTable = generateUniqueName(); + try { + // Create table with DESC ordering on NUMBER column + String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" + + "ID CHAR(15) NOT NULL, " + + "NUMBER VARCHAR NOT NULL, " + + "ENTITY_ID VARCHAR NOT NULL, " + + "CREATED_BY VARCHAR, " + + "DATA VARCHAR " + + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; + conn.createStatement().execute(createTableDDL); + + // Insert test data + String upsert = "UPSERT INTO " + testTable + + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; + PreparedStatement ps = conn.prepareStatement(upsert); + + ps.setString(1, "id_1"); + ps.setString(2, "20251012"); + ps.setString(3, "entity_1"); + ps.setString(4, "user1"); + ps.setString(5, "data1"); + ps.executeUpdate(); + + ps.setString(1, "id_2"); + ps.setString(2, "20250912"); + ps.setString(3, "entity_2"); + ps.setString(4, "user2"); + ps.setString(5, "data2"); + ps.executeUpdate(); + + ps.setString(1, "id_3"); + ps.setString(2, "20250913"); + ps.setString(3, "entity_3"); + ps.setString(4, "user3"); + ps.setString(5, "data3"); + ps.executeUpdate(); + + ps.setString(1, "id_1"); + ps.setString(2, "20251012"); + ps.setString(3, "entity_1b"); + ps.setString(4, "user4"); + ps.setString(5, "data4"); + ps.executeUpdate(); + + conn.commit(); + + // Run query with partial composite key IN (first two columns only) + String query = "SELECT * FROM " + testTable + + " WHERE (ID, NUMBER) IN (('id_1', '20251012'), ('id_2', '20250912'))"; + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + + // Should return 3 rows: id_1 with 2 ENTITY_IDs at same NUMBER, id_2 with 1 ENTITY_ID + int rowCount = 0; + while (rs.next()) { + rowCount++; + String id = rs.getString("ID"); + String number = rs.getString("NUMBER"); + // Verify the combinations + assertTrue("Unexpected row", + (id.equals("id_1") && number.equals("20251012")) || + (id.equals("id_2") && number.equals("20250912"))); + } + + assertEquals("Expected 3 rows", 3, rowCount); + } finally { + conn.close(); + } + } + + @Test + public void testKeyExplosionMixedAndOr() throws Exception { + // Variation 8: Mixed AND/OR with ranges on DESC column + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + String testTable = generateUniqueName(); + try { + // Create table with DESC ordering on NUMBER column + String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" + + "ID CHAR(15) NOT NULL, " + + "NUMBER VARCHAR NOT NULL, " + + "ENTITY_ID VARCHAR NOT NULL, " + + "CREATED_BY VARCHAR, " + + "DATA VARCHAR " + + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; + conn.createStatement().execute(createTableDDL); + + // Insert test data + String upsert = "UPSERT INTO " + testTable + + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; + PreparedStatement ps = conn.prepareStatement(upsert); + + ps.setString(1, "id_1"); + ps.setString(2, "20251012"); + ps.setString(3, "entity_1"); + ps.setString(4, "user1"); + ps.setString(5, "data1"); + ps.executeUpdate(); + + ps.setString(1, "id_1"); + ps.setString(2, "20250910"); + ps.setString(3, "entity_1b"); + ps.setString(4, "user2"); + ps.setString(5, "data2"); + ps.executeUpdate(); + + ps.setString(1, "id_2"); + ps.setString(2, "20251011"); + ps.setString(3, "entity_2"); + ps.setString(4, "user3"); + ps.setString(5, "data3"); + ps.executeUpdate(); + + ps.setString(1, "id_3"); + ps.setString(2, "20250913"); + ps.setString(3, "entity_3"); + ps.setString(4, "user4"); + ps.setString(5, "data4"); + ps.executeUpdate(); + + conn.commit(); + + // Run query with mixed AND/OR conditions + String query = "SELECT * FROM " + testTable + + " WHERE (ID = 'id_1' AND NUMBER > '20250911') OR (ID = 'id_2' AND NUMBER <= '20251012')"; + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + + // Should return: id_1 with NUMBER=20251012, and id_2 with NUMBER=20251011 + int rowCount = 0; + while (rs.next()) { + rowCount++; + String id = rs.getString("ID"); + String number = rs.getString("NUMBER"); + // Verify expected combinations + assertTrue("Unexpected row", + (id.equals("id_1") && number.equals("20251012")) || + (id.equals("id_2") && number.equals("20251011"))); + } + + assertEquals("Expected 2 rows", 2, rowCount); + } finally { + conn.close(); + } + } + + @Test + public void testKeyExplosionPartialCompositeInInteger() throws Exception { + // Variation 6: Partial composite key IN (INTEGER type) + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + String testTable = generateUniqueName(); + try { + // Create table with DESC ordering on NUMBER column + String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" + + "ID CHAR(15) NOT NULL, " + + "NUMBER INTEGER NOT NULL, " + + "ENTITY_ID VARCHAR NOT NULL, " + + "CREATED_BY VARCHAR, " + + "DATA VARCHAR " + + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; + conn.createStatement().execute(createTableDDL); + + // Insert test data + String upsert = "UPSERT INTO " + testTable + + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; + PreparedStatement ps = conn.prepareStatement(upsert); + + ps.setString(1, "id_1"); + ps.setInt(2, 20251012); + ps.setString(3, "entity_1"); + ps.setString(4, "user1"); + ps.setString(5, "data1"); + ps.executeUpdate(); + + ps.setString(1, "id_2"); + ps.setInt(2, 20250912); + ps.setString(3, "entity_2"); + ps.setString(4, "user2"); + ps.setString(5, "data2"); + ps.executeUpdate(); + + ps.setString(1, "id_3"); + ps.setInt(2, 20250913); + ps.setString(3, "entity_3"); + ps.setString(4, "user3"); + ps.setString(5, "data3"); + ps.executeUpdate(); + + ps.setString(1, "id_1"); + ps.setInt(2, 20251012); + ps.setString(3, "entity_1b"); + ps.setString(4, "user4"); + ps.setString(5, "data4"); + ps.executeUpdate(); + + conn.commit(); + + // Run query with partial composite key IN (first two columns only) + String query = "SELECT * FROM " + testTable + + " WHERE (ID, NUMBER) IN (('id_1', 20251012), ('id_2', 20250912))"; + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + + // Should return 3 rows: id_1 with 2 ENTITY_IDs at same NUMBER, id_2 with 1 ENTITY_ID + int rowCount = 0; + while (rs.next()) { + rowCount++; + String id = rs.getString("ID"); + int number = rs.getInt("NUMBER"); + // Verify the combinations + assertTrue("Unexpected row", + (id.equals("id_1") && number == 20251012) || + (id.equals("id_2") && number == 20250912)); + } + + assertEquals("Expected 3 rows", 3, rowCount); + } finally { + conn.close(); + } + } + + @Test + public void testKeyExplosionMixedAndOrInteger() throws Exception { + // Variation 8: Mixed AND/OR with ranges on DESC column (INTEGER type) + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + String testTable = generateUniqueName(); + try { + // Create table with DESC ordering on NUMBER column + String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" + + "ID CHAR(15) NOT NULL, " + + "NUMBER INTEGER NOT NULL, " + + "ENTITY_ID VARCHAR NOT NULL, " + + "CREATED_BY VARCHAR, " + + "DATA VARCHAR " + + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; + conn.createStatement().execute(createTableDDL); + + // Insert test data + String upsert = "UPSERT INTO " + testTable + + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; + PreparedStatement ps = conn.prepareStatement(upsert); + + ps.setString(1, "id_1"); + ps.setInt(2, 20251012); + ps.setString(3, "entity_1"); + ps.setString(4, "user1"); + ps.setString(5, "data1"); + ps.executeUpdate(); + + ps.setString(1, "id_1"); + ps.setInt(2, 20250910); + ps.setString(3, "entity_1b"); + ps.setString(4, "user2"); + ps.setString(5, "data2"); + ps.executeUpdate(); + + ps.setString(1, "id_2"); + ps.setInt(2, 20251011); + ps.setString(3, "entity_2"); + ps.setString(4, "user3"); + ps.setString(5, "data3"); + ps.executeUpdate(); + + ps.setString(1, "id_3"); + ps.setInt(2, 20250913); + ps.setString(3, "entity_3"); + ps.setString(4, "user4"); + ps.setString(5, "data4"); + ps.executeUpdate(); + + conn.commit(); + + // Run query with mixed AND/OR conditions + String query = "SELECT * FROM " + testTable + + " WHERE (ID = 'id_1' AND NUMBER > 20250911) OR (ID = 'id_2' AND NUMBER <= 20251012)"; + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + + // Should return: id_1 with NUMBER=20251012, and id_2 with NUMBER=20251011 + int rowCount = 0; + while (rs.next()) { + rowCount++; + String id = rs.getString("ID"); + int number = rs.getInt("NUMBER"); + // Verify expected combinations + assertTrue("Unexpected row", + (id.equals("id_1") && number == 20251012) || + (id.equals("id_2") && number == 20251011)); + } + + assertEquals("Expected 2 rows", 2, rowCount); + } finally { + conn.close(); + } + } + + + } diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java index 6ecfc7ff011..2820afe411b 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java @@ -7202,8 +7202,8 @@ public void testReverseVarLengthRange6916() throws Exception { String openQry = "select * from " + tableName + " where k > 'a' and k<'aaa'"; Scan openScan = getOptimizedQueryPlan(openQry, Collections.emptyList()).getContext().getScan(); - assertEquals("\\x9E\\x9E\\x9F\\x00", Bytes.toStringBinary(openScan.getStartRow())); - assertEquals("\\x9E\\xFF", Bytes.toStringBinary(openScan.getStopRow())); +// assertEquals("\\x9E\\x9E\\x9F\\x00", Bytes.toStringBinary(openScan.getStartRow())); +// assertEquals("\\x9E\\xFF", Bytes.toStringBinary(openScan.getStopRow())); ResultSet rs = stmt.executeQuery("EXPLAIN " + openQry); String explainPlan = QueryUtil.getExplainPlan(rs); assertEquals(explainExpected, explainPlan); diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java index 33f616f189e..f6c7d82716d 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java @@ -1280,8 +1280,8 @@ public void testLikeExpressionWithDescOrder() throws SQLException { byte[] invStopRow = new byte[startRow.length]; SortOrder.invert(stopRow, 0, invStopRow, 0, stopRow.length); - assertArrayEquals(invStopRow, lowerRange); - assertArrayEquals(invStartRow, upperRange); + assertArrayEquals(startRow, lowerRange); + assertArrayEquals(stopRow, upperRange); assertFalse(lowerInclusive); assertTrue(upperInclusive); @@ -3241,15 +3241,15 @@ public void testLastPkColumnIsVariableLengthAndDescBug5307() throws Exception { + "where (OBJ.OBJECT_ID, OBJ.OBJECT_VERSION) in (('obj1', '2222'),('obj2', '1111'),('obj3', '1111'))"; queryPlan = TestUtil.getOptimizeQueryPlan(conn, sql); scan = queryPlan.getContext().getScan(); - FilterList filterList = (FilterList) scan.getFilter(); - assertTrue(filterList.getOperator() == Operator.MUST_PASS_ALL); - assertEquals(filterList.getFilters().size(), 2); - assertTrue(filterList.getFilters().get(0) instanceof SkipScanFilter); - assertTrue(filterList.getFilters().get(1) instanceof RowKeyComparisonFilter); - RowKeyComparisonFilter rowKeyComparisonFilter = - (RowKeyComparisonFilter) filterList.getFilters().get(1); - assertEquals(rowKeyComparisonFilter.toString(), - "(OBJECT_ID, OBJECT_VERSION) IN (X'6f626a3100cdcdcdcd',X'6f626a3200cececece',X'6f626a3300cececece')"); +// FilterList filterList = (FilterList) scan.getFilter(); +// assertTrue(filterList.getOperator() == Operator.MUST_PASS_ALL); +// assertEquals(filterList.getFilters().size(), 2); +// assertTrue(filterList.getFilters().get(0) instanceof SkipScanFilter); +// assertTrue(filterList.getFilters().get(1) instanceof RowKeyComparisonFilter); +// RowKeyComparisonFilter rowKeyComparisonFilter = +// (RowKeyComparisonFilter) filterList.getFilters().get(1); +// assertEquals(rowKeyComparisonFilter.toString(), +// "(OBJECT_ID, OBJECT_VERSION) IN (X'6f626a3100cdcdcdcd',X'6f626a3200cececece',X'6f626a3300cececece')"); assertTrue(queryPlan.getContext().getScanRanges().isPointLookup()); assertArrayEquals(startKey, scan.getStartRow()); diff --git a/pom.xml b/pom.xml index 3114d5e4a9d..ccae93600f6 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ true - 2.18.4.1 + 2.14.1 4.1.126.Final 3.5.2 From 58ef6a91e76025f8940e66ccfad2156412ef1fa8 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Tue, 6 Jan 2026 14:32:32 +0530 Subject: [PATCH 5/7] Revert "ITs changes" This reverts commit fd464043167ffe1a007f495f5c3ecb72ad62232a. --- .../org/apache/phoenix/end2end/QueryIT.java | 579 +----------------- .../phoenix/compile/QueryCompilerTest.java | 4 +- .../phoenix/compile/WhereOptimizerTest.java | 22 +- pom.xml | 2 +- 4 files changed, 20 insertions(+), 587 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java index b57a58fecf7..1ce36c241a7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java @@ -27,17 +27,15 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.sql.*; -import java.util.Arrays; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.Collection; -import java.util.HashSet; -import java.util.List; import java.util.Properties; -import java.util.Set; import org.apache.phoenix.exception.SQLExceptionCode; -import org.apache.phoenix.thirdparty.com.google.common.collect.Lists; import org.apache.phoenix.util.PropertiesUtil; -import org.apache.phoenix.util.QueryUtil; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runners.Parameterized.Parameters; @@ -50,14 +48,7 @@ public class QueryIT extends BaseQueryIT { @Parameters(name = "QueryIT_{index}") // name is used by failsafe as file name in reports public static synchronized Collection data() { - // Return only one parameter set to run a single iteration - // Parameters: indexDDL, columnEncoded, keepDeletedCells - List testCases = Lists.newArrayList(); - testCases.add(new Object[] { NO_INDEX, false, false }); // No index, no column encoding - return testCases; - - // Original code that runs all iterations: - // return BaseQueryIT.allIndexes(); + return BaseQueryIT.allIndexes(); } public QueryIT(String indexDDL, boolean columnEncoded, boolean keepDeletedCells) { @@ -178,562 +169,4 @@ public void testDistinctLimitScan() throws Exception { conn.close(); } } - - @Test - public void testExplosion() throws Exception { - String tableName = generateUniqueName(); - String indexName = generateUniqueName(); - try (Connection conn = DriverManager.getConnection(getUrl()); - Statement stmt = conn.createStatement()) { - stmt.execute("create table " + tableName + " (id varchar primary key, ts timestamp)"); - // stmt.execute("create table " + tableName + "(id varchar NOT NULL, ts timestamp NOT NULL CONSTRAINT PK PRIMARY KEY (id, ts DESC))"); - stmt.execute("create index " + indexName + " on " + tableName + "(ts desc)"); - - String query = "select id, ts from " + tableName - + " where ts >= TIMESTAMP '2023-02-23 13:30:00' and ts < TIMESTAMP '2023-02-23 13:40:00'"; - ResultSet rs = stmt.executeQuery("EXPLAIN " + query); - String explainPlan = QueryUtil.getExplainPlan(rs); - System.out.println("EXPLAIN PLAN: " + explainPlan); - PreparedStatement statement = conn.prepareStatement(query); - rs = statement.executeQuery(); - int rowCount = 0; - while (rs.next()) { - rowCount++; - } - // ResultSet rs = stmt.executeQuery("EXPLAIN " + query); - // String explainPlan = QueryUtil.getExplainPlan(rs); - // assertEquals( - // "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + indexName - // + " [~1,677,159,600,000] - [~1,677,159,000,000]\n SERVER FILTER BY FIRST KEY ONLY", - // explainPlan); - } - } - - - - @Test - public void testKeyExplosion() throws Exception { - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - String testTable = generateUniqueName(); - try { - // Create table with DESC ordering on NUMBER column - String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" - + "ID CHAR(15) NOT NULL, " - + "NUMBER VARCHAR NOT NULL, " - + "ENTITY_ID VARCHAR NOT NULL, " - + "CREATED_BY VARCHAR, " - + "DATA VARCHAR " - + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; - conn.createStatement().execute(createTableDDL); - - // Insert test data - String upsert = "UPSERT INTO " + testTable - + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; - PreparedStatement ps = conn.prepareStatement(upsert); - - // Insert first row - ps.setString(1, "id_1"); - ps.setString(2, "20251012"); - ps.setString(3, "entity_1"); - ps.setString(4, "user1"); - ps.setString(5, "data1"); - ps.executeUpdate(); - - // Insert second row - ps.setString(1, "id_2"); - ps.setString(2, "20250912"); - ps.setString(3, "entity_2"); - ps.setString(4, "user2"); - ps.setString(5, "data2"); - ps.executeUpdate(); - - ps.setString(1, "id_3"); - ps.setString(2, "20250913"); - ps.setString(3, "entity_3"); - ps.setString(4, "user3"); - ps.setString(5, "data3"); - ps.executeUpdate(); - -// -// ps.setString(1, "id_1"); -// ps.setString(2, "20250910"); -// ps.setString(3, "entity_3"); -// ps.setString(4, "user22"); -// ps.setString(5, "data22"); -// ps.executeUpdate(); -// -// ps.setString(1, "id_3"); -// ps.setString(2, "20250911"); -// ps.setString(3, "entity_11"); -// ps.setString(4, "user21"); -// ps.setString(5, "data21"); -// ps.executeUpdate(); - - conn.commit(); - - // Run the query with IN clause - String query = "SELECT * FROM " + testTable - + " WHERE (ID, NUMBER, ENTITY_ID) IN (('id_1', '20251012', 'entity_1'), ('id_2', '20250912', 'entity_2'))"; - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - // Verify we get exactly 2 rows back - int rowCount = 0; - while (rs.next()) { - rowCount++; - String id = rs.getString("ID"); - String number = rs.getString("NUMBER"); - String entityId = rs.getString("ENTITY_ID"); - - // Verify the data matches what we inserted - if (rowCount == 1) { - assertEquals("id_1", id); - assertEquals("20251012", number); - assertEquals("entity_1", entityId); - } else if (rowCount == 2) { - assertEquals("id_2", id); - assertEquals("20250912", number); - assertEquals("entity_2", entityId); - } - } - - assertEquals("Expected 2 rows", 2, rowCount); - } finally { - conn.close(); - } - } - - @Test - public void testKeyExplosionInteger() throws Exception { - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - String testTable = generateUniqueName(); - // Create table with DESC ordering on NUMBER column - String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" - + "ID CHAR(15) NOT NULL, " - + "NUMBER INTEGER NOT NULL, " - + "ENTITY_ID VARCHAR NOT NULL, " - + "CREATED_BY VARCHAR, " - + "DATA VARCHAR " - + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; - conn.createStatement().execute(createTableDDL); - - // Insert test data - String upsert = "UPSERT INTO " + testTable - + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; - PreparedStatement ps = conn.prepareStatement(upsert); - - // Insert first row - ps.setString(1, "id_1"); - ps.setInt(2, 20251012); - ps.setString(3, "entity_1"); - ps.setString(4, "user1"); - ps.setString(5, "data1"); - ps.executeUpdate(); - - // Insert second row - ps.setString(1, "id_2"); - ps.setInt(2, 20250912); - ps.setString(3, "entity_2"); - ps.setString(4, "user2"); - ps.setString(5, "data2"); - ps.executeUpdate(); - - ps.setString(1, "id_3"); - ps.setInt(2, 20250910); - ps.setString(3, "entity_3"); - ps.setString(4, "user3"); - ps.setString(5, "data3"); - ps.executeUpdate(); - conn.commit(); - - // Run the query with IN clause - String query = "SELECT * FROM " + testTable - + " WHERE (ID, NUMBER, ENTITY_ID) IN (('id_1', 20251012, 'entity_1'), ('id_2', 20250912, 'entity_2'))"; - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - // Verify we get exactly 2 rows back - int rowCount = 0; - while (rs.next()) { - rowCount++; - String id = rs.getString("ID"); - String number = rs.getString("NUMBER"); - String entityId = rs.getString("ENTITY_ID"); - - // Verify the data matches what we inserted - if (rowCount == 1) { - assertEquals("id_1", id); - assertEquals("20251012", number); - assertEquals("entity_1", entityId); - } else if (rowCount == 2) { - assertEquals("id_2", id); - assertEquals("20250912", number); - assertEquals("entity_2", entityId); - } - } - - assertEquals("Expected 2 rows", 2, rowCount); - } - - - @Test - public void testExplosionIntegerIndex() throws Exception { - String tableName = generateUniqueName(); - String indexName = generateUniqueName(); - System.out.println(tableName); - System.out.println(indexName); - try (Connection conn = DriverManager.getConnection(getUrl()); - Statement stmt = conn.createStatement()) { - stmt.execute("create table " + tableName + " (id varchar primary key, ts integer)"); - stmt.execute("create index " + indexName + " on " + tableName + "(ts desc)"); - - // Insert test data - String upsert = "UPSERT INTO " + tableName - + " (id, ts) VALUES (?, ?)"; - PreparedStatement ps = conn.prepareStatement(upsert); - - // Insert first row - ps.setString(1, "id_1"); - ps.setInt(2, 20251012); - ps.executeUpdate(); - - // Insert second row - ps.setString(1, "id_2"); - ps.setInt(2, 20250912); - ps.executeUpdate(); - - ps.setString(1, "id_3"); - ps.setInt(2, 20250910); - ps.executeUpdate(); - conn.commit(); - - String query = "select * from " + tableName - + " where ts > 20250911"; - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - String explainPlan = QueryUtil.getExplainPlan(rs); - System.out.println("EXPLAIN PLAN: " + explainPlan); - statement = conn.prepareStatement(query); - rs = statement.executeQuery(); - int rowCount = 0; - while (rs.next()) { - rowCount++; - } - // ResultSet rs = stmt.executeQuery("EXPLAIN " + query); - // String explainPlan = QueryUtil.getExplainPlan(rs); - // assertEquals( - // "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + indexName - // + " [~1,677,159,600,000] - [~1,677,159,000,000]\n SERVER FILTER BY FIRST KEY ONLY", - // explainPlan); - } - } - - @Test - public void testKeyExplosionPartialCompositeIn() throws Exception { - // Variation 6: Partial composite key IN - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - String testTable = generateUniqueName(); - try { - // Create table with DESC ordering on NUMBER column - String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" - + "ID CHAR(15) NOT NULL, " - + "NUMBER VARCHAR NOT NULL, " - + "ENTITY_ID VARCHAR NOT NULL, " - + "CREATED_BY VARCHAR, " - + "DATA VARCHAR " - + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; - conn.createStatement().execute(createTableDDL); - - // Insert test data - String upsert = "UPSERT INTO " + testTable - + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; - PreparedStatement ps = conn.prepareStatement(upsert); - - ps.setString(1, "id_1"); - ps.setString(2, "20251012"); - ps.setString(3, "entity_1"); - ps.setString(4, "user1"); - ps.setString(5, "data1"); - ps.executeUpdate(); - - ps.setString(1, "id_2"); - ps.setString(2, "20250912"); - ps.setString(3, "entity_2"); - ps.setString(4, "user2"); - ps.setString(5, "data2"); - ps.executeUpdate(); - - ps.setString(1, "id_3"); - ps.setString(2, "20250913"); - ps.setString(3, "entity_3"); - ps.setString(4, "user3"); - ps.setString(5, "data3"); - ps.executeUpdate(); - - ps.setString(1, "id_1"); - ps.setString(2, "20251012"); - ps.setString(3, "entity_1b"); - ps.setString(4, "user4"); - ps.setString(5, "data4"); - ps.executeUpdate(); - - conn.commit(); - - // Run query with partial composite key IN (first two columns only) - String query = "SELECT * FROM " + testTable - + " WHERE (ID, NUMBER) IN (('id_1', '20251012'), ('id_2', '20250912'))"; - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - // Should return 3 rows: id_1 with 2 ENTITY_IDs at same NUMBER, id_2 with 1 ENTITY_ID - int rowCount = 0; - while (rs.next()) { - rowCount++; - String id = rs.getString("ID"); - String number = rs.getString("NUMBER"); - // Verify the combinations - assertTrue("Unexpected row", - (id.equals("id_1") && number.equals("20251012")) || - (id.equals("id_2") && number.equals("20250912"))); - } - - assertEquals("Expected 3 rows", 3, rowCount); - } finally { - conn.close(); - } - } - - @Test - public void testKeyExplosionMixedAndOr() throws Exception { - // Variation 8: Mixed AND/OR with ranges on DESC column - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - String testTable = generateUniqueName(); - try { - // Create table with DESC ordering on NUMBER column - String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" - + "ID CHAR(15) NOT NULL, " - + "NUMBER VARCHAR NOT NULL, " - + "ENTITY_ID VARCHAR NOT NULL, " - + "CREATED_BY VARCHAR, " - + "DATA VARCHAR " - + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; - conn.createStatement().execute(createTableDDL); - - // Insert test data - String upsert = "UPSERT INTO " + testTable - + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; - PreparedStatement ps = conn.prepareStatement(upsert); - - ps.setString(1, "id_1"); - ps.setString(2, "20251012"); - ps.setString(3, "entity_1"); - ps.setString(4, "user1"); - ps.setString(5, "data1"); - ps.executeUpdate(); - - ps.setString(1, "id_1"); - ps.setString(2, "20250910"); - ps.setString(3, "entity_1b"); - ps.setString(4, "user2"); - ps.setString(5, "data2"); - ps.executeUpdate(); - - ps.setString(1, "id_2"); - ps.setString(2, "20251011"); - ps.setString(3, "entity_2"); - ps.setString(4, "user3"); - ps.setString(5, "data3"); - ps.executeUpdate(); - - ps.setString(1, "id_3"); - ps.setString(2, "20250913"); - ps.setString(3, "entity_3"); - ps.setString(4, "user4"); - ps.setString(5, "data4"); - ps.executeUpdate(); - - conn.commit(); - - // Run query with mixed AND/OR conditions - String query = "SELECT * FROM " + testTable - + " WHERE (ID = 'id_1' AND NUMBER > '20250911') OR (ID = 'id_2' AND NUMBER <= '20251012')"; - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - // Should return: id_1 with NUMBER=20251012, and id_2 with NUMBER=20251011 - int rowCount = 0; - while (rs.next()) { - rowCount++; - String id = rs.getString("ID"); - String number = rs.getString("NUMBER"); - // Verify expected combinations - assertTrue("Unexpected row", - (id.equals("id_1") && number.equals("20251012")) || - (id.equals("id_2") && number.equals("20251011"))); - } - - assertEquals("Expected 2 rows", 2, rowCount); - } finally { - conn.close(); - } - } - - @Test - public void testKeyExplosionPartialCompositeInInteger() throws Exception { - // Variation 6: Partial composite key IN (INTEGER type) - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - String testTable = generateUniqueName(); - try { - // Create table with DESC ordering on NUMBER column - String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" - + "ID CHAR(15) NOT NULL, " - + "NUMBER INTEGER NOT NULL, " - + "ENTITY_ID VARCHAR NOT NULL, " - + "CREATED_BY VARCHAR, " - + "DATA VARCHAR " - + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; - conn.createStatement().execute(createTableDDL); - - // Insert test data - String upsert = "UPSERT INTO " + testTable - + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; - PreparedStatement ps = conn.prepareStatement(upsert); - - ps.setString(1, "id_1"); - ps.setInt(2, 20251012); - ps.setString(3, "entity_1"); - ps.setString(4, "user1"); - ps.setString(5, "data1"); - ps.executeUpdate(); - - ps.setString(1, "id_2"); - ps.setInt(2, 20250912); - ps.setString(3, "entity_2"); - ps.setString(4, "user2"); - ps.setString(5, "data2"); - ps.executeUpdate(); - - ps.setString(1, "id_3"); - ps.setInt(2, 20250913); - ps.setString(3, "entity_3"); - ps.setString(4, "user3"); - ps.setString(5, "data3"); - ps.executeUpdate(); - - ps.setString(1, "id_1"); - ps.setInt(2, 20251012); - ps.setString(3, "entity_1b"); - ps.setString(4, "user4"); - ps.setString(5, "data4"); - ps.executeUpdate(); - - conn.commit(); - - // Run query with partial composite key IN (first two columns only) - String query = "SELECT * FROM " + testTable - + " WHERE (ID, NUMBER) IN (('id_1', 20251012), ('id_2', 20250912))"; - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - // Should return 3 rows: id_1 with 2 ENTITY_IDs at same NUMBER, id_2 with 1 ENTITY_ID - int rowCount = 0; - while (rs.next()) { - rowCount++; - String id = rs.getString("ID"); - int number = rs.getInt("NUMBER"); - // Verify the combinations - assertTrue("Unexpected row", - (id.equals("id_1") && number == 20251012) || - (id.equals("id_2") && number == 20250912)); - } - - assertEquals("Expected 3 rows", 3, rowCount); - } finally { - conn.close(); - } - } - - @Test - public void testKeyExplosionMixedAndOrInteger() throws Exception { - // Variation 8: Mixed AND/OR with ranges on DESC column (INTEGER type) - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - String testTable = generateUniqueName(); - try { - // Create table with DESC ordering on NUMBER column - String createTableDDL = "CREATE TABLE IF NOT EXISTS " + testTable + " (" - + "ID CHAR(15) NOT NULL, " - + "NUMBER INTEGER NOT NULL, " - + "ENTITY_ID VARCHAR NOT NULL, " - + "CREATED_BY VARCHAR, " - + "DATA VARCHAR " - + "CONSTRAINT PK PRIMARY KEY (ID, NUMBER DESC, ENTITY_ID))"; - conn.createStatement().execute(createTableDDL); - - // Insert test data - String upsert = "UPSERT INTO " + testTable - + " (ID, NUMBER, ENTITY_ID, CREATED_BY, DATA) VALUES (?, ?, ?, ?, ?)"; - PreparedStatement ps = conn.prepareStatement(upsert); - - ps.setString(1, "id_1"); - ps.setInt(2, 20251012); - ps.setString(3, "entity_1"); - ps.setString(4, "user1"); - ps.setString(5, "data1"); - ps.executeUpdate(); - - ps.setString(1, "id_1"); - ps.setInt(2, 20250910); - ps.setString(3, "entity_1b"); - ps.setString(4, "user2"); - ps.setString(5, "data2"); - ps.executeUpdate(); - - ps.setString(1, "id_2"); - ps.setInt(2, 20251011); - ps.setString(3, "entity_2"); - ps.setString(4, "user3"); - ps.setString(5, "data3"); - ps.executeUpdate(); - - ps.setString(1, "id_3"); - ps.setInt(2, 20250913); - ps.setString(3, "entity_3"); - ps.setString(4, "user4"); - ps.setString(5, "data4"); - ps.executeUpdate(); - - conn.commit(); - - // Run query with mixed AND/OR conditions - String query = "SELECT * FROM " + testTable - + " WHERE (ID = 'id_1' AND NUMBER > 20250911) OR (ID = 'id_2' AND NUMBER <= 20251012)"; - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - // Should return: id_1 with NUMBER=20251012, and id_2 with NUMBER=20251011 - int rowCount = 0; - while (rs.next()) { - rowCount++; - String id = rs.getString("ID"); - int number = rs.getInt("NUMBER"); - // Verify expected combinations - assertTrue("Unexpected row", - (id.equals("id_1") && number == 20251012) || - (id.equals("id_2") && number == 20251011)); - } - - assertEquals("Expected 2 rows", 2, rowCount); - } finally { - conn.close(); - } - } - - - } diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java index 2820afe411b..6ecfc7ff011 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java @@ -7202,8 +7202,8 @@ public void testReverseVarLengthRange6916() throws Exception { String openQry = "select * from " + tableName + " where k > 'a' and k<'aaa'"; Scan openScan = getOptimizedQueryPlan(openQry, Collections.emptyList()).getContext().getScan(); -// assertEquals("\\x9E\\x9E\\x9F\\x00", Bytes.toStringBinary(openScan.getStartRow())); -// assertEquals("\\x9E\\xFF", Bytes.toStringBinary(openScan.getStopRow())); + assertEquals("\\x9E\\x9E\\x9F\\x00", Bytes.toStringBinary(openScan.getStartRow())); + assertEquals("\\x9E\\xFF", Bytes.toStringBinary(openScan.getStopRow())); ResultSet rs = stmt.executeQuery("EXPLAIN " + openQry); String explainPlan = QueryUtil.getExplainPlan(rs); assertEquals(explainExpected, explainPlan); diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java index f6c7d82716d..33f616f189e 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java @@ -1280,8 +1280,8 @@ public void testLikeExpressionWithDescOrder() throws SQLException { byte[] invStopRow = new byte[startRow.length]; SortOrder.invert(stopRow, 0, invStopRow, 0, stopRow.length); - assertArrayEquals(startRow, lowerRange); - assertArrayEquals(stopRow, upperRange); + assertArrayEquals(invStopRow, lowerRange); + assertArrayEquals(invStartRow, upperRange); assertFalse(lowerInclusive); assertTrue(upperInclusive); @@ -3241,15 +3241,15 @@ public void testLastPkColumnIsVariableLengthAndDescBug5307() throws Exception { + "where (OBJ.OBJECT_ID, OBJ.OBJECT_VERSION) in (('obj1', '2222'),('obj2', '1111'),('obj3', '1111'))"; queryPlan = TestUtil.getOptimizeQueryPlan(conn, sql); scan = queryPlan.getContext().getScan(); -// FilterList filterList = (FilterList) scan.getFilter(); -// assertTrue(filterList.getOperator() == Operator.MUST_PASS_ALL); -// assertEquals(filterList.getFilters().size(), 2); -// assertTrue(filterList.getFilters().get(0) instanceof SkipScanFilter); -// assertTrue(filterList.getFilters().get(1) instanceof RowKeyComparisonFilter); -// RowKeyComparisonFilter rowKeyComparisonFilter = -// (RowKeyComparisonFilter) filterList.getFilters().get(1); -// assertEquals(rowKeyComparisonFilter.toString(), -// "(OBJECT_ID, OBJECT_VERSION) IN (X'6f626a3100cdcdcdcd',X'6f626a3200cececece',X'6f626a3300cececece')"); + FilterList filterList = (FilterList) scan.getFilter(); + assertTrue(filterList.getOperator() == Operator.MUST_PASS_ALL); + assertEquals(filterList.getFilters().size(), 2); + assertTrue(filterList.getFilters().get(0) instanceof SkipScanFilter); + assertTrue(filterList.getFilters().get(1) instanceof RowKeyComparisonFilter); + RowKeyComparisonFilter rowKeyComparisonFilter = + (RowKeyComparisonFilter) filterList.getFilters().get(1); + assertEquals(rowKeyComparisonFilter.toString(), + "(OBJECT_ID, OBJECT_VERSION) IN (X'6f626a3100cdcdcdcd',X'6f626a3200cececece',X'6f626a3300cececece')"); assertTrue(queryPlan.getContext().getScanRanges().isPointLookup()); assertArrayEquals(startKey, scan.getStartRow()); diff --git a/pom.xml b/pom.xml index ccae93600f6..3114d5e4a9d 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ true - 2.14.1 + 2.18.4.1 4.1.126.Final 3.5.2 From d60489203eaa1505b3249b217a120bd7833a8b0d Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Wed, 26 Aug 2026 20:11:15 +0530 Subject: [PATCH 6/7] PHOENIX-7993: Move PhoenixSyncTableOutputRepositoryTest class as an Integration test --- .../end2end/PhoenixSyncTableOutputRepositoryIT.java} | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) rename phoenix-core/src/{test/java/org/apache/phoenix/mapreduce/PhoenixSyncTableOutputRepositoryTest.java => it/java/org/apache/phoenix/end2end/PhoenixSyncTableOutputRepositoryIT.java} (98%) diff --git a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/PhoenixSyncTableOutputRepositoryTest.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixSyncTableOutputRepositoryIT.java similarity index 98% rename from phoenix-core/src/test/java/org/apache/phoenix/mapreduce/PhoenixSyncTableOutputRepositoryTest.java rename to phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixSyncTableOutputRepositoryIT.java index dfdaabecd27..fb0d0364700 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/PhoenixSyncTableOutputRepositoryTest.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixSyncTableOutputRepositoryIT.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.phoenix.mapreduce; +package org.apache.phoenix.end2end; import static org.junit.Assert.*; @@ -33,8 +33,10 @@ import org.apache.hadoop.hbase.io.compress.Compression; import org.apache.hadoop.hbase.util.Bytes; import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.mapreduce.PhoenixSyncTableCheckpointOutputRow; import org.apache.phoenix.mapreduce.PhoenixSyncTableCheckpointOutputRow.Status; import org.apache.phoenix.mapreduce.PhoenixSyncTableCheckpointOutputRow.Type; +import org.apache.phoenix.mapreduce.PhoenixSyncTableOutputRepository; import org.apache.phoenix.query.BaseTest; import org.apache.phoenix.schema.PTable; import org.apache.phoenix.schema.PTable.QualifierEncodingScheme; @@ -44,14 +46,16 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.apache.phoenix.thirdparty.com.google.common.collect.Maps; /** - * Unit tests for PhoenixSyncTableOutputRepository and PhoenixSyncTableCheckpointOutputRow. Tests - * checkpoint table operations and data model functionality. + * Integration tests for PhoenixSyncTableOutputRepository and PhoenixSyncTableCheckpointOutputRow. + * Tests checkpoint table operations and data model functionality. */ -public class PhoenixSyncTableOutputRepositoryTest extends BaseTest { +@Category(NeedsOwnMiniClusterTest.class) +public class PhoenixSyncTableOutputRepositoryIT extends BaseTest { private Connection connection; private PhoenixSyncTableOutputRepository repository; From f21e8badf5255df63bbb2882d40c91bff9a7e8a8 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Wed, 26 Aug 2026 20:14:09 +0530 Subject: [PATCH 7/7] PHOENIX-7993: Move PhoenixSyncTableOutputRepositoryTest class as an Integration test --- .../apache/phoenix/jdbc/PhoenixDriver.java | 4 +- .../phoenix/jdbc/PhoenixEmbeddedDriver.java | 69 +++++-------------- .../apache/phoenix/monitoring/MetricType.java | 2 - .../ConnectionQueryServicesMetrics.java | 9 +-- .../ConnectionQueryServicesMetricsIT.java | 21 ------ ...ectionQueryServicesMetricsManagerTest.java | 27 +------- 6 files changed, 28 insertions(+), 104 deletions(-) diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java index f3784183555..953bbc5bd57 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixDriver.java @@ -41,7 +41,6 @@ import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesImpl; import org.apache.phoenix.query.QueryServicesOptions; -import org.apache.phoenix.util.EnvironmentEdgeManager; import org.apache.phoenix.util.PropertiesUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -206,7 +205,6 @@ public boolean acceptsURL(String url) throws SQLException { @Override public Connection connect(String url, Properties info) throws SQLException { - long connectionStartTime = EnvironmentEdgeManager.currentTimeMillis(); GLOBAL_PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER.increment(); if (!acceptsURL(url)) { GLOBAL_FAILED_PHOENIX_CONNECTIONS.increment(); @@ -215,7 +213,7 @@ public Connection connect(String url, Properties info) throws SQLException { lockInterruptibly(LockMode.READ); try { checkClosed(); - return createConnection(url, info, connectionStartTime); + return createConnection(url, info); } catch (SQLException sqlException) { if (sqlException.getErrorCode() != SQLExceptionCode.NEW_CONNECTION_THROTTLED.getErrorCode()) { GLOBAL_FAILED_PHOENIX_CONNECTIONS.increment(); diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java index ea1d416fd8a..b5bbe2ea552 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java @@ -17,8 +17,6 @@ */ package org.apache.phoenix.jdbc; -import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTION_CREATION_TIME_MS; -import static org.apache.phoenix.query.QueryServices.QUERY_SERVICES_NAME; import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM; import java.sql.Connection; @@ -26,18 +24,17 @@ import java.sql.DriverPropertyInfo; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; -import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.logging.Logger; import javax.annotation.concurrent.Immutable; import org.apache.phoenix.coprocessorclient.MetaDataProtocol; -import org.apache.phoenix.monitoring.ConnectionQueryServicesMetric; -import org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesMetricsManager; import org.apache.phoenix.query.ConnectionQueryServices; import org.apache.phoenix.query.QueryServices; -import org.apache.phoenix.util.*; +import org.apache.phoenix.util.PhoenixRuntime; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.SQLCloseable; import org.apache.phoenix.thirdparty.com.google.common.collect.ImmutableMap; @@ -122,59 +119,31 @@ public boolean acceptsURL(String url) throws SQLException { @Override public Connection connect(String url, Properties info) throws SQLException { - long connectionStartTime = EnvironmentEdgeManager.currentTimeMillis(); if (!acceptsURL(url)) { return null; } - return createConnection(url, info, connectionStartTime); + return createConnection(url, info); } - protected final Connection createConnection(String url, Properties info, - long connectionCreationTime) throws SQLException { + protected final Connection createConnection(String url, Properties info) throws SQLException { Properties augmentedInfo = PropertiesUtil.deepCopy(info); augmentedInfo.putAll(getDefaultProps().asMap()); - Connection connection = null; - try { - if (url.contains("|")) { - // Get HAURLInfo to pass it to connection creation - HAURLInfo haurlInfo = HighAvailabilityGroup.getUrlInfo(url, augmentedInfo); - // High availability connection using two clusters - Optional haGroup = HighAvailabilityGroup.get(url, augmentedInfo); - if (haGroup.isPresent()) { - connection = haGroup.get().connect(augmentedInfo, haurlInfo); - setPhoenixConnectionTime(connectionCreationTime, connection); - return connection; - } else { - // If empty HA group is returned, fall back to single cluster. - url = HighAvailabilityGroup.getFallbackCluster(url, info).orElseThrow( - () -> new SQLException( - "HA group can not be initialized, fallback to single cluster")); - } - } - ConnectionQueryServices cqs = getConnectionQueryServices(url, augmentedInfo); - connection = cqs.connect(url, augmentedInfo); - setPhoenixConnectionTime(connectionCreationTime, connection); - Map> metrics = - ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); - if (!metrics.isEmpty()) { - List serviceMetrics = metrics.get("DEFAULT_CQSN"); - } - return connection; - } catch (SQLException e) { - if (connection != null) { - connection.close(); + if (url.contains("|")) { + // Get HAURLInfo to pass it to connection creation + HAURLInfo haurlInfo = HighAvailabilityGroup.getUrlInfo(url, augmentedInfo); + // High availability connection using two clusters + Optional haGroup = HighAvailabilityGroup.get(url, augmentedInfo); + if (haGroup.isPresent()) { + return haGroup.get().connect(augmentedInfo, haurlInfo); + } else { + // If empty HA group is returned, fall back to single cluster. + url = HighAvailabilityGroup.getFallbackCluster(url, info).orElseThrow( + () -> new SQLException("HA group can not be initialized, fallback to single cluster")); } - throw e; } - } - - private void setPhoenixConnectionTime(long connectionCreationTime, Connection connection) { - String connectionQueryServiceName = - ((PhoenixConnection) connection).getQueryServices().getConfiguration() - .get(QUERY_SERVICES_NAME); - ConnectionQueryServicesMetricsManager.updateMetrics(connectionQueryServiceName, - PHOENIX_CONNECTION_CREATION_TIME_MS, connectionCreationTime); + ConnectionQueryServices cqs = getConnectionQueryServices(url, augmentedInfo); + return cqs.connect(url, augmentedInfo); } /** diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java index de559e4aff4..ff80705c0d4 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java @@ -236,8 +236,6 @@ public enum MetricType { PHOENIX_CONNECTIONS_FAILED_COUNTER("cf", "Number of client Phoenix Connections Failed to open" + ", not including throttled connections", LogLevel.OFF, PLong.INSTANCE), - PHOENIX_CONNECTION_CREATION_TIME_MS("cct", - "Time spent in creating Phoenix connections in milliseconds", LogLevel.OFF, PLong.INSTANCE), CLIENT_METADATA_CACHE_MISS_COUNTER("cmcm", "Number of cache misses for the CQSI cache.", LogLevel.DEBUG, PLong.INSTANCE), CLIENT_METADATA_CACHE_HIT_COUNTER("cmch", "Number of cache hits for the CQSI cache.", diff --git a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java index 8c3ac719d27..575d38530eb 100644 --- a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java +++ b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetrics.java @@ -17,6 +17,10 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; +import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -26,8 +30,6 @@ import org.apache.phoenix.monitoring.ConnectionQueryServicesMetricImpl; import org.apache.phoenix.monitoring.MetricType; -import static org.apache.phoenix.monitoring.MetricType.*; - /** * Class for Connection Query Service Metrics. */ @@ -40,8 +42,7 @@ public enum QueryServiceMetrics { CONNECTION_QUERY_SERVICE_OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER( OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER), CONNECTION_QUERY_SERVICE_PHOENIX_CONNECTIONS_THROTTLED_COUNTER( - PHOENIX_CONNECTIONS_THROTTLED_COUNTER), - CONNECTION_QUERY_SERVICE_CREATION_TIME(PHOENIX_CONNECTION_CREATION_TIME_MS); + PHOENIX_CONNECTIONS_THROTTLED_COUNTER); private MetricType metricType; private ConnectionQueryServicesMetric metric; diff --git a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java index 3b7fec50569..57791072cda 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsIT.java @@ -226,27 +226,6 @@ public void testMultipleCQSIMetricsInParallel() throws Exception { assertEquals("Number of passing CSQI Metrics check should be : ", 4, counter.get()); } - @Test - public void testConnectionTime() { - Map> metrics = - ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); - List serviceMetrics = metrics.get("DEFAULT_CQSN"); - assertNotNull("No metrics found for service: DEFAULT_CQSN", serviceMetrics); - - // Find connection creation time metric - boolean foundMetric = false; - for (ConnectionQueryServicesMetric metric : serviceMetrics) { - System.out.println("Found metric: " + metric.getMetricType() + " = " + metric.getValue()); - if (metric.getMetricType() == PHOENIX_CONNECTION_CREATION_TIME_MS) { - assertTrue("Connection creation time should be >= 0", metric.getValue() >= 0); - foundMetric = true; - break; - } - } - assertTrue("Connection creation time metric not found", foundMetric); - - } - private void checkConnectionQueryServiceMetricsValues(String queryServiceName) throws Exception { String CREATE_TABLE_DDL = "CREATE TABLE IF NOT EXISTS %s (K VARCHAR(10) NOT NULL" + " PRIMARY KEY, V VARCHAR)"; diff --git a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java index 039b7be051f..86fc007b906 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/connectionqueryservice/ConnectionQueryServicesMetricsManagerTest.java @@ -17,12 +17,13 @@ */ package org.apache.phoenix.monitoring.connectionqueryservice; -import static org.apache.phoenix.monitoring.MetricType.*; +import static org.apache.phoenix.monitoring.MetricType.OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER; +import static org.apache.phoenix.monitoring.MetricType.PHOENIX_CONNECTIONS_THROTTLED_COUNTER; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.connectionQueryServiceNames; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.openInternalPhoenixConnCounter; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.openPhoenixConnCounter; import static org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesNameMetricsTest.phoenixConnThrottledCounter; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; @@ -31,7 +32,6 @@ import org.apache.phoenix.monitoring.ConnectionQueryServicesMetric; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesOptions; -import org.apache.phoenix.util.PhoenixRuntime; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; @@ -101,27 +101,6 @@ public void testHistogramMetricsForOpenPhoenixConnectionCounter() { } } - @Test - public void testConnectionTime() { - Map> metrics = - ConnectionQueryServicesMetricsManager.getAllConnectionQueryServicesMetrics(); - List serviceMetrics = metrics.get("DEFAULT_CQSN"); - assertNotNull("No metrics found for service: DEFAULT_CQSN", serviceMetrics); - - // Find connection creation time metric - boolean foundMetric = false; - for (ConnectionQueryServicesMetric metric : serviceMetrics) { - System.out.println("Found metric: " + metric.getMetricType() + " = " + metric.getValue()); - if (metric.getMetricType() == PHOENIX_CONNECTION_CREATION_TIME_MS) { - assertTrue("Connection creation time should be >= 0", metric.getValue() >= 0); - foundMetric = true; - break; - } - } - assertTrue("Connection creation time metric not found", foundMetric); - - } - private void updateMetricsAndHistogram(long counter, String connectionQueryServiceName) { ConnectionQueryServicesMetricsManager.updateMetrics(connectionQueryServiceName, OPEN_PHOENIX_CONNECTIONS_COUNTER, counter);