FMX commented on code in PR #2456:
URL: https://github.com/apache/celeborn/pull/2456#discussion_r1593651943


##########
common/src/main/scala/org/apache/celeborn/common/util/PbSerDeUtils.scala:
##########
@@ -490,4 +490,170 @@ object PbSerDeUtils {
       pbWorkerEventInfo.getWorkerEventType.getNumber,
       pbWorkerEventInfo.getEventStartTime())
   }
+
+  private def toPackedPartitionLocation(
+      pbPackedLocationsBuilder: PbPackedPartitionLocations.Builder,
+      workerIdIndex: Map[String, Int],
+      mountPointsIndex: Map[String, Int],
+      location: PartitionLocation): PbPackedPartitionLocations.Builder = {
+    pbPackedLocationsBuilder.addIds(location.getId)
+    pbPackedLocationsBuilder.addEpoches(location.getEpoch)
+    
pbPackedLocationsBuilder.addWorkerIds(workerIdIndex(location.getWorker.toUniqueId()))
+    pbPackedLocationsBuilder.addMapIdBitMap(
+      Utils.roaringBitmapToByteString(location.getMapIdBitMap))
+    pbPackedLocationsBuilder.addTypes(location.getStorageInfo.getType.getValue)
+    pbPackedLocationsBuilder.addMountPoints(
+      mountPointsIndex(location.getStorageInfo.getMountPoint))
+    
pbPackedLocationsBuilder.addFinalResult(location.getStorageInfo.isFinalResult)
+    if (location.getStorageInfo.getFilePath != null && 
location.getStorageInfo.getFilePath.nonEmpty) {
+      pbPackedLocationsBuilder.addFilePaths(location.getStorageInfo.getFilePath
+        .substring(location.getStorageInfo.getMountPoint.length))
+    } else {
+      pbPackedLocationsBuilder.addFilePaths("")
+    }
+    
pbPackedLocationsBuilder.addAvailableStorageTypes(location.getStorageInfo.availableStorageTypes)
+    pbPackedLocationsBuilder.addModes(location.getMode.mode())
+  }
+
+  def toPbPackedPartitionLocationsPair(inputLocations: List[PartitionLocation])
+      : PbPackedPartitionLocationsPair = {
+    val packedLocationPairsBuilder = 
PbPackedPartitionLocationsPair.newBuilder()
+    val packedLocationsBuilder = PbPackedPartitionLocations.newBuilder()
+
+    val implicateLocations = inputLocations.map(_.getPeer).filterNot(_ == null)
+
+    val allLocations = (inputLocations ++ implicateLocations)
+    val workerIdList = new util.ArrayList[String](
+      allLocations.map(_.getWorker.toUniqueId()).toSet.asJava)
+    val workerIdIndex = workerIdList.asScala.zipWithIndex.toMap
+    val mountPointsList = new util.ArrayList[String](
+      allLocations.map(
+        _.getStorageInfo.getMountPoint).toSet.asJava)
+    val mountPointsIndex = mountPointsList.asScala.zipWithIndex.toMap
+
+    packedLocationsBuilder.addAllWorkerIdsSet(workerIdList)
+    packedLocationsBuilder.addAllMountPointsSet(mountPointsList)
+
+    val locationIndexes = allLocations.map(_.hashCode()).zipWithIndex.toMap
+
+    for (location <- allLocations) {
+      toPackedPartitionLocation(
+        packedLocationsBuilder,
+        workerIdIndex,
+        mountPointsIndex,
+        location)
+      if (location.getPeer != null) {
+        packedLocationPairsBuilder.addPeerIndexes(
+          locationIndexes(location.getPeer.hashCode()))
+      } else {
+        packedLocationPairsBuilder.addPeerIndexes(-1)

Review Comment:
   I think Integer.MAX_VALUE can be the perfect value to indicate that there is 
no peer for this location.



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

Reply via email to