PHOENIX-7790 Add create command in PhoenixHAAdminTool for creating a new HAGroup#2397
Merged
Merged
Conversation
tkhurana
reviewed
Apr 9, 2026
| "SELECT COUNT(*) FROM " + SYSTEM_HA_GROUP_NAME + " WHERE " + HA_GROUP_NAME + " = ?"; | ||
| try ( | ||
| PhoenixConnection conn = (PhoenixConnection) DriverManager | ||
| .getConnection(JDBC_PROTOCOL_ZK + JDBC_PROTOCOL_SEPARATOR + localZkUrl); |
Contributor
There was a problem hiding this comment.
Better to use ConnectionUtil.getInputConnection() than constructing the url by hand.
tkhurana
reviewed
Apr 9, 2026
|
|
||
| try ( | ||
| PhoenixConnection conn = (PhoenixConnection) DriverManager | ||
| .getConnection(JDBC_PROTOCOL_ZK + JDBC_PROTOCOL_SEPARATOR + localZkUrl); |
tkhurana
reviewed
Apr 9, 2026
|
|
||
| /** | ||
| * 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 |
Contributor
There was a problem hiding this comment.
Is this comment correct ? It seems the create command is also creating the znode.
tkhurana
requested changes
Apr 10, 2026
tkhurana
reviewed
Apr 10, 2026
| * 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. | ||
| */ |
Contributor
There was a problem hiding this comment.
Can we expose this method as an API also ? It will be useful from a test perspective.
Contributor
Author
There was a problem hiding this comment.
Discussed offline and we plan to pick this later when time permits.
tkhurana
approved these changes
Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
createcommand toPhoenixHAAdminToolthat allows administrators to create a new HA group entry in theSYSTEM.HA_GROUPtable 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)createcommand: Registered asCMD_CREATEin the mainrun()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 intoSYSTEM.HA_GROUPviainsertIntoSystemTable(), and triggers ZK znode initialization viaHAGroupStoreManager.getHAGroupStoreRecord().haGroupExistsInSystemTable(): QueriesSYSTEM.HA_GROUPusingConnectionUtil.getInputConnection()to check for pre-existing entries, enabling idempotent behavior.insertIntoSystemTable(): Performs anUPSERT INTO SYSTEM.HA_GROUPwith 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 toClusterRoleenum.--zk-url-1,--cluster-url-1,--cluster-role-1,--hdfs-url-1and their cluster-2 counterparts.printUsage()and addedprintCreateHelp().--dry-runto preview what would be created without persisting changes.--admin-version(defaults to 1).PhoenixHAAdminToolIT.java(+144 lines)testCreateCommandNewHAGroup: Verifies end-to-end creation - checksSYSTEM.HA_GROUProw is written with correct columns and ZK znode is created with matching fields (policy, cluster URLs, HDFS URLs, admin version).testCreateCommandAlreadyExists: Verifies idempotency - runningcreateon an existing group prints a skip message and does not overwrite the existing row.testCreateCommandDryRun: Verifies dry-run mode shows planned creation without writing toSYSTEM.HA_GROUP.testCreateCommandMissingRequiredArg: VerifiesRET_ARGUMENT_ERRORis returned when a required option (e.g.,--policy) is omitted.Design Decisions
createcommand uses--zk-url-1/2,--cluster-url-1/2, etc., rather than--cluster-url/--peer-cluster-url(which theupdatecommand uses). This avoids the local/peer distinction and lets the same command run identically on both clusters.RET_SUCCESSwith a skip message, making it safe to re-run.HAGroupStoreManager.getHAGroupStoreRecord()which lazily initializes the ZK znode from the system table entry.ConnectionUtil.getInputConnection(): Used instead of manually constructing JDBC URLs, per project convention.Usage
Run this same command on both clusters to set up the HA pair.
Test Plan
testCreateCommandNewHAGroup- verifies SYSTEM.HA_GROUP row and ZK znode creationtestCreateCommandAlreadyExists- verifies idempotent skip behaviortestCreateCommandDryRun- verifies no side effects in dry-run modetestCreateCommandMissingRequiredArg- verifies argument validation