lcspinter commented on a change in pull request #2827:
URL: https://github.com/apache/hive/pull/2827#discussion_r761742553



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CycleUpdaterThread.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.txn.compactor;
+
+import org.apache.hadoop.hive.metastore.metrics.Metrics;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This thread simply updates a gauge metric by the given interval with the 
time elapsed since start
+ */
+class CycleUpdaterThread extends Thread {
+
+  private static final String CLASS_NAME = CycleUpdaterThread.class.getName();
+  private static final Logger LOG = LoggerFactory.getLogger(CLASS_NAME);
+
+  private final String gaugeName;
+  private final long startTime;
+  private final long updateInterval;
+
+  /**
+   * Constructor
+   * @param gaugeName name of the gauge which obtained from {@link 
org.apache.hadoop.hive.metastore.metrics.Metrics}
+   * @param startTime the start of the measurement
+   * @param updateInterval the update interval
+   */
+  CycleUpdaterThread(String gaugeName, long startTime, long updateInterval) {
+    this.gaugeName = gaugeName;
+    this.startTime = startTime;
+    this.updateInterval = updateInterval;
+  }
+
+  @Override
+  public void run() {
+    while (!isInterrupted()) {
+      updateMetric();
+
+      try {
+        Thread.sleep(updateInterval);
+      } catch (InterruptedException e) {
+        LOG.debug("Thread has been interrupted - this is normal");
+      }
+    }
+  }
+
+  @Override
+  public void interrupt() {
+    LOG.debug("Interrupting for {}", gaugeName);
+    super.interrupt();
+    updateMetric();
+  }
+
+  private void updateMetric() {
+    updateMetric((int)(System.currentTimeMillis() - startTime));
+  }
+
+  private void updateMetric(int elapsed) {

Review comment:
       Could you please combine the two updateMetric() functions?

##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CycleUpdaterThread.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.txn.compactor;
+
+import org.apache.hadoop.hive.metastore.metrics.Metrics;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This thread simply updates a gauge metric by the given interval with the 
time elapsed since start
+ */
+class CycleUpdaterThread extends Thread {

Review comment:
       Although I like that thread and the threadfactory is separated into 
different classes, usually, I use the built-in java utilities for thread 
management. You might have a look at the `Executors` API. Also there is a 
`ThreadFactoryBuilder` which might substitute your `CycleUpdaterThreadFactory`. 
   A good example can be found in `CompactorUtil`.

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/Initiator.java
##########
@@ -558,4 +563,11 @@ private String getInitiatorId(long threadId) {
     name.append(threadId);
     return name.toString();
   }
+
+  private void stopCycleUpdaterThread() {

Review comment:
       ExecutorService.shutdown()

##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnStore.java
##########
@@ -25,7 +25,6 @@
 import org.apache.hadoop.hive.common.ValidTxnList;
 import org.apache.hadoop.hive.common.classification.RetrySemantics;
 import org.apache.hadoop.hive.metastore.api.*;

Review comment:
       I know it's not part of this change, but could you please replace this 
wildcard import? 

##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CycleUpdaterThreadFactory.java
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.txn.compactor;
+
+/**
+ * Factory for the {@link CycleUpdaterThread} class
+ */
+final class CycleUpdaterThreadFactory {
+
+  private static final long DEFAULT_UPDATE_INTERVAL_IN_MILLISECONDS = 1_000L;

Review comment:
       Do we want to make this config costumisable? 




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to