From issues-return-4228-archive-asf-public=cust-asf.ponee.io@phoenix.apache.org Sat Jan 26 00:47:58 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id A5454180771 for ; Sat, 26 Jan 2019 00:47:57 +0100 (CET) Received: (qmail 12851 invoked by uid 500); 25 Jan 2019 23:47:56 -0000 Mailing-List: contact issues-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list issues@phoenix.apache.org Received: (qmail 12842 invoked by uid 99); 25 Jan 2019 23:47:56 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Jan 2019 23:47:56 +0000 From: GitBox To: issues@phoenix.apache.org Subject: [GitHub] karanmehta93 commented on a change in pull request #430: PHOENIX-5091 Add new features to UpdateStatisticsTool Message-ID: <154846007625.7209.4424886991551603924.gitbox@gitbox.apache.org> Date: Fri, 25 Jan 2019 23:47:56 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit karanmehta93 commented on a change in pull request #430: PHOENIX-5091 Add new features to UpdateStatisticsTool URL: https://github.com/apache/phoenix/pull/430#discussion_r251170880 ########## File path: phoenix-core/src/main/java/org/apache/phoenix/schema/stats/UpdateStatisticsTool.java ########## @@ -77,49 +82,103 @@ "Restore Directory for HBase snapshot"); private static final Option RUN_FOREGROUND_OPTION = new Option("runfg", "run-foreground", false, - "If specified, runs UpdateStatisticsTool in Foreground. Default - Runs the build in background."); + "If specified, runs UpdateStatisticsTool in Foreground. Default - Runs the build in background"); + private static final Option MANAGE_SNAPSHOT_OPTION = + new Option("ms", "manage-snapshot", false, + "Creates a new snapshot, runs the tool and deletes it"); + private static final Option HELP_OPTION = new Option("h", "help", false, "Help"); - private Configuration conf; private String tableName; private String snapshotName; private Path restoreDir; + private boolean manageSnapshot; private boolean isForeground; + private Job job; + @Override public int run(String[] args) throws Exception { parseArgs(args); - Job job = configureJob(conf, tableName, snapshotName, restoreDir); + preJobTask(); + configureJob(); TableMapReduceUtil.initCredentials(job); - return runJob(job, isForeground); + int ret = runJob(); + postJobTask(); + return ret; + } + + /** + * Run any tasks before the MR job is launched + * Currently being used for snapshot creation + */ + private void preJobTask() throws Exception { + if (!manageSnapshot) { + return; + } + + try (final Connection conn = ConnectionUtil.getInputConnection(getConf())) { + HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin(); + boolean namespaceMapping = getConf().getBoolean(IS_NAMESPACE_MAPPING_ENABLED, + DEFAULT_IS_NAMESPACE_MAPPING_ENABLED); + String physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), + namespaceMapping).getNameAsString(); + admin.snapshot(snapshotName, physicalTableName); + LOG.info("Successfully created snapshot " + snapshotName + " for " + physicalTableName); + } + } + + /** + * Run any tasks before the MR job is completed successfully + * Currently being used for snapshot deletion + */ + private void postJobTask() throws Exception { + if (!manageSnapshot) { + return; + } + + try (final Connection conn = ConnectionUtil.getInputConnection(getConf())) { + HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin(); + admin.deleteSnapshot(snapshotName); + LOG.info("Successfully deleted snapshot " + snapshotName); + } } - private void parseArgs(String[] args) { + void parseArgs(String[] args) { CommandLine cmdLine = null; try { cmdLine = parseOptions(args); } catch (IllegalStateException e) { printHelpAndExit(e.getMessage(), getOptions()); } - conf = HBaseConfiguration.create(); + if (getConf() == null) { + setConf(HBaseConfiguration.create()); + } + tableName = cmdLine.getOptionValue(TABLE_NAME_OPTION.getOpt()); snapshotName = cmdLine.getOptionValue(SNAPSHOT_NAME_OPTION.getOpt()); + if (snapshotName == null) { + snapshotName = "UpdateStatisticsTool_" + tableName + "_" + System.currentTimeMillis(); + } + String restoreDirOptionValue = cmdLine.getOptionValue(RESTORE_DIR_OPTION.getOpt()); if (restoreDirOptionValue == null) { - restoreDirOptionValue = conf.get(FS_DEFAULT_NAME_KEY) + "/tmp"; + restoreDirOptionValue = getConf().get(FS_DEFAULT_NAME_KEY) + "/tmp"; } + restoreDir = new Path(restoreDirOptionValue); + manageSnapshot = cmdLine.hasOption(MANAGE_SNAPSHOT_OPTION.getOpt()); isForeground = cmdLine.hasOption(RUN_FOREGROUND_OPTION.getOpt()); } - Job configureJob(Configuration conf, String tableName, - String snapshotName, Path restoreDir) throws Exception { - Job job = Job.getInstance(conf, "Update statistics for " + tableName); + private void configureJob() throws Exception { + job = Job.getInstance(getConf(), "Update statistics for " + tableName); Review comment: Let me add snapshot name here. Other info should be read from the logs and configuration. Wdyt? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services