You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@celeborn.apache.org by "waitinfuture (via GitHub)" <gi...@apache.org> on 2023/09/16 14:57:41 UTC
[GitHub] [incubator-celeborn] waitinfuture commented on a diff in pull request #1907: [CELEBORN-980] Asynchronously delete original files to fix `ReusedExchange` bug
waitinfuture commented on code in PR #1907:
URL: https://github.com/apache/incubator-celeborn/pull/1907#discussion_r1327960673
##########
common/src/main/proto/TransportMessages.proto:
##########
@@ -493,4 +494,13 @@ message PbStreamHandler {
int32 numChunks = 2;
repeated int64 chunkOffsets = 3 ;
string fullPath = 4;
-}
\ No newline at end of file
+}
+
+message PbBufferStreamEnd {
+ enum Type {
+ Spark = 0;
Review Comment:
Better to use `ChunkStream/CreditStream`, or `MapPartition/ReducePartition`, WDYT @RexXiong @FMX
##########
worker/src/main/java/org/apache/celeborn/service/deploy/worker/storage/PartitionFilesSorter.java:
##########
@@ -687,4 +709,88 @@ private void readBufferBySize(ByteBuffer buffer, int toRead) throws IOException
}
}
}
+
+ public void cleanupExpiredShuffleKey(Set<String> expiredShuffleKeys) {
+ cleaner.cleanupExpiredShuffleKey(expiredShuffleKeys);
+ }
+}
+
+class PartitionFilesCleaner {
+ private static final Logger logger = LoggerFactory.getLogger(PartitionFilesCleaner.class);
+
+ private final LinkedBlockingQueue<PartitionFilesSorter.FileSorter> queue =
+ new LinkedBlockingQueue<>();
+ private final Lock lock = new ReentrantLock();
+ private final Condition notEmpty = lock.newCondition();
+
+ PartitionFilesCleaner(ChunkStreamManager chunkStreamManager) {
+ Thread cleaner =
+ new Thread(
+ () -> {
+ while (true) {
+ try {
+ lock.lockInterruptibly();
+ while (queue.isEmpty()) {
+ notEmpty.await(500, TimeUnit.MILLISECONDS);
+ }
+ Iterator<PartitionFilesSorter.FileSorter> it = queue.iterator();
+ while (it.hasNext()) {
+ PartitionFilesSorter.FileSorter sorter = it.next();
+ boolean streamFetchFinished = true;
+ Set<Long> streamIds =
+ chunkStreamManager.shuffleStreamIds.get(sorter.getShuffleKey());
+
+ if (streamIds != null) {
+ for (long streamId : streamIds) {
+ ChunkStreamManager.StreamRegisterState registerState =
+ chunkStreamManager.streamRegisterStates.get(streamId);
+ if (registerState != null) {
+ boolean hasOriginalFileFetcher =
+ !registerState.isRangeRead()
+ // TODO:(fchen)
+ // && registerState.isReadBufferFromOriginalFile()
+ && registerState.isRegisterBefore(sorter.getStartTimestamp());
Review Comment:
Seems original fetch can be registered after sorter's timestamp. For example at time1 a range reader comes and `FileSorter` is created, at time2 a non-range reader comes and at this time the sort task has not finished, so it uses original file but has larger timestamp than `FileSorter`'s.
##########
worker/src/main/java/org/apache/celeborn/service/deploy/worker/storage/ChunkStreamManager.java:
##########
@@ -169,6 +227,7 @@ public void cleanupExpiredShuffleKey(Set<String> expiredShuffleKeys) {
// normally expiredStreamIds set will be empty as streamId will be removed when be fully read
if (expiredStreamIds != null && !expiredStreamIds.isEmpty()) {
streams.keySet().removeAll(expiredStreamIds);
+ streamRegisterStates.keySet().removeAll(expiredShuffleKeys);
Review Comment:
Should be `expiredStreamIds`
##########
client/src/main/java/org/apache/celeborn/client/read/WorkerPartitionReader.java:
##########
@@ -171,27 +187,28 @@ private void fetchChunks() throws IOException, InterruptedException {
final int inFlight = chunkIndex - returnedChunks;
if (inFlight < fetchMaxReqsInFlight) {
final int toFetch =
- Math.min(fetchMaxReqsInFlight - inFlight + 1, streamHandle.getNumChunks() - chunkIndex);
+ Math.min(fetchMaxReqsInFlight - inFlight + 1, streamHandler.getNumChunks() - chunkIndex);
for (int i = 0; i < toFetch; i++) {
if (testFetch && fetchChunkRetryCnt < fetchChunkMaxRetry - 1 && chunkIndex == 3) {
callback.onFailure(chunkIndex, new CelebornIOException("Test fetch chunk failure"));
} else {
- try {
- TransportClient client =
- clientFactory.createClient(location.getHost(), location.getFetchPort());
- client.fetchChunk(streamHandle.getStreamId(), chunkIndex, fetchTimeoutMs, callback);
- chunkIndex++;
- } catch (IOException e) {
- logger.error(
- "fetchChunk for streamId: {}, chunkIndex: {} failed.",
- streamHandle.getStreamId(),
- chunkIndex,
- e);
- ExceptionUtils.wrapAndThrowIOException(e);
- } catch (InterruptedException e) {
- logger.error("PartitionReader thread interrupted while fetching chunks.");
- throw e;
+ if (!client.isActive()) {
+ try {
+ client = clientFactory.createClient(location.getHost(), location.getFetchPort());
Review Comment:
`clientFactory.createClient` will call `handler.getResponseHandler().updateTimeOfLastRequest()` when cached client is found. But since `client.fetchChunk` will also call `updateTimeOfLastRequest`, so I think it's fine here.
##########
worker/src/main/scala/org/apache/celeborn/service/deploy/worker/FetchHandler.scala:
##########
@@ -96,128 +95,122 @@ class FetchHandler(val conf: CelebornConf, val transportConf: TransportConf)
case r: ChunkFetchRequest =>
handleChunkFetchRequest(client, r)
case r: RpcRequest =>
- // process PbOpenStream RPC
- var streamShuffleKey: String = null
- var streamFileName: String = null
- try {
- val pbMsg = TransportMessage.fromByteBuffer(r.body().nioByteBuffer())
- val pbOpenStream = pbMsg.getParsedPayload[PbOpenStream]
- val (shuffleKey, fileName, startIndex, endIndex, initialCredit, readLocalShuffle) =
- (
- pbOpenStream.getShuffleKey,
- pbOpenStream.getFileName,
- pbOpenStream.getStartIndex,
- pbOpenStream.getEndIndex,
- pbOpenStream.getInitialCredit,
- pbOpenStream.getReadLocalShuffle)
- streamShuffleKey = shuffleKey
- streamFileName = fileName
- workerSource.startTimer(WorkerSource.OPEN_STREAM_TIME, streamShuffleKey)
- handleOpenStreamInternal(
- client,
- shuffleKey,
- fileName,
- startIndex,
- endIndex,
- initialCredit,
- r,
- false,
- readLocalShuffle)
- } catch {
- case _: Exception =>
- // process legacy OpenStream RPCs
- logDebug("Open stream with legacy RPCs")
- try {
- val decodedMsg = Message.decode(r.body().nioByteBuffer())
- val (shuffleKey, fileName) =
- if (decodedMsg.`type`() == Type.OPEN_STREAM) {
- val openStream = decodedMsg.asInstanceOf[OpenStream]
- (
- new String(openStream.shuffleKey, StandardCharsets.UTF_8),
- new String(openStream.fileName, StandardCharsets.UTF_8))
- } else {
- val openStreamWithCredit = decodedMsg.asInstanceOf[OpenStreamWithCredit]
- (
- new String(openStreamWithCredit.shuffleKey, StandardCharsets.UTF_8),
- new String(openStreamWithCredit.fileName, StandardCharsets.UTF_8))
- }
- streamShuffleKey = shuffleKey
- streamFileName = fileName
- var startIndex = 0
- var endIndex = 0
- var initialCredit = 0
- getRawFileInfo(shuffleKey, fileName).getPartitionType match {
- case PartitionType.REDUCE =>
- startIndex = decodedMsg.asInstanceOf[OpenStream].startMapIndex
- endIndex = decodedMsg.asInstanceOf[OpenStream].endMapIndex
- case PartitionType.MAP =>
- initialCredit = decodedMsg.asInstanceOf[OpenStreamWithCredit].initialCredit
- startIndex = decodedMsg.asInstanceOf[OpenStreamWithCredit].startIndex
- endIndex = decodedMsg.asInstanceOf[OpenStreamWithCredit].endIndex
- case PartitionType.MAPGROUP =>
- }
- handleOpenStreamInternal(
- client,
- shuffleKey,
- fileName,
- startIndex,
- endIndex,
- initialCredit,
- r,
- true)
- } catch {
- case e: IOException =>
- handleRpcIOException(client, r.requestId, streamShuffleKey, streamFileName, e)
- }
- } finally {
- r.body().release()
- workerSource.stopTimer(WorkerSource.OPEN_STREAM_TIME, streamShuffleKey)
- }
+ handleRpcRequest(client, r)
case unknown: RequestMessage =>
throw new IllegalArgumentException(s"Unknown message type id: ${unknown.`type`.id}")
}
}
+ private def handleRpcRequest(client: TransportClient, rpcRequest: RpcRequest): Unit = {
+ try {
+ val message = TransportMessage.fromByteBuffer(rpcRequest.body().nioByteBuffer())
+ .getParsedPayload[GeneratedMessageV3]
+ if (message == null) {
+ return handleLegacyRpcMessage(client, rpcRequest)
Review Comment:
In case of legacy messages, i.e. `OPEN_STREAM` and `OPEN_STREAM_WITH_CREDIT`, I suppose `TransportMessage.fromByteBuffer` will throw Exception instead of returning `null`, that's why previously handling legacy is inside the catch block. @FMX could you confirm this?
##########
worker/src/main/java/org/apache/celeborn/service/deploy/worker/storage/ChunkStreamManager.java:
##########
@@ -148,18 +181,43 @@ public long chunksBeingTransferred() {
public long registerStream(
String shuffleKey, FileManagedBuffers buffers, TimeWindow fetchTimeMetric) {
long myStreamId = nextStreamId.getAndIncrement();
- streams.put(myStreamId, new StreamState(shuffleKey, buffers, fetchTimeMetric));
+ return registerStream(myStreamId, shuffleKey, buffers, fetchTimeMetric);
+ }
+
+ public long registerStream(
+ long streamId, String shuffleKey, FileManagedBuffers buffers, TimeWindow fetchTimeMetric) {
+ streams.put(streamId, new StreamState(shuffleKey, buffers, fetchTimeMetric));
shuffleStreamIds.compute(
shuffleKey,
(key, value) -> {
if (value == null) {
value = ConcurrentHashMap.newKeySet();
}
- value.add(myStreamId);
+ value.add(streamId);
return value;
});
- return myStreamId;
+ return streamId;
+ }
+
+ public long registeringStream(String shuffleKey, String fileName, int startIndex, int endIndex) {
Review Comment:
`registeringStream` and `registerStream` are a bit confusing
##########
worker/src/main/java/org/apache/celeborn/service/deploy/worker/storage/PartitionFilesSorter.java:
##########
@@ -687,4 +709,88 @@ private void readBufferBySize(ByteBuffer buffer, int toRead) throws IOException
}
}
}
+
+ public void cleanupExpiredShuffleKey(Set<String> expiredShuffleKeys) {
+ cleaner.cleanupExpiredShuffleKey(expiredShuffleKeys);
+ }
+}
+
+class PartitionFilesCleaner {
+ private static final Logger logger = LoggerFactory.getLogger(PartitionFilesCleaner.class);
+
+ private final LinkedBlockingQueue<PartitionFilesSorter.FileSorter> queue =
+ new LinkedBlockingQueue<>();
+ private final Lock lock = new ReentrantLock();
+ private final Condition notEmpty = lock.newCondition();
+
+ PartitionFilesCleaner(ChunkStreamManager chunkStreamManager) {
+ Thread cleaner =
+ new Thread(
+ () -> {
+ while (true) {
+ try {
+ lock.lockInterruptibly();
+ while (queue.isEmpty()) {
+ notEmpty.await(500, TimeUnit.MILLISECONDS);
+ }
+ Iterator<PartitionFilesSorter.FileSorter> it = queue.iterator();
+ while (it.hasNext()) {
+ PartitionFilesSorter.FileSorter sorter = it.next();
+ boolean streamFetchFinished = true;
+ Set<Long> streamIds =
+ chunkStreamManager.shuffleStreamIds.get(sorter.getShuffleKey());
Review Comment:
This logic seems to be if **ANY** file of the shuffle has streams reading the original file, all original files can not be deleted, instead of checking the current file.
##########
worker/src/main/java/org/apache/celeborn/service/deploy/worker/storage/ChunkStreamManager.java:
##########
@@ -44,9 +44,41 @@ public class ChunkStreamManager {
private final AtomicLong nextStreamId;
// StreamId -> StreamState
protected final ConcurrentHashMap<Long, StreamState> streams;
+ // StreamId -> StreamRegisterState
+ protected final ConcurrentHashMap<Long, StreamRegisterState> streamRegisterStates;
// ShuffleKey -> StreamId
protected final ConcurrentHashMap<String, Set<Long>> shuffleStreamIds;
+ protected static class StreamRegisterState {
+ final long streamId;
Review Comment:
`streamId` seems unnecessary
--
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: issues-unsubscribe@celeborn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org