[
https://issues.apache.org/jira/browse/PHOENIX-5592?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17236477#comment-17236477
]
ASF GitHub Bot commented on PHOENIX-5592:
-----------------------------------------
yanxinyi commented on a change in pull request #975:
URL: https://github.com/apache/phoenix/pull/975#discussion_r528000931
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/mapreduce/ViewTTLTool.java
##########
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.mapreduce;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.ParseException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
+import org.apache.hadoop.io.NullWritable;
+import org.apache.hadoop.mapreduce.Job;
+import org.apache.hadoop.mapreduce.JobPriority;
+import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
+import org.apache.phoenix.mapreduce.util.ConnectionUtil;
+import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil;
+import org.apache.phoenix.mapreduce.util.PhoenixMapReduceUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.util.Properties;
+
+public class ViewTTLTool extends Configured implements Tool {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(ViewTTLTool.class);
+
+ public static enum MR_COUNTER_METRICS {
+ FAILED,
+ SUCCEED
+ }
+
+ public static final String ADDING_DELETION_MARKS_FOR_ALL_VIEWS =
"ADDING_DELETION_MARKS_FOR_ALL_VIEWS";
+
+ public static final int DEFAULT_MAPPER_SPLIT_SIZE = 10;
+
+ public static final int DEFAULT_QUERY_BATCH_SIZE = 100;
+
+ private static final Option DELETE_ALL_VIEW_OPTION = new Option("a",
"all", false,
+ "Delete all views from all tables.");
+ private static final Option VIEW_NAME_OPTION = new Option("v", "view",
true,
+ "Delete Phoenix View Name");
+ private static final Option TENANT_ID_OPTION = new Option("i", "id", true,
+ "Delete an view based on the tenant id.");
+ private static final Option JOB_PRIORITY_OPTION = new Option("p",
"job-priority", true,
+ "Define job priority from 0(highest) to 4");
+ private static final Option SPLIT_SIZE_OPTION = new Option("s",
"split-size-per-mapper", true,
+ "Define split size for each mapper.");
+ private static final Option BATCH_SIZE_OPTION = new Option("b",
"batch-size-for-query-more", true,
+ "Define batch size for fetching views metadata from syscat.");
+ private static final Option RUN_FOREGROUND_OPTION = new Option("runfg",
+ "run-foreground", false, "If specified, runs ViewTTLTool " +
+ "in Foreground. Default - Runs the build in background");
+
+ private static final Option HELP_OPTION = new Option("h", "help", false,
"Help");
+
+ Configuration configuration;
+ Connection connection;
+
+ private String viewName;
+ private String tenantId;
+ private String jobName;
+ private boolean isDeletingAllViews;
+ private JobPriority jobPriority;
+ private boolean isForeground;
+ private int splitSize;
+ private int batchSize;
+ private Job job;
+
+ public void parseArgs(String[] args) {
+ CommandLine cmdLine;
+ try {
+ cmdLine = parseOptions(args);
+ } catch (IllegalStateException e) {
+ printHelpAndExit(e.getMessage(), getOptions());
+ throw e;
+ }
+
+ if (getConf() == null) {
+ setConf(HBaseConfiguration.create());
+ }
+
+ if (cmdLine.hasOption(DELETE_ALL_VIEW_OPTION.getOpt())) {
+ this.isDeletingAllViews = true;
+ } else if (cmdLine.hasOption(VIEW_NAME_OPTION.getOpt())) {
+ viewName = cmdLine.getOptionValue(VIEW_NAME_OPTION.getOpt());
+ this.isDeletingAllViews = false;
+ }
+
+ if (cmdLine.hasOption(TENANT_ID_OPTION.getOpt())) {
+ tenantId = cmdLine.getOptionValue((TENANT_ID_OPTION.getOpt()));
+ }
+
+ jobPriority = getJobPriority(cmdLine);
+ if (cmdLine.hasOption(SPLIT_SIZE_OPTION.getOpt())) {
+ splitSize =
Integer.valueOf(cmdLine.getOptionValue(SPLIT_SIZE_OPTION.getOpt()));
+ } else {
+ splitSize = DEFAULT_MAPPER_SPLIT_SIZE;
+ }
+
+ if (cmdLine.hasOption(BATCH_SIZE_OPTION.getOpt())) {
+ batchSize =
Integer.valueOf(cmdLine.getOptionValue(SPLIT_SIZE_OPTION.getOpt()));
+ } else {
+ batchSize = DEFAULT_QUERY_BATCH_SIZE;
+ }
+
+ isForeground = cmdLine.hasOption(RUN_FOREGROUND_OPTION.getOpt());
+ }
+
+ public String getJobPriority() {
+ return this.jobPriority.toString();
+ }
+
+ private JobPriority getJobPriority(CommandLine cmdLine) {
+ String jobPriorityOption =
cmdLine.getOptionValue(JOB_PRIORITY_OPTION.getOpt());
+ if (jobPriorityOption == null) {
+ return JobPriority.NORMAL;
+ }
+
+ switch (jobPriorityOption) {
+ case "0" : return JobPriority.VERY_HIGH;
+ case "1" : return JobPriority.HIGH;
+ case "2" : return JobPriority.NORMAL;
+ case "3" : return JobPriority.LOW;
+ case "4" : return JobPriority.VERY_LOW;
+ default:
+ return JobPriority.NORMAL;
+ }
+ }
+
+ public Job getJob() {
+ return this.job;
+ }
+
+ public boolean isDeletingAllViews() {
+ return this.isDeletingAllViews;
+ }
+
+ public String getTenantId() {
+ return this.tenantId;
+ }
+
+ public String getViewName() {
+ return this.viewName;
+ }
+
+ public int getSplitSize() {
+ return this.splitSize;
+ }
+
+ public int getBatchSize() {
+ return this.batchSize;
+ }
+
+ public CommandLine parseOptions(String[] args) {
+ final Options options = getOptions();
+ CommandLineParser parser = new PosixParser();
+ CommandLine cmdLine = null;
+ try {
+ cmdLine = parser.parse(options, args);
+ } catch (ParseException e) {
+ printHelpAndExit("Error parsing command line options: " +
e.getMessage(), options);
+ }
+
+ if (!cmdLine.hasOption(DELETE_ALL_VIEW_OPTION.getOpt()) &&
+ !cmdLine.hasOption(VIEW_NAME_OPTION.getOpt()) &&
+ !cmdLine.hasOption(TENANT_ID_OPTION.getOpt())) {
+ throw new IllegalStateException("No deletion job is specified, " +
+ "please indicate deletion job for ALL/TABLE/VIEW/TENANT
level");
+ }
+
+ if (cmdLine.hasOption(HELP_OPTION.getOpt())) {
+ printHelpAndExit(options, 0);
+ }
+
+ this.jobPriority = getJobPriority(cmdLine);
+
+ return cmdLine;
+ }
+
+ private Options getOptions() {
+ final Options options = new Options();
+ options.addOption(DELETE_ALL_VIEW_OPTION);
+ options.addOption(VIEW_NAME_OPTION);
+ options.addOption(TENANT_ID_OPTION);
+ options.addOption(HELP_OPTION);
+ options.addOption(JOB_PRIORITY_OPTION);
+ options.addOption(RUN_FOREGROUND_OPTION);
+ options.addOption(SPLIT_SIZE_OPTION);
+ options.addOption(BATCH_SIZE_OPTION);
+
+ return options;
+ }
+
+ private void printHelpAndExit(String errorMessage, Options options) {
+ System.err.println(errorMessage);
Review comment:
added
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
> MapReduce job to asynchronously delete rows where the VIEW_TTL has expired.
> ---------------------------------------------------------------------------
>
> Key: PHOENIX-5592
> URL: https://issues.apache.org/jira/browse/PHOENIX-5592
> Project: Phoenix
> Issue Type: Sub-task
> Reporter: Xinyi Yan
> Assignee: Xinyi Yan
> Priority: Major
> Fix For: 4.16.0
>
> Time Spent: 7h
> Remaining Estimate: 0h
>
> Find the entities from the system catalog which views have TTLs defined on
> them. Spawn an MR job, whose splitter will create a map task. The mapper
> issues “select count(1) from the entity and Inject TTL attributes and Delete
> Hint during Map task. Since the current Phoniex MR framework doesn't support
> this feature, PhoenixMultiViewReader, PhoenixMultiViewInputSplit,
> PhoenixMultiViewInputFormat, and a few MR related util classes need to
> implement.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)