stream2000 commented on code in PR #9160:
URL: https://github.com/apache/hudi/pull/9160#discussion_r1258215273
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HoodieHeartbeatClient.java:
##########
@@ -186,35 +180,54 @@ public void start(String instantTime) {
/**
* Stops the heartbeat for the specified instant.
- * @param instantTime
+ *
+ * @param instantTime The instant time for the heartbeat.
* @throws HoodieException
*/
public void stop(String instantTime) throws HoodieException {
Heartbeat heartbeat = instantToHeartbeatMap.get(instantTime);
- if (heartbeat != null && heartbeat.isHeartbeatStarted() &&
!heartbeat.isHeartbeatStopped()) {
- LOG.info("Stopping heartbeat for instant " + instantTime);
- heartbeat.getTimer().cancel();
- heartbeat.setHeartbeatStopped(true);
- LOG.info("Stopped heartbeat for instant " + instantTime);
+ if (isHeartbeatStarted(heartbeat)) {
+ stopHeartbeat(heartbeat);
HeartbeatUtils.deleteHeartbeatFile(fs, basePath, instantTime);
LOG.info("Deleted heartbeat file for instant " + instantTime);
}
}
/**
* Stops all heartbeats started via this instance of the client.
+ *
* @throws HoodieException
*/
public void stop() throws HoodieException {
- instantToHeartbeatMap.values().forEach(heartbeat ->
stop(heartbeat.getInstantTime()));
+
instantToHeartbeatMap.values().stream().filter(this::isHeartbeatStarted).forEach(this::stopHeartbeat);
+ }
+
+ /**
+ * Whether the given heartbeat is started.
+ *
+ * @param heartbeat The heartbeat to check whether is started.
+ * @return Whether the heartbeat is started.
+ * @throws IOException
+ */
+ public boolean isHeartbeatStarted(Heartbeat heartbeat) {
+ return heartbeat != null && heartbeat.isHeartbeatStarted() &&
!heartbeat.isHeartbeatStopped();
+ }
+
+ /**
+ * Stops the given heartbeat.
+ *
+ * @param heartbeat The heartbeat to stop.
+ */
+ public void stopHeartbeat(Heartbeat heartbeat) {
Review Comment:
We don't need to make it public right?
--
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]