You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/08/27 12:05:43 UTC

[GitHub] [spark] Ngone51 commented on a change in pull request #25577: [WIP][CORE][SPARK-28867] InMemoryStore checkpoint to speed up replay log file in HistoryServer

Ngone51 commented on a change in pull request #25577: [WIP][CORE][SPARK-28867] InMemoryStore checkpoint to speed up replay log file in HistoryServer
URL: https://github.com/apache/spark/pull/25577#discussion_r318042018
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/status/InMemoryStoreCheckpoint.scala
 ##########
 @@ -0,0 +1,136 @@
+/*
+ * 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.status
+
+import java.io.BufferedOutputStream
+import java.util.concurrent.{CountDownLatch, TimeUnit}
+
+import org.apache.hadoop.fs.{FileUtil, Path}
+
+import org.apache.spark.SparkConf
+import org.apache.spark.deploy.SparkHadoopUtil
+import org.apache.spark.internal.Logging
+import org.apache.spark.internal.config._
+import org.apache.spark.internal.config.Status._
+import org.apache.spark.scheduler.EventLoggingListener
+import org.apache.spark.serializer.JavaSerializer
+import org.apache.spark.status.api.v1
+import org.apache.spark.util.{ThreadUtils, Utils}
+import org.apache.spark.util.kvstore.InMemoryStore
+
+case class InMemoryStoreSnapshot(
+    store: InMemoryStore,
+    eventsNum: Int,
+    finished: Boolean) extends Serializable
+
+
+private[spark] class InMemoryStoreCheckpoint(
+    store: InMemoryStore,
+    conf: SparkConf,
+    listener: AppStatusListener) extends Logging {
+  var lastRecordEventsNum: Int = 0
+  var finished: Boolean = false
+
+  // used to count the number of processed events in a live AppStatusListener
+  private var processedEventsNum = 0
+  private val batchSize = conf.get(IMS_CHECKPOINT_BATCH_SIZE)
+  private val bufferSize = conf.get(IMS_CHECKPOINT_BUFFER_SIZE).toInt
+  private var latch = new CountDownLatch(0)
+  @volatile var isDone = true
+  // a JavaSerializer used to serialize InMemoryStoreSnapshot
+  private val serializer = new JavaSerializer(conf).newInstance()
+  private val logBaseDir = Utils.resolveURI(conf.get(EVENT_LOG_DIR).stripSuffix("/"))
+  private lazy val ckpPath = getCheckpointPath
+  private val hadoopConf = SparkHadoopUtil.get.newConfiguration(conf)
+  private val fileSystem = Utils.getHadoopFileSystem(logBaseDir, hadoopConf)
+  private val executor = ThreadUtils.newDaemonSingleThreadExecutor(
+    "inmemorystore-checkpoint-thread")
+  // should be inited before the first time checkpoint
+  var appInfo: v1.ApplicationInfo = _
+
+  private val checkpointTask = new Runnable {
+    override def run(): Unit = Utils.tryLogNonFatalError(doCheckpoint())
+  }
+
+  private def getCheckpointPath: String = {
+    val appId = appInfo.id
+    val appAttemptId = appInfo.attempts.head.attemptId
+    EventLoggingListener.getLogPath(logBaseDir, appId, appAttemptId, None)
+  }
+
+  def await(): Unit = latch.await()
+
+  def eventInc(finish: Boolean = false): Unit = {
+    processedEventsNum += 1
+    val shouldCheckpoint = !finished && (processedEventsNum - lastRecordEventsNum >=
+      batchSize || finish)
+    if (shouldCheckpoint) {
+      // flush to make sure that all processed events' related data have write into InMemoryStore
+      listener.flush(listener.update(_, System.nanoTime()))
+      latch = new CountDownLatch(1)
 
 Review comment:
   Since all events are processed in the single dispatchThread, so we'll only have that one thread to create new `CountDownLatch`. But I just realize that variable `latch` maybe override if the number of backlog events exceeds checkpoint batch size while last checkpoint is still in progress. So, I update the `shouldCheckpoint` condition to `isDone && (finish || processedEventsNum - lastRecordEventsNum >= batchSize)` to cover that corner case.

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org