[ 
https://issues.apache.org/jira/browse/HIVE-23516?focusedWorklogId=442293&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-442293
 ]

ASF GitHub Bot logged work on HIVE-23516:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Jun/20 17:06
            Start Date: 06/Jun/20 17:06
    Worklog Time Spent: 10m 
      Work Description: aasha commented on a change in pull request #1044:
URL: https://github.com/apache/hive/pull/1044#discussion_r436284316



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/parse/repl/metric/MetricSink.java
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.hadoop.hive.ql.parse.repl.metric;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.api.ReplicationMetricList;
+import org.apache.hadoop.hive.metastore.api.ReplicationMetrics;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.utils.Retry;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.parse.repl.metric.event.ReplicationMetric;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * MetricSink.
+ * Scheduled thread to poll from Metric Collector and persists to DB
+ */
+public final class MetricSink {
+  private static final Logger LOG = LoggerFactory.getLogger(MetricSink.class);
+  private ScheduledExecutorService executorService;
+  private static volatile MetricSink instance;
+  private boolean isInitialised = false;
+  private HiveConf conf;
+
+  private MetricSink() {
+    this.executorService = Executors.newSingleThreadScheduledExecutor();
+  }
+
+  public static MetricSink getInstance() {
+    if (instance == null) {
+      synchronized (MetricSink.class) {
+        if (instance == null) {
+          instance = new MetricSink();
+        }
+      }
+    }
+    return instance;
+  }
+
+  public synchronized void init(HiveConf conf) {
+    if (!isInitialised) {
+      this.conf = conf;
+      long frequencyInMins = MetastoreConf.getLongVar(conf, 
MetastoreConf.ConfVars.REPL_METRICS_UPDATE_FREQUENCY);
+      this.executorService.schedule(new MetricSinkWriter(conf), 
frequencyInMins, TimeUnit.MINUTES);
+      isInitialised = true;
+    }
+  }
+
+  static class MetricSinkWriter implements Runnable {
+    private MetricCollector collector;
+    private HiveConf conf;
+
+    // writer instance
+
+    MetricSinkWriter(HiveConf conf) {
+      this.collector = MetricCollector.getInstance();
+      this.conf = conf;
+    }
+
+    @Override
+    public void run() {
+      // get metrics
+      List<ReplicationMetric> metrics = collector.getMetrics();
+      // write metrics and retry if fails
+      Retry<Void> retriable = new Retry<Void>(Exception.class) {
+        @Override
+        public Void execute() throws Exception {
+          ReplicationMetricList metricList = new ReplicationMetricList();
+          List<ReplicationMetrics> replicationMetricsList = new ArrayList<>();
+          for (ReplicationMetric metric : metrics) {
+            ReplicationMetrics persistentMetric = new ReplicationMetrics();
+            persistentMetric.setDumpExecutionId(metric.getDumpExecutionId());
+            
persistentMetric.setScheduledExecutionId(metric.getScheduledExecutionId());
+            persistentMetric.setPolicy(metric.getPolicy());
+            ObjectMapper mapper = new ObjectMapper();
+            
persistentMetric.setProgress(mapper.writeValueAsString(metric.getProgress()));
+            
persistentMetric.setMetadata(mapper.writeValueAsString(metric.getMetadata()));
+            replicationMetricsList.add(persistentMetric);
+          }
+          metricList.setReplicationMetricList(replicationMetricsList);

Review comment:
       This is just an assignment. Where is the 2X memory coming from? The list 
in metricList is not allocated any extra memory apart from the list size. 




----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 442293)
    Time Spent: 5h 50m  (was: 5h 40m)

> Store hive replication policy execution metrics in the relational DB
> --------------------------------------------------------------------
>
>                 Key: HIVE-23516
>                 URL: https://issues.apache.org/jira/browse/HIVE-23516
>             Project: Hive
>          Issue Type: Task
>            Reporter: Aasha Medhi
>            Assignee: Aasha Medhi
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-23516.01.patch, HIVE-23516.02.patch, 
> HIVE-23516.03.patch, HIVE-23516.04.patch, HIVE-23516.05.patch, 
> HIVE-23516.06.patch, HIVE-23516.07.patch, HIVE-23516.08.patch, 
> HIVE-23516.09.patch, HIVE-23516.10.patch, HIVE-23516.11.patch, 
> HIVE-23516.12.patch, HIVE-23516.13.patch, HIVE-23516.14.patch, 
> HIVE-23516.15.patch, Replication Metrics.pdf
>
>          Time Spent: 5h 50m
>  Remaining Estimate: 0h
>
> Details documented in the attached doc



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to