jpisaac commented on code in PR #2074:
URL: https://github.com/apache/phoenix/pull/2074#discussion_r1994114851
##########
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/HighAvailabilityPolicy.java:
##########
@@ -44,63 +46,96 @@ public Connection provide(HighAvailabilityGroup haGroup,
Properties info,
FailoverPhoenixContext context = new FailoverPhoenixContext(info,
haGroup, haURLInfo);
return new FailoverPhoenixConnection(context);
}
+
@Override
void transitClusterRole(HighAvailabilityGroup haGroup,
ClusterRoleRecord oldRecord,
ClusterRoleRecord newRecord) throws SQLException {
if (oldRecord.getRole1() == ACTIVE && newRecord.getRole1() ==
STANDBY) {
- transitStandby(haGroup, oldRecord.getZk1());
+ transitStandby(haGroup, oldRecord.getUrl1(),
oldRecord.getRegistryType());
}
if (oldRecord.getRole2() == ACTIVE && newRecord.getRole2() ==
STANDBY) {
- transitStandby(haGroup, oldRecord.getZk2());
+ transitStandby(haGroup, oldRecord.getUrl2(),
oldRecord.getRegistryType());
}
if (oldRecord.getRole1() != ACTIVE && newRecord.getRole1() ==
ACTIVE) {
- transitActive(haGroup, oldRecord.getZk1());
+ transitActive(haGroup, oldRecord.getUrl1(),
oldRecord.getRegistryType());
}
if (oldRecord.getRole2() != ACTIVE && newRecord.getRole2() ==
ACTIVE) {
- transitActive(haGroup, oldRecord.getZk2());
+ transitActive(haGroup, oldRecord.getUrl2(),
oldRecord.getRegistryType());
}
}
- private void transitStandby(HighAvailabilityGroup haGroup, String
zkUrl)
- 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",
- zkUrl, haGroup.getGroupInfo());
- ConnectionQueryServices cqs = null;
-
- //Close connections for every HAURLInfo's (different principal)
conn for a give HAGroup
- for (HAURLInfo haurlInfo :
HighAvailabilityGroup.URLS.get(haGroup.getGroupInfo())) {
- try {
- String jdbcZKUrl =
haGroup.getGroupInfo().getJDBCUrl(zkUrl, haurlInfo);
- cqs = PhoenixDriver.INSTANCE.getConnectionQueryServices(
- jdbcZKUrl, haGroup.getProperties());
- cqs.closeAllConnections(new SQLExceptionInfo
- .Builder(SQLExceptionCode.HA_CLOSED_AFTER_FAILOVER)
- .setMessage("Phoenix connection got closed due to
failover")
-
.setHaGroupInfo(haGroup.getGroupInfo().toString()));
- LOG.info("Closed all connections to cluster {} for HA
group {}",
- jdbcZKUrl, haGroup.getGroupInfo());
- } finally {
- if (cqs != null) {
- //CQS is closed but it is not invalidated from global
cache in PhoenixDriver
- //so that any new connection will get error instead of
creating a new CQS
- LOG.info("Closing CQS after cluster '{}' becomes
STANDBY", zkUrl);
- cqs.close();
- LOG.info("Successfully closed CQS after cluster '{}'
becomes STANDBY",
- zkUrl);
+
+ @Override
+ void transitRoleRecordRegistry(HighAvailabilityGroup haGroup,
ClusterRoleRecord oldRecord,
+ ClusterRoleRecord newRecord) throws
SQLException {
+ Optional<String> activeUrl = oldRecord.getActiveUrl();
+
+ //Close connections for Active HBase cluster as there is a change
in Registry Type
+ if (activeUrl.isPresent()) {
+ LOG.info("Cluster {} has a change in registryType in HA group
{}, now closing "
+ + "all its connections", activeUrl.get(),
oldRecord.getRegistryType());
+ closeConnections(haGroup, activeUrl.get(),
oldRecord.getRegistryType());
+ } else {
+ LOG.info("None of the cluster in HA Group {} is active",
haGroup);
+ }
+ }
+
+ /**
+ * For FAILOVER Policy if there is a change in active url or no new
active url then close all connections.
+ * (url1, ACTIVE, url2, STANDBY) --> (url1, ACTIVE, url3, STANDBY)
//Nothing is needed
+ * (url1, ACTIVE, url2, STANDBY) --> (url3, ACTIVE, url2, STANDBY)
//Active url change close connections
+ * (url1, ACTIVE, url2, STANDBY) --> (url3, ACTIVE, url4, STANDBY)
//Active url change close connections
+ * (url1, ACTIVE, url2, STANDBY) --> (url3, ACTIVE, url1, STANDBY)
+ * //Here active became standby but other url
changed close connections
+ * (url1, OFFLINE, url2, STANDBY) --> (url3, ACTIVE, url2, STANDBY)
//Nothing to do as there were no connections
+ * (url1, ACTIVE, url2, STANDBY) --> (url3, OFFLINE, url2, STANDBY)
//Closing old connections as no new active url
+ * @param haGroup The high availability (HA) group
+ * @param oldRecord The older cluster role record cached in this
client for the given HA group
+ * @param newRecord New cluster role record read from one ZooKeeper
cluster znode
+ * @throws SQLException when not able to close connections
Review Comment:
Need to explain what url1 ... url4 stand for. Not sure what the transitions
standfor?
--
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]