swaroopak commented on a change in pull request #664: PHOENIX-5592 MapReduce 
job to asynchronously delete rows where the VI…
URL: https://github.com/apache/phoenix/pull/664#discussion_r364883984
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/phoenix/mapreduce/ViewTTLDeleteJobMapper.java
 ##########
 @@ -0,0 +1,163 @@
+/*
+ * 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.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.io.NullWritable;
+import org.apache.hadoop.mapreduce.JobStatus;
+import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.phoenix.compile.QueryPlan;
+import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.jdbc.PhoenixResultSet;
+import org.apache.phoenix.jdbc.PhoenixStatement;
+import org.apache.phoenix.mapreduce.util.ConnectionUtil;
+import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil;
+import org.apache.phoenix.mapreduce.util.ViewInfoTracker;
+import org.apache.phoenix.mapreduce.util.MultiViewJobStatusTracker;
+import org.apache.phoenix.mapreduce.util.DefaultMultiViewJobStatusTracker;
+import org.apache.phoenix.mapreduce.util.PhoenixViewTtlUtil;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.SchemaUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.SQLException;
+import java.util.List;
+
+public class ViewTTLDeleteJobMapper extends Mapper<NullWritable, 
ViewInfoTracker, NullWritable, NullWritable> {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ViewTTLDeleteJobMapper.class);
+    private MultiViewJobStatusTracker multiViewJobStatusTracker;
+
+    private void initMultiViewJobStatusTracker(Configuration config) {
+        try {
+            Class<?> defaultViewDeletionTrackerClass = 
DefaultMultiViewJobStatusTracker.class;
+            if 
(config.get(PhoenixConfigurationUtil.MAPREDUCE_VIEW_TTL_MAPPER_TRACKER_CLAZZ) 
!= null) {
+                LOGGER.info("Using customized tracker class : " + 
config.get(PhoenixConfigurationUtil.MAPREDUCE_VIEW_TTL_MAPPER_TRACKER_CLAZZ));
+                defaultViewDeletionTrackerClass = Class.forName(
+                        
config.get(PhoenixConfigurationUtil.MAPREDUCE_VIEW_TTL_MAPPER_TRACKER_CLAZZ));
+            } else {
+                LOGGER.info("Using default tracker class ");
+            }
+            this.multiViewJobStatusTracker = (MultiViewJobStatusTracker) 
defaultViewDeletionTrackerClass.newInstance();
+        } catch (Exception e) {
+            LOGGER.info("exception " + e.getMessage());
+            LOGGER.info("stack trace" + e.getStackTrace().toString());
+        }
+    }
+
+    @Override
+    protected void map(NullWritable key, ViewInfoTracker value,
+                       Context context) {
+        final Configuration config = context.getConfiguration();
+
+        if (this.multiViewJobStatusTracker == null) {
+            initMultiViewJobStatusTracker(config);
+        }
+
+        LOGGER.debug(String.format("Deleting from view %s, TenantID %s, and 
TTL value: %d",
+                value.getViewName(), value.getTenantId(), value.getViewTtl()));
+
+        try (PhoenixConnection connection =(PhoenixConnection) 
ConnectionUtil.getInputConnection(config) ){
+            if (value.getTenantId() != null && 
!value.getTenantId().equals("NULL")) {
+                try (PhoenixConnection tenantConnection = 
(PhoenixConnection)PhoenixViewTtlUtil.
+                        buildTenantConnection(connection.getURL(), 
value.getTenantId())) {
+                    deletingExpiredRows(tenantConnection, value, config);
+                }
+            } else {
+                deletingExpiredRows(connection, value, config);
+            }
+
+        } catch (SQLException e) {
+            LOGGER.error(e.getErrorCode() + e.getSQLState(), 
e.getStackTrace());
 
 Review comment:
   nit: good to put a custom message string so that it can come handy in 
debugging sessions if needed. 
    

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


With regards,
Apache Git Services

Reply via email to