Copilot commented on code in PR #3387: URL: https://github.com/apache/celeborn/pull/3387#discussion_r2230465859
########## worker/src/main/java/org/apache/celeborn/service/deploy/worker/WriterHelper.java: ########## @@ -0,0 +1,119 @@ +/* + * 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.celeborn.service.deploy.worker; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.celeborn.common.identity.UserIdentifier; +import org.apache.celeborn.common.meta.WorkerPartitionLocationInfo; +import org.apache.celeborn.common.protocol.PartitionLocation; +import org.apache.celeborn.common.protocol.PartitionSplitMode; +import org.apache.celeborn.common.protocol.PartitionType; +import org.apache.celeborn.common.protocol.message.ControlMessages.ReserveSlotsResponse; +import org.apache.celeborn.common.protocol.message.StatusCode; +import org.apache.celeborn.common.rpc.RpcCallContext; +import org.apache.celeborn.service.deploy.worker.storage.PartitionDataWriter; +import org.apache.celeborn.service.deploy.worker.storage.StorageManager; + +public class WriterHelper { + + private static final Logger LOG = LoggerFactory.getLogger(WriterHelper.class); + + private final StorageManager storageManager; + private final WorkerPartitionLocationInfo partitionLocationInfo; + + public WriterHelper( + StorageManager storageManager, WorkerPartitionLocationInfo partitionLocationInfo) { + this.storageManager = storageManager; + this.partitionLocationInfo = partitionLocationInfo; + } + + public List<PartitionLocation> createWriters( + String shuffleKey, + String applicationId, + int shuffleId, + List<PartitionLocation> requestLocs, + long splitThreshold, + PartitionSplitMode splitMode, + PartitionType partitionType, + boolean rangeReadFilter, + UserIdentifier userIdentifier, + boolean partitionSplitEnabled, + boolean isSegmentGranularityVisible) { + List<PartitionLocation> locs = new ArrayList<>(); + try { + ConcurrentLinkedQueue<PartitionLocation> locQueue = new ConcurrentLinkedQueue<>(); + requestLocs + .parallelStream() + .forEach( + requestLoc -> { + PartitionLocation location = + partitionLocationInfo.getPrimaryLocation(shuffleKey, requestLoc.getUniqueId()); + if (location == null) { + location = requestLoc; + PartitionDataWriter writer; + try { + writer = + storageManager.createPartitionDataWriter( + applicationId, + shuffleId, + location, + splitThreshold, + splitMode, + partitionType, + rangeReadFilter, + userIdentifier, + partitionSplitEnabled, + isSegmentGranularityVisible); + } catch (IOException e) { + throw new RuntimeException(e); + } + locQueue.add(new WorkingPartition(location, writer)); + } else { + locQueue.add(location); + } + }); + locs.addAll(locQueue); + } catch (Exception e) { + LOG.error("CreateWriter for {} failed.", shuffleKey, e); + } + return locs; + } + + public void destroyWriters( + List<PartitionLocation> locs, RpcCallContext context, String shuffleKey, String msg) { + locs.parallelStream() + .forEach( + partitionLocation -> { + WorkingPartition workingPartition = (WorkingPartition) partitionLocation; + PartitionDataWriter fileWriter = workingPartition.getFileWriter(); + fileWriter.destroy( + new IOException( + String.format( + "Destroy FileWriter %s caused by " + "reserving slots failed for %s.", + fileWriter, shuffleKey))); + }); + context.reply(new ReserveSlotsResponse(StatusCode.RESERVE_SLOTS_FAILED, msg)); Review Comment: The destroyWriters method should not send RPC replies as it's called multiple times in the Controller. This will cause multiple replies to be sent for the same RPC call, which is incorrect. ```suggestion ``` ########## worker/src/main/java/org/apache/celeborn/service/deploy/worker/WriterHelper.java: ########## @@ -0,0 +1,119 @@ +/* + * 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.celeborn.service.deploy.worker; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.celeborn.common.identity.UserIdentifier; +import org.apache.celeborn.common.meta.WorkerPartitionLocationInfo; +import org.apache.celeborn.common.protocol.PartitionLocation; +import org.apache.celeborn.common.protocol.PartitionSplitMode; +import org.apache.celeborn.common.protocol.PartitionType; +import org.apache.celeborn.common.protocol.message.ControlMessages.ReserveSlotsResponse; +import org.apache.celeborn.common.protocol.message.StatusCode; +import org.apache.celeborn.common.rpc.RpcCallContext; +import org.apache.celeborn.service.deploy.worker.storage.PartitionDataWriter; +import org.apache.celeborn.service.deploy.worker.storage.StorageManager; + +public class WriterHelper { + + private static final Logger LOG = LoggerFactory.getLogger(WriterHelper.class); + + private final StorageManager storageManager; + private final WorkerPartitionLocationInfo partitionLocationInfo; + + public WriterHelper( + StorageManager storageManager, WorkerPartitionLocationInfo partitionLocationInfo) { + this.storageManager = storageManager; + this.partitionLocationInfo = partitionLocationInfo; + } + + public List<PartitionLocation> createWriters( + String shuffleKey, + String applicationId, + int shuffleId, + List<PartitionLocation> requestLocs, + long splitThreshold, + PartitionSplitMode splitMode, + PartitionType partitionType, + boolean rangeReadFilter, + UserIdentifier userIdentifier, + boolean partitionSplitEnabled, + boolean isSegmentGranularityVisible) { + List<PartitionLocation> locs = new ArrayList<>(); + try { + ConcurrentLinkedQueue<PartitionLocation> locQueue = new ConcurrentLinkedQueue<>(); + requestLocs + .parallelStream() + .forEach( + requestLoc -> { + PartitionLocation location = + partitionLocationInfo.getPrimaryLocation(shuffleKey, requestLoc.getUniqueId()); Review Comment: The method is calling `getPrimaryLocation` for all request locations, but this should differentiate between primary and replica locations based on the context. The original code used `getPrimaryLocation` for primary locations and `getReplicaLocation` for replica locations. ```suggestion PartitionLocation location; if (requestLoc.isPrimary()) { location = partitionLocationInfo.getPrimaryLocation(shuffleKey, requestLoc.getUniqueId()); } else { location = partitionLocationInfo.getReplicaLocation(shuffleKey, requestLoc.getUniqueId()); } ``` -- 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]
