FMX commented on code in PR #2456:
URL: https://github.com/apache/celeborn/pull/2456#discussion_r1593676216
##########
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)
+ }
+ }
+
+ packedLocationPairsBuilder.setInputLocationSize(inputLocations.size)
+
packedLocationPairsBuilder.setLocations(packedLocationsBuilder.build()).build()
+ }
+
+ def fromPbPackedPartitionLocationsPair(pbPartitionLocationsPair:
PbPackedPartitionLocationsPair)
+ : (util.List[PartitionLocation], util.List[PartitionLocation]) = {
+ val primaryLocations = new util.ArrayList[PartitionLocation]()
+ val replicateLocations = new util.ArrayList[PartitionLocation]()
+ val pbPackedPartitionLocations = pbPartitionLocationsPair.getLocations
+ val inputLocationSize = pbPartitionLocationsPair.getInputLocationSize
+ val idList = pbPackedPartitionLocations.getIdsList
+ val locationCount = idList.size()
+ var index = 0
+
+ val locations = new util.ArrayList[PartitionLocation]()
+ while (index < locationCount) {
+ val loc =
+ fromPackedPartitionLocations(pbPackedPartitionLocations, index)
+ if (index < inputLocationSize) {
Review Comment:
We need to distinguish direct input locations and implicit input locations
to avoid cyclic reference.
--
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]