Skip to content

PHOENIX-7790 Add create command in PhoenixHAAdminTool for creating a new HAGroup#2397

Merged
tkhurana merged 6 commits into
apache:PHOENIX-7562-feature-newfrom
ritegarg:PHOENIX-7790
Apr 11, 2026
Merged

PHOENIX-7790 Add create command in PhoenixHAAdminTool for creating a new HAGroup#2397
tkhurana merged 6 commits into
apache:PHOENIX-7562-feature-newfrom
ritegarg:PHOENIX-7790

Conversation

@ritegarg
Copy link
Copy Markdown
Contributor

@ritegarg ritegarg commented Mar 30, 2026

Summary

Adds a new create command to PhoenixHAAdminTool that allows administrators to create a new HA group entry in the SYSTEM.HA_GROUP table and initialize the corresponding ZooKeeper znode. This is a prerequisite step for setting up a new High Availability (HA) cluster pair.

Previously, HA group entries had to be created through lower-level programmatic APIs or test utilities. This PR exposes a CLI-based workflow consistent with the existing admin tool commands (update, get, list, initiate-failover, abort-failover).

What Changed

PhoenixHAAdminTool.java (+259 lines)

  • New create command: Registered as CMD_CREATE in the main run() dispatch, alongside existing commands.
  • executeCreate() method: Parses CLI arguments for both clusters using a symmetric slot-based model (cluster 1 / cluster 2 instead of local / peer), checks for existing entries (idempotent), inserts into SYSTEM.HA_GROUP via insertIntoSystemTable(), and triggers ZK znode initialization via HAGroupStoreManager.getHAGroupStoreRecord().
  • haGroupExistsInSystemTable(): Queries SYSTEM.HA_GROUP using ConnectionUtil.getInputConnection() to check for pre-existing entries, enabling idempotent behavior.
  • insertIntoSystemTable(): Performs an UPSERT INTO SYSTEM.HA_GROUP with all slot-based columns (ZK_URL_1/2, CLUSTER_URL_1/2, CLUSTER_ROLE_1/2, HDFS_URL_1/2, POLICY, VERSION).
  • parseClusterRole(): Validates and converts string role values to ClusterRole enum.
  • 8 new CLI options: --zk-url-1, --cluster-url-1, --cluster-role-1, --hdfs-url-1 and their cluster-2 counterparts.
  • Help text and usage examples: Updated printUsage() and added printCreateHelp().
  • Supports --dry-run to preview what would be created without persisting changes.
  • Supports optional --admin-version (defaults to 1).

PhoenixHAAdminToolIT.java (+144 lines)

  • testCreateCommandNewHAGroup: Verifies end-to-end creation - checks SYSTEM.HA_GROUP row is written with correct columns and ZK znode is created with matching fields (policy, cluster URLs, HDFS URLs, admin version).
  • testCreateCommandAlreadyExists: Verifies idempotency - running create on an existing group prints a skip message and does not overwrite the existing row.
  • testCreateCommandDryRun: Verifies dry-run mode shows planned creation without writing to SYSTEM.HA_GROUP.
  • testCreateCommandMissingRequiredArg: Verifies RET_ARGUMENT_ERROR is returned when a required option (e.g., --policy) is omitted.

Design Decisions

  • Symmetric slot-based options: The create command uses --zk-url-1/2, --cluster-url-1/2, etc., rather than --cluster-url / --peer-cluster-url (which the update command uses). This avoids the local/peer distinction and lets the same command run identically on both clusters.
  • Idempotent: If the HA group already exists, the command returns RET_SUCCESS with a skip message, making it safe to re-run.
  • ZK znode initialization: After inserting the system table row, the command calls HAGroupStoreManager.getHAGroupStoreRecord() which lazily initializes the ZK znode from the system table entry.
  • Connection via ConnectionUtil.getInputConnection(): Used instead of manually constructing JDBC URLs, per project convention.

Usage

phoenix-consistentha-admin-tool create \
  -g myHAGroup -p FAILOVER \
  -zk1 zk-host1:2181:/hbase -c1 hmaster1:16000 -cr1 ACTIVE \
  -zk2 zk-host2:2181:/hbase -c2 hmaster2:16000 -cr2 STANDBY \
  -hdfs1 hdfs://host1:8020 -hdfs2 hdfs://host2:8020

Run this same command on both clusters to set up the HA pair.

Test Plan

  • testCreateCommandNewHAGroup - verifies SYSTEM.HA_GROUP row and ZK znode creation
  • testCreateCommandAlreadyExists - verifies idempotent skip behavior
  • testCreateCommandDryRun - verifies no side effects in dry-run mode
  • testCreateCommandMissingRequiredArg - verifies argument validation

"SELECT COUNT(*) FROM " + SYSTEM_HA_GROUP_NAME + " WHERE " + HA_GROUP_NAME + " = ?";
try (
PhoenixConnection conn = (PhoenixConnection) DriverManager
.getConnection(JDBC_PROTOCOL_ZK + JDBC_PROTOCOL_SEPARATOR + localZkUrl);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use ConnectionUtil.getInputConnection() than constructing the url by hand.


try (
PhoenixConnection conn = (PhoenixConnection) DriverManager
.getConnection(JDBC_PROTOCOL_ZK + JDBC_PROTOCOL_SEPARATOR + localZkUrl);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


/**
* Test that the create command successfully creates a new HA group entry in SYSTEM.HA_GROUP. The
* ZK znode should NOT be created by the create command (it initializes lazily on first access via
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct ? It seems the create command is also creating the znode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is, fixed

* prints a skip message and returns success without modifying the existing row. The ZK znode is
* initialized automatically on first access by HAGroupStoreClient. Run the same command on both
* clusters.
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expose this method as an API also ? It will be useful from a test perspective.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline and we plan to pick this later when time permits.

@ritegarg ritegarg requested a review from tkhurana April 10, 2026 17:14
@tkhurana tkhurana merged commit 84ed758 into apache:PHOENIX-7562-feature-new Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants