ritegarg commented on code in PR #2302:
URL: https://github.com/apache/phoenix/pull/2302#discussion_r2464060516


##########
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HAGroupStoreManager.java:
##########
@@ -187,13 +286,97 @@ public void setHAGroupStatusToStoreAndForward(final 
String haGroupName)
      *
      * @param haGroupName name of the HA group
      * @throws IOException when HAGroupStoreClient is not healthy.
+     * @throws StaleHAGroupStoreRecordVersionException if the cached version 
is invalid,
+     *      the state might have been updated by some other RS,
+     *      check the state again and retry if the use case still needs it.
+     * @throws InvalidClusterRoleTransitionException if the transition is 
invalid,
+     *      the state might have been updated by some other RS,
+     *      check the state again and retry if the use case still needs it.
      */
     public void setHAGroupStatusToSync(final String haGroupName)
             throws IOException, StaleHAGroupStoreRecordVersionException,
-            InvalidClusterRoleTransitionException {
-        HAGroupStoreClient haGroupStoreClient = 
getHAGroupStoreClient(haGroupName);
+            InvalidClusterRoleTransitionException, SQLException {
+        HAGroupStoreClient haGroupStoreClient
+                = getHAGroupStoreClientAndSetupFailoverManagement(haGroupName);
+        HAGroupStoreRecord haGroupStoreRecord = 
haGroupStoreClient.getHAGroupStoreRecord();
+        if (haGroupStoreRecord != null) {
+            HAGroupState targetHAGroupState = 
haGroupStoreRecord.getHAGroupState()
+                    == HAGroupState.ACTIVE_NOT_IN_SYNC_TO_STANDBY
+                    ? ACTIVE_IN_SYNC_TO_STANDBY
+                    : ACTIVE_IN_SYNC;
+            haGroupStoreClient.setHAGroupStatusIfNeeded(targetHAGroupState);
+        } else {
+            throw new IOException("Current HAGroupStoreRecord is null for HA 
group: "
+                    + haGroupName);
+        }
+    }
+
+    /**
+     * Initiates failover on the active cluster by transitioning to the 
appropriate TO_STANDBY state.
+     * Checks current state and transitions to:
+     * - ACTIVE_IN_SYNC_TO_STANDBY if currently ACTIVE_IN_SYNC
+     * - ACTIVE_NOT_IN_SYNC_TO_STANDBY if currently ACTIVE_NOT_IN_SYNC
+     *
+     * @param haGroupName name of the HA group
+     * @throws IOException when HAGroupStoreClient is not healthy.
+     * @throws StaleHAGroupStoreRecordVersionException when the version is 
stale,
+     *      the state might have been updated by some other RS,
+     *      check the state again and retry if the use case still needs it.
+     * @throws InvalidClusterRoleTransitionException when the transition is 
not valid,
+     *      the state might have been updated by some other RS,
+     *      check the state again and retry if the use case still needs it.
+     * @throws SQLException when there is an error with the database operation
+     */
+    public void initiateFailoverOnActiveCluster(final String haGroupName)

Review Comment:
   @Himanshu-g81 you can use setHAGroupStatusToSync



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to