vinothchandar commented on a change in pull request #1752:
URL: https://github.com/apache/hudi/pull/1752#discussion_r446615608



##########
File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
##########
@@ -48,7 +49,12 @@ private[hudi] object HoodieSparkSqlWriter {
   def write(sqlContext: SQLContext,
             mode: SaveMode,
             parameters: Map[String, String],
-            df: DataFrame): (Boolean, common.util.Option[String]) = {
+            df: DataFrame,
+            hoodieWriteClient: 
Option[HoodieWriteClient[HoodieRecordPayload[Nothing]]],

Review comment:
       scala has default values/optional parameters.. so instead of changing 
signature to pass empty everywhere.. we can just specify defaults here,

##########
File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
##########
@@ -303,6 +334,18 @@ private[hudi] object HoodieSparkSqlWriter {
             }
           })
       }
+      (false, common.util.Option.empty())
+    }
+  }
+
+  private def isAsyncCompactionEnabled(client: 
HoodieWriteClient[HoodieRecordPayload[Nothing]],
+                                       parameters: Map[String, String], 
configuration: Configuration) : Boolean = {
+    log.info(s"Config.isInlineCompaction ? 
${client.getConfig.isInlineCompaction}")
+    if (!client.getConfig.isInlineCompaction

Review comment:
       what if the user sets the writeClient config for `inline` = false and 
does not set async compaction datasource option? should we control at a single 
level.. 

##########
File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
##########
@@ -279,6 +297,15 @@ private[hudi] object HoodieSparkSqlWriter {
         log.info("Commit " + instantTime + " failed!")
       }
 
+      val asyncCompactionEnabled = isAsyncCompactionEnabled(client, 
parameters, jsc.hadoopConfiguration())
+      val compactionInstant : common.util.Option[java.lang.String] =
+      if (asyncCompactionEnabled) {
+        client.scheduleCompaction(common.util.Option.of(new 
util.HashMap[String, String](mapAsJavaMap(metaMap))))

Review comment:
       is it possible that nothing is actually scheduled here, since there is 
nothiing to compact?

##########
File path: 
hudi-spark/src/main/java/org/apache/hudi/async/SparkStreamingWriterActivityDetector.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.hudi.async;
+
+import java.util.function.Supplier;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+/**
+ * This class is used to detect activity of spark streaming writer. THis is 
used to decide if HoodieWriteClient
+ * and async compactor needs to be closed. Spark Structured Streaming do not 
have explicit API on the Sink side to
+ * determine if the stream is done. In this absence, async compactor 
proactively checks with the sink if it is
+ * active. If there is no activity for sufficient period, async compactor 
shuts down. If the sink was indeed active,
+ * a subsequent batch will re-trigger async compaction.
+ */
+public class SparkStreamingWriterActivityDetector {

Review comment:
       basic question..  if there are no writes , no compaction gets scheduled 
right? so async compaction is a no-op i.e it will check if there is some work 
to do, if not won't trigger anything?




----------------------------------------------------------------
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:
[email protected]


Reply via email to