This is an automated email from the ASF dual-hosted git repository.

lokiore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new 40c2934a34 PHOENIX-7586 (ADDENDUM) :- Handle Role transitions for 
ActiveToStanby role in Failover HAPolicy (#2174)
40c2934a34 is described below

commit 40c2934a34a34b587c41179dd2dc815a3c0cf74b
Author: Lokesh Khurana <[email protected]>
AuthorDate: Tue Jun 10 10:49:53 2025 -0700

    PHOENIX-7586 (ADDENDUM) :- Handle Role transitions for ActiveToStanby role 
in Failover HAPolicy (#2174)
    
    Closing connections when we transition to either Standby or 
Active_To_Standby instead of closing it at Standby only.
---
 .../phoenix/jdbc/HighAvailabilityPolicy.java       | 27 +++----
 .../phoenix/jdbc/FailoverPhoenixConnection2IT.java | 84 +---------------------
 2 files changed, 17 insertions(+), 94 deletions(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityPolicy.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityPolicy.java
index 05bee338a2..727cb4b680 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityPolicy.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityPolicy.java
@@ -75,20 +75,20 @@ public enum HighAvailabilityPolicy {
                         "Doing nothing for Cluster Role Change");
                 return;
             }
-            if ((oldRecord.getRole1() == ACTIVE || oldRecord.getRole1() == 
ACTIVE_TO_STANDBY)
-                    && newRecord.getRole1() == STANDBY) {
-                transitStandby(haGroup, oldRecord.getUrl1(), 
oldRecord.getRegistryType());
+            if (oldRecord.getRole1() == ACTIVE &&
+                    (newRecord.getRole1() == STANDBY || newRecord.getRole1() 
== ACTIVE_TO_STANDBY)) {
+                transitStandby(haGroup, oldRecord.getUrl1(), 
oldRecord.getRegistryType(),
+                        newRecord.getRole1());
             }
-            if ((oldRecord.getRole2() == ACTIVE || oldRecord.getRole2() == 
ACTIVE_TO_STANDBY)
-                    && newRecord.getRole2() == STANDBY) {
-                transitStandby(haGroup, oldRecord.getUrl2(), 
oldRecord.getRegistryType());
+            if (oldRecord.getRole2() == ACTIVE &&
+                    (newRecord.getRole2() == STANDBY || newRecord.getRole2() 
== ACTIVE_TO_STANDBY)) {
+                transitStandby(haGroup, oldRecord.getUrl2(), 
oldRecord.getRegistryType(),
+                        newRecord.getRole2());
             }
-            if ((oldRecord.getRole1() != ACTIVE && oldRecord.getRole1() != 
ACTIVE_TO_STANDBY)
-                    && (newRecord.getRole1() == ACTIVE || newRecord.getRole1() 
== ACTIVE_TO_STANDBY)) {
+            if (oldRecord.getRole1() != ACTIVE && newRecord.getRole1() == 
ACTIVE) {
                 transitActive(haGroup, oldRecord.getUrl1(), 
oldRecord.getRegistryType());
             }
-            if ((oldRecord.getRole2() != ACTIVE && oldRecord.getRole2() != 
ACTIVE_TO_STANDBY)
-                    && (newRecord.getRole2() == ACTIVE || newRecord.getRole2() 
== ACTIVE_TO_STANDBY)) {
+            if (oldRecord.getRole2() != ACTIVE && newRecord.getRole2() == 
ACTIVE) {
                 transitActive(haGroup, oldRecord.getUrl2(), 
oldRecord.getRegistryType());
             }
         }
@@ -154,10 +154,11 @@ public enum HighAvailabilityPolicy {
         }
 
         private void transitStandby(HighAvailabilityGroup haGroup, String url,
-                                    ClusterRoleRecord.RegistryType 
registryType) throws SQLException {
+                                    ClusterRoleRecord.RegistryType 
registryType,
+                                    ClusterRoleRecord.ClusterRole newRole) 
throws SQLException {
             // Close connections when a previously ACTIVE HBase cluster 
becomes STANDBY.
-            LOG.info("Cluster {} becomes STANDBY in HA group {}, now close all 
its connections",
-                    url, haGroup.getGroupInfo());
+            LOG.info("Cluster {} becomes {} in HA group {}, now close all its 
connections",
+                    url, newRole, haGroup.getGroupInfo());
             closeConnections(haGroup, url, registryType);
         }
 
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/FailoverPhoenixConnection2IT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/FailoverPhoenixConnection2IT.java
index 4a50c056de..d9520a8409 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/jdbc/FailoverPhoenixConnection2IT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/jdbc/FailoverPhoenixConnection2IT.java
@@ -532,20 +532,12 @@ public class FailoverPhoenixConnection2IT {
     }
 
     /**
-     * Test connections behaviour when doing 2-step failover.
-     * cluster 1 ( ACTIVE --> ACTIVE_TO_STANDBY --> STANDBY )
+     * Test connections should close early when transitioning to ATS.
+     * cluster 1 ( ACTIVE --> ACTIVE_TO_STANDBY )
      */
     @Test(timeout = 300000)
-    public void 
testAllWrappedConnectionsClosedAtRightTimeDuringClusterRoleChange()
+    public void testAllWrappedConnectionsClosedWhenRoleChangeFromActiveToATS()
             throws Exception {
-        //Write Some data to ACTIVE cluster
-        Connection connection = createFailoverConnection();
-        Statement statement = connection.createStatement();
-        short numOfRows = 100;
-        for (int i = 0; i < numOfRows; i++) {
-            statement.executeUpdate(String.format("UPSERT INTO %s VALUES(%d, 
1984)", tableName, i));
-        }
-        connection.commit();
 
         //Creating some connections to ACTIVE cluster
         short numberOfConnections = 10;
@@ -558,83 +550,13 @@ public class FailoverPhoenixConnection2IT {
         //Transit Role1 ACTIVE --> ACTIVE_TO_STANDBY
         CLUSTERS.transitClusterRole(haGroup, 
ClusterRoleRecord.ClusterRole.ACTIVE_TO_STANDBY,
                 ClusterRoleRecord.ClusterRole.STANDBY);
-        //Connections should be open
-        assertFalse(connection.isClosed());
-        for (short i = 0; i < numberOfConnections; i++) {
-            FailoverPhoenixConnection conn = ((FailoverPhoenixConnection) 
connectionList.get(i));
-            assertFalse(conn.isClosed());
-            assertFalse(conn.getWrappedConnection().isClosed());
-        }
 
-        //Read with the open connection for random id
-        try {
-            ResultSet rs = connection.createStatement().executeQuery(
-                    String.format("SELECT v FROM %s WHERE id = %d", tableName, 
50));
-            assertTrue(rs.next());
-            assertEquals(1984, rs.getInt(1));
-        } catch (Exception e) {
-            fail();
-        }
-
-        //Transit Role1 ACTIVE_TO_STANDBY --> STANDBY
-        CLUSTERS.transitClusterRole(haGroup, 
ClusterRoleRecord.ClusterRole.STANDBY,
-                ClusterRoleRecord.ClusterRole.STANDBY);
         //Connections should be closed
         for (short i = 0; i < numberOfConnections; i++) {
             FailoverPhoenixConnection conn = ((FailoverPhoenixConnection) 
connectionList.get(i));
             assertFalse(conn.isClosed());
             assertTrue(conn.getWrappedConnection().isClosed());
         }
-
-        //Try reading again, but it should throw SQLException
-        try {
-            connection.createStatement().executeQuery(
-                    String.format("SELECT v FROM %s WHERE id = %d", tableName, 
50));
-            fail();
-        } catch (Exception e) {
-            if (e instanceof SQLException) {
-                //Expected as connections should be closed
-            } else {
-                fail();
-            }
-        }
-    }
-
-    /**
-     * Test early rollback of Failover Policy where connections should not be 
affected
-     * ACTIVE --> ACTIVE_TO_STANDBY and then ACTIVE_TO_STANDBY --> ACTIVE
-     */
-    @Test(timeout = 300000)
-    public void testEarlyRollbackHasNoEffectOnFailoverConnections() throws 
Exception {
-        //Creating some connections to ACTIVE cluster
-        short numberOfConnections = 3;
-        //Create FailoverPhoenixConnections with default urls
-        List<Connection> connectionList = new ArrayList<>(numberOfConnections);
-        for (short i = 0; i < numberOfConnections; i++) {
-            connectionList.add(createFailoverConnection());
-        }
-
-        //Transit Role1 ACTIVE --> ACTIVE_TO_STANDBY
-        CLUSTERS.transitClusterRole(haGroup, 
ClusterRoleRecord.ClusterRole.ACTIVE_TO_STANDBY,
-                ClusterRoleRecord.ClusterRole.STANDBY);
-        //Connections should be open
-        for (short i = 0; i < numberOfConnections; i++) {
-            FailoverPhoenixConnection conn = ((FailoverPhoenixConnection) 
connectionList.get(i));
-            assertFalse(conn.isClosed());
-            assertFalse(conn.getWrappedConnection().isClosed());
-        }
-
-        //Transit Role1 ACTIVE_TO_STANDBY --> ACTIVE
-        CLUSTERS.transitClusterRole(haGroup, 
ClusterRoleRecord.ClusterRole.ACTIVE,
-                ClusterRoleRecord.ClusterRole.STANDBY);
-        //Connections should still be open
-        for (short i = 0; i < numberOfConnections; i++) {
-            FailoverPhoenixConnection conn = ((FailoverPhoenixConnection) 
connectionList.get(i));
-            assertFalse(conn.isClosed());
-            assertFalse(conn.getWrappedConnection().isClosed());
-            //closing connections
-            conn.close();
-        }
     }
 
     /**

Reply via email to