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 2022/12/22 22:37:17 UTC

[GitHub] [spark] gengliangwang commented on a diff in pull request #39141: [SPARK-41422][UI] Protobuf serializer for ExecutorSummaryWrapper

gengliangwang commented on code in PR #39141:
URL: https://github.com/apache/spark/pull/39141#discussion_r1055907620


##########
core/src/main/scala/org/apache/spark/status/protobuf/ExecutorSummaryWrapperSerializer.scala:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.protobuf
+
+import java.util.Date
+
+import collection.JavaConverters._
+
+import org.apache.spark.resource.ResourceInformation
+import org.apache.spark.status.ExecutorSummaryWrapper
+import org.apache.spark.status.api.v1.{ExecutorSummary, MemoryMetrics}
+import org.apache.spark.status.protobuf.Utils.getOptional
+
+class ExecutorSummaryWrapperSerializer extends ProtobufSerDe {
+
+  override val supportClass: Class[_] = classOf[ExecutorSummaryWrapper]
+
+  override def serialize(input: Any): Array[Byte] = {
+    serialize(input.asInstanceOf[ExecutorSummaryWrapper])
+  }
+
+  def serialize(input: ExecutorSummaryWrapper): Array[Byte] = {
+    val info = serializeExecutorSummary(input.info)
+    val builder = StoreTypes.ExecutorSummaryWrapper.newBuilder()
+      .setInfo(info)
+    builder.build().toByteArray
+  }
+
+  def deserialize(bytes: Array[Byte]): ExecutorSummaryWrapper = {
+    val binary = StoreTypes.ExecutorSummaryWrapper.parseFrom(bytes)
+    val info = deserializeExecutorSummary(binary.getInfo)
+    new ExecutorSummaryWrapper(info = info)
+  }
+
+  private def serializeExecutorSummary(
+      input: ExecutorSummary): StoreTypes.ExecutorSummary = {
+    val builder = StoreTypes.ExecutorSummary.newBuilder()
+      .setId(input.id)
+      .setHostPort(input.hostPort)
+      .setIsActive(input.isActive)
+      .setRddBlocks(input.rddBlocks)
+      .setMemoryUsed(input.memoryUsed)
+      .setDiskUsed(input.diskUsed)
+      .setTotalCores(input.totalCores)
+      .setMaxTasks(input.maxTasks)
+      .setActiveTasks(input.activeTasks)
+      .setFailedTasks(input.failedTasks)
+      .setCompletedTasks(input.completedTasks)
+      .setTotalTasks(input.totalTasks)
+      .setTotalDuration(input.totalDuration)
+      .setTotalGcTime(input.totalGCTime)
+      .setTotalInputBytes(input.totalInputBytes)
+      .setTotalShuffleRead(input.totalShuffleRead)
+      .setTotalShuffleWrite(input.totalShuffleWrite)
+      .setIsBlacklisted(input.isBlacklisted)
+      .setMaxMemory(input.maxMemory)
+      .setAddTime(input.addTime.getTime)
+
+    input.removeTime.foreach {
+      date => builder.setRemoveTime(date.getTime)
+    }
+    input.removeReason.foreach(builder.setRemoveReason)
+    input.executorLogs.foreach { case (k, v) =>
+      builder.putExecutorLogs(k, v)
+    }
+    input.memoryMetrics.foreach { metrics =>
+      builder.setMemoryMetrics(serializeMemoryMetrics(metrics))
+    }
+    input.blacklistedInStages.foreach(builder.addBlacklistedInStages)
+    input.peakMemoryMetrics.foreach { metrics =>
+      builder.setPeakMemoryMetrics(ExecutorMetricsSerializer.serialize(metrics))
+    }
+    input.attributes.foreach { case (k, v) =>
+      builder.putAttributes(k, v)
+    }
+    input.resources.foreach { case (k, v) =>
+      builder.putResources(k, serializeResourceInformation(v))
+    }
+
+    builder.setResourceProfileId(input.resourceProfileId)
+    builder.setIsExcluded(input.isExcluded)
+
+    input.excludedInStages.foreach(builder.addExcludedInStages)
+
+    builder.build()
+  }
+
+  private def deserializeExecutorSummary(
+      binary: StoreTypes.ExecutorSummary): ExecutorSummary = {
+    val peakMemoryMetrics =
+      getOptional(binary.hasPeakMemoryMetrics,
+        () => ExecutorMetricsSerializer.deserialize(binary.getPeakMemoryMetrics))
+    val removeTime = getOptional(binary.hasRemoveTime, () => new Date(binary.getRemoveTime))
+    val removeReason = getOptional(binary.hasRemoveReason, () => binary.getRemoveReason)
+    val memoryMetrics =
+      getOptional(binary.hasMemoryMetrics,
+        () => deserializeMemoryMetrics(binary.getMemoryMetrics))
+    new ExecutorSummary(
+      id = binary.getId,
+      hostPort = binary.getHostPort,
+      isActive = binary.getIsActive,
+      rddBlocks = binary.getRddBlocks,
+      memoryUsed = binary.getMemoryUsed,
+      diskUsed = binary.getDiskUsed,
+      totalCores = binary.getTotalCores,
+      maxTasks = binary.getMaxTasks,
+      activeTasks = binary.getActiveTasks,
+      failedTasks = binary.getFailedTasks,
+      completedTasks = binary.getCompletedTasks,
+      totalTasks = binary.getTotalTasks,
+      totalDuration = binary.getTotalDuration,
+      totalGCTime = binary.getTotalGcTime,
+      totalInputBytes = binary.getTotalInputBytes,
+      totalShuffleRead = binary.getTotalShuffleRead,
+      totalShuffleWrite = binary.getTotalShuffleWrite,
+      isBlacklisted = binary.getIsBlacklisted,
+      maxMemory = binary.getMaxMemory,
+      addTime = new Date(binary.getAddTime),
+      removeTime = removeTime,
+      removeReason = removeReason,
+      executorLogs = binary.getExecutorLogsMap.asScala.toMap,
+      memoryMetrics = memoryMetrics,
+      // TODO: fix toInt

Review Comment:
   @techaddict There are some todos here. Will you fix them?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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