kadirozde commented on code in PR #2310:
URL: https://github.com/apache/phoenix/pull/2310#discussion_r2515660972


##########
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixHAAdminTool.java:
##########
@@ -17,187 +17,1479 @@
  */
 package org.apache.phoenix.jdbc;
 
-import java.io.FileReader;
-import java.io.Reader;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
-import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
 
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.CommandLine;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.CommandLineParser;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.HelpFormatter;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.Option;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.Options;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.PosixParser;
-import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.util.GenericOptionsParser;
 import org.apache.hadoop.util.Tool;
 import org.apache.hadoop.util.ToolRunner;
+import org.apache.phoenix.exception.StaleHAGroupStoreRecordVersionException;
+import org.apache.phoenix.jdbc.ClusterRoleRecord.ClusterRole;
+import org.apache.phoenix.jdbc.HAGroupStoreRecord.HAGroupState;
 import org.apache.phoenix.jdbc.PhoenixHAAdmin.HighAvailibilityCuratorProvider;
-import org.apache.phoenix.util.JacksonUtil;
 import 
org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting;
-import org.apache.phoenix.thirdparty.com.google.common.base.Preconditions;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.CommandLine;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.DefaultParser;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.Option;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.Options;
+import org.apache.zookeeper.data.Stat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static 
org.apache.phoenix.jdbc.HAGroupStoreClient.ZK_CONSISTENT_HA_GROUP_RECORD_NAMESPACE;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLUSTER_ROLE_1;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLUSTER_ROLE_2;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLUSTER_URL_1;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLUSTER_URL_2;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.HA_GROUP_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.POLICY;
+import static 
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_HA_GROUP_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VERSION;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ZK_URL_1;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ZK_URL_2;
+import static org.apache.phoenix.jdbc.PhoenixHAAdmin.getLocalZkUrl;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_ZK;
+
 /**
- * The command line tool to manage high availability (HA) groups and their 
cluster roles.
+ * Command-line tool to manage HAGroupStoreRecord configurations.
+ * Updates both ZooKeeper and System.HA_GROUP table atomically.
+ * Requires admin version increment for all updates.
  */
-@Deprecated //As we are moving ZKLess for HA, we will need to update or create 
new Tool from scratch
-//for Admin like commands used by this tool
 public class PhoenixHAAdminTool extends Configured implements Tool {
-    // Following are return value of this tool. We need this to be very 
explicit because external
-    // system calling this tool may need to retry, alert or audit the 
operations of cluster roles.
-    public static final int RET_SUCCESS = 0; // Saul Goodman
-    public static final int RET_ARGUMENT_ERROR = 1; // arguments are invalid
-    public static final int RET_SYNC_ERROR = 2; //  error to sync from 
manifest to ZK
-    public static final int RET_REPAIR_FOUND_INCONSISTENCIES = 3; // error to 
repair current ZK
+
+    // Return codes
+    public static final int RET_SUCCESS = 0;
+    public static final int RET_ARGUMENT_ERROR = 1;
+    public static final int RET_UPDATE_ERROR = 2;
+    public static final int RET_VERSION_CONFLICT = 3;
+    public static final int RET_VALIDATION_ERROR = 4;
 
     private static final Logger LOG = 
LoggerFactory.getLogger(PhoenixHAAdminTool.class);
 
-    private static final Option HELP_OPT = new Option("h", "help", false, 
"Show this help");
-    private static final Option FORCEFUL_OPT =
-            new Option("F", "forceful", false,
-                    "Forceful writing cluster role records ignoring errors on 
other clusters");
-    private static final Option MANIFEST_OPT =
-            new Option("m", "manifest", true, "Manifest file containing 
cluster role records");
-    private static final Option LIST_OPT =
-            new Option("l", "list", false, "List all HA groups stored on this 
ZK cluster");
-    private static final Option REPAIR_OPT = new Option("r", "repair", false,
-            "Verify all HA groups stored on this ZK cluster and repair if 
inconsistency found");
-    @VisibleForTesting
-    static final Options OPTIONS = new Options()
-            .addOption(HELP_OPT)
-            .addOption(FORCEFUL_OPT)
-            .addOption(MANIFEST_OPT)
-            .addOption(LIST_OPT)
-            .addOption(REPAIR_OPT);
+    // Commands
+    private static final String CMD_UPDATE = "update";

Review Comment:
   Can we write enough description for each command to explain what exactly the 
command does and which parameters it requires? What happens when one ZK URL vs 
two ZK URLs are given? How are failures handled?



##########
phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixHAAdminTool.java:
##########
@@ -17,187 +17,1479 @@
  */
 package org.apache.phoenix.jdbc;
 
-import java.io.FileReader;
-import java.io.Reader;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
-import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
 
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.CommandLine;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.CommandLineParser;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.HelpFormatter;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.Option;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.Options;
-import org.apache.phoenix.thirdparty.org.apache.commons.cli.PosixParser;
-import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.util.GenericOptionsParser;
 import org.apache.hadoop.util.Tool;
 import org.apache.hadoop.util.ToolRunner;
+import org.apache.phoenix.exception.StaleHAGroupStoreRecordVersionException;
+import org.apache.phoenix.jdbc.ClusterRoleRecord.ClusterRole;
+import org.apache.phoenix.jdbc.HAGroupStoreRecord.HAGroupState;
 import org.apache.phoenix.jdbc.PhoenixHAAdmin.HighAvailibilityCuratorProvider;
-import org.apache.phoenix.util.JacksonUtil;
 import 
org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting;
-import org.apache.phoenix.thirdparty.com.google.common.base.Preconditions;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.CommandLine;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.DefaultParser;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.Option;
+import org.apache.phoenix.thirdparty.org.apache.commons.cli.Options;
+import org.apache.zookeeper.data.Stat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static 
org.apache.phoenix.jdbc.HAGroupStoreClient.ZK_CONSISTENT_HA_GROUP_RECORD_NAMESPACE;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLUSTER_ROLE_1;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLUSTER_ROLE_2;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLUSTER_URL_1;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.CLUSTER_URL_2;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.HA_GROUP_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.POLICY;
+import static 
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_HA_GROUP_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VERSION;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ZK_URL_1;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ZK_URL_2;
+import static org.apache.phoenix.jdbc.PhoenixHAAdmin.getLocalZkUrl;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_ZK;
+
 /**
- * The command line tool to manage high availability (HA) groups and their 
cluster roles.
+ * Command-line tool to manage HAGroupStoreRecord configurations.
+ * Updates both ZooKeeper and System.HA_GROUP table atomically.

Review Comment:
   We update ZK atomically but not the system table. The description and code 
comments should clarify this. It is also possible that the system table update 
may fail. 



-- 
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