veghlaci05 commented on code in PR #3803:
URL: https://github.com/apache/hive/pull/3803#discussion_r1031290340
##########
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/MetaStoreCompactorThread.java:
##########
@@ -133,4 +134,28 @@ protected static long updateCycleDurationMetric(String
metric, long startedAt) {
}
return 0;
}
+
+ // This method was created to reduce duplication between
+ // Compactor classes Cleaner and Initiator
+ protected long getThreadSleepTime(long elapsedTime, AtomicBoolean stop,
CompactorUtil.CompactorThreadType type) {
+ long checkInterval;
+ switch (type) {
+ case INITIATOR:
+ checkInterval =
conf.getTimeVar(HiveConf.ConfVars.HIVE_COMPACTOR_CHECK_INTERVAL,
TimeUnit.MILLISECONDS);
+ break;
+ case CLEANER:
+ checkInterval = conf.getTimeVar(
+ HiveConf.ConfVars.HIVE_COMPACTOR_CLEANER_RUN_INTERVAL,
TimeUnit.MILLISECONDS);
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown type: " + type);
+ }
+
+ if (elapsedTime < checkInterval && !stop.get()) {
+ return checkInterval - elapsedTime;
+ } else {
+ //In case where Thread.sleep is not required
+ return -1;
+ }
+ }
Review Comment:
1. Move this method to `CompactorThread`
2. Field `stop` is acccessible in `CompactorThread`, so you don't need to
pass it.
3. Restore `checkinterval set in `init()` methods, so no need to set it here
again in every iteration
4. Move `checkinterval` to `CompactorThread` and for `Worker` set it to 0 in
`Worker.init()`
5. `Thread.sleep()` should happen here
6. Logging should happen here like `LOG.debug(type + " loop took "...)`
7. The method name should be sth like `doPostLoopActions`and it should be
void
8. Worker should call this method as well
--
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]