jerrypeng commented on code in PR #38517:
URL: https://github.com/apache/spark/pull/38517#discussion_r1048920790


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/AsyncCommitLog.scala:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.spark.sql.execution.streaming
+
+import java.io.OutputStream
+import java.util.concurrent.{CompletableFuture, ConcurrentLinkedDeque, 
ThreadPoolExecutor}
+
+import scala.collection.JavaConverters._
+
+import org.apache.spark.sql.SparkSession
+
+/**
+ * Implementation of CommitLog to perform asynchronous writes to storage
+ */
+class AsyncCommitLog(sparkSession: SparkSession, path: String, 
executorService: ThreadPoolExecutor)
+    extends CommitLog(sparkSession, path) {
+
+  // A queue of batches written to storage.  Used to keep track when to purge 
old batches
+  val writtenToDurableStorage =
+    new ConcurrentLinkedDeque[Long](listBatchesOnDisk.toList.asJavaCollection)
+
+  /**
+   * Writes a new batch to the commit log asynchronously
+   * @param batchId id of batch to write
+   * @param metadata metadata of batch to write
+   * @return a CompeletableFuture that contains the batch id.  The future is 
completed when
+   *         the async write of the batch is completed.  Future may also be 
completed exceptionally
+   *         to indicate some write error.
+   */
+  def addAsync(batchId: Long, metadata: CommitMetadata): 
CompletableFuture[Long] = {
+    require(metadata != null, "'null' metadata cannot be written to a metadata 
log")
+    val future: CompletableFuture[Long] = addNewBatchByStreamAsync(batchId) { 
output =>
+      serialize(metadata, output)
+    }.thenApply((ret: Boolean) => {
+      if (ret) {
+        batchId
+      } else {
+        throw new IllegalStateException(
+          s"Concurrent update to the log. Multiple streaming jobs detected for 
$batchId"

Review Comment:
   This is the message in existing implementation.  We don't really 
differentiate which log.  However, you should know which log it is based on the 
stack trace.



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