You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/01/02 06:48:55 UTC

[GitHub] [hudi] n3nash commented on a change in pull request #2359: [HUDI-1486] Remove inflight rollback in hoodie writer

n3nash commented on a change in pull request #2359:
URL: https://github.com/apache/hudi/pull/2359#discussion_r550360249



##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/heartbeat/HoodieHeartbeatClient.java
##########
@@ -0,0 +1,196 @@
+/*
+ * 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.hudi.client.heartbeat;
+
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import javax.annotation.concurrent.NotThreadSafe;
+import java.io.File;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+/**
+ * This class creates heartbeat for hudi client. This heartbeat is used to ascertain whether the running job is or not.
+ * NOTE: Due to CPU contention on the driver/client node, the heartbeats could be delayed, hence it's important to set
+ *       the value high enough to avoid that possibility.
+ */
+@NotThreadSafe
+public class HoodieHeartbeatClient implements AutoCloseable, Serializable {
+
+  // TODO : Throw new exception from thread
+  private static final Logger LOG = LogManager.getLogger(HoodieHeartbeatClient.class);
+
+  // path to the hearbeat folder where all writers are updating their heartbeats
+  private final transient FileSystem fs;
+  private final String basePath;
+  private String heartBeatFolderPath;
+  private String currentInstantTime;
+  private int numHeartBeatsForCurrentInstantTime;
+  // heartbeat interval in millis
+  private final long heartbeatIntervalInMillis;
+  private final transient ExecutorService executorService = Executors.newSingleThreadExecutor();
+  private volatile boolean shutdownRequested;
+  private boolean isHearbeatStarted = false;
+  private boolean isHeatBeatStopped = false;
+  private transient Future<?> heartBeatFuture;
+  private Long lastHeartBeatTime;
+  // This is required for testing. Problem : if we set heartbeatIntervalInSeconds really large, test takes longer, if
+  // we set it small and you are debugging with breakpoint, causes issues. Need to implement a Mock in tests
+  private final Boolean skipHeartBeatCheck;
+
+  public HoodieHeartbeatClient(FileSystem fs, String basePath, long heartbeatIntervalInSeconds) {
+    ValidationUtils.checkArgument(heartbeatIntervalInSeconds >= 1, "Cannot set heartbeat lower than 1 second");
+    this.fs = fs;
+    this.basePath = basePath;
+    this.heartBeatFolderPath = HoodieTableMetaClient.getHeartbeatFolderPath(basePath);
+    this.heartbeatIntervalInMillis = heartbeatIntervalInSeconds * 1000L;

Review comment:
       I think it's easier for people to reason with seconds and not set too low a value like 1000ms etc which can overwhelm RPC's




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