-
Notifications
You must be signed in to change notification settings - Fork 382
feat: add Celeborn shuffle manager and partition pusher (5/n) #5501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sunchao
merged 2 commits into
apache:main
from
pingzh:pingzh-celeborn-shuffle-manager-part-5
Aug 27, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
236 changes: 236 additions & 0 deletions
236
spark/src/main/java/org/apache/comet/shuffle/CelebornShufflePartitionPusher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,236 @@ | ||
| /* | ||
| * 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.comet.shuffle; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.lang.reflect.Method; | ||
| import java.lang.reflect.Modifier; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteOrder; | ||
|
|
||
| /** Adapts complete Comet shuffle frames to an existing, task-owned Celeborn shuffle client. */ | ||
| public final class CelebornShufflePartitionPusher implements ShufflePartitionPusher { | ||
|
|
||
| private static final int CELEBORN_BATCH_HEADER_BYTES = 4 * Integer.BYTES; | ||
| private static final int MINIMUM_COMET_FRAME_BYTES = 2 * Long.BYTES; | ||
|
|
||
| private final Object shuffleClient; | ||
| private final Method pushOrMergeData; | ||
| private final Method computeBatchCRC; | ||
| private final int shuffleId; | ||
| private final int mapId; | ||
| private final int encodedAttemptId; | ||
| private final int numMappers; | ||
| private final int numPartitions; | ||
|
|
||
| /** | ||
| * Captures all shuffle and map-attempt identity before native worker threads invoke this pusher. | ||
| * | ||
| * <p>Celeborn remains an optional, application-provided dependency: accepting its client as an | ||
| * {@link Object} and resolving its public raw-push method avoids a compile-time dependency. | ||
| * | ||
| * @param shuffleClient the application's existing Celeborn shuffle client | ||
| * @param shuffleId the Celeborn shuffle identifier for this task | ||
| * @param mapId the logical map partition | ||
| * @param encodedAttemptId the Celeborn-encoded stage and task attempt | ||
| * @param numMappers the total number of map partitions | ||
| * @param numPartitions the total number of reduce partitions | ||
| */ | ||
| public CelebornShufflePartitionPusher( | ||
| Object shuffleClient, | ||
| int shuffleId, | ||
| int mapId, | ||
| int encodedAttemptId, | ||
| int numMappers, | ||
| int numPartitions) { | ||
| if (shuffleClient == null) { | ||
| throw new IllegalArgumentException("Celeborn shuffle client must not be null"); | ||
| } | ||
| if (shuffleId < 0) { | ||
| throw new IllegalArgumentException("Celeborn shuffle ID must not be negative"); | ||
| } | ||
| if (mapId < 0) { | ||
| throw new IllegalArgumentException("Celeborn map ID must not be negative"); | ||
| } | ||
| if (encodedAttemptId < 0) { | ||
| throw new IllegalArgumentException("Celeborn encoded attempt ID must not be negative"); | ||
| } | ||
| if (numMappers <= 0) { | ||
| throw new IllegalArgumentException("Celeborn mapper count must be positive"); | ||
| } | ||
| if (mapId >= numMappers) { | ||
| throw new IllegalArgumentException("Celeborn map ID is outside the mapper count"); | ||
| } | ||
| if (numPartitions <= 0) { | ||
| throw new IllegalArgumentException("Celeborn partition count must be positive"); | ||
| } | ||
|
|
||
| final Method pushMethod; | ||
| try { | ||
| pushMethod = | ||
| shuffleClient | ||
| .getClass() | ||
| .getMethod( | ||
| "pushOrMergeData", | ||
| int.class, | ||
| int.class, | ||
| int.class, | ||
| int.class, | ||
| byte[].class, | ||
| int.class, | ||
| int.class, | ||
| int.class, | ||
| int.class, | ||
| boolean.class, | ||
| boolean.class); | ||
| } catch (NoSuchMethodException | SecurityException e) { | ||
| throw new IllegalArgumentException( | ||
| "Celeborn shuffle client does not provide the required public raw-push API", e); | ||
| } | ||
|
|
||
| if (pushMethod.getReturnType() != int.class || Modifier.isStatic(pushMethod.getModifiers())) { | ||
| throw new IllegalArgumentException( | ||
| "Celeborn raw-push API must be an instance method returning an int"); | ||
| } | ||
|
|
||
| Method integrityMethod = null; | ||
| try { | ||
| integrityMethod = | ||
| shuffleClient | ||
| .getClass() | ||
| .getMethod( | ||
| "computeBatchCRC", | ||
| int.class, | ||
| int.class, | ||
| int.class, | ||
| int.class, | ||
| byte[].class, | ||
| int.class, | ||
| int.class); | ||
| } catch (NoSuchMethodException missing) { | ||
| // Older Celeborn clients account for integrity inside pushOrMergeData instead. | ||
| try { | ||
| for (Method method : shuffleClient.getClass().getMethods()) { | ||
| if (method.getName().equals("computeBatchCRC")) { | ||
| throw new IllegalArgumentException( | ||
| "Celeborn integrity-accounting API has an incompatible signature", missing); | ||
| } | ||
| } | ||
| } catch (SecurityException failure) { | ||
| throw new IllegalArgumentException( | ||
| "Cannot inspect the optional Celeborn integrity-accounting API", failure); | ||
| } | ||
| } catch (SecurityException failure) { | ||
| throw new IllegalArgumentException( | ||
| "Cannot resolve the optional Celeborn integrity-accounting API", failure); | ||
| } | ||
|
|
||
| if (integrityMethod != null | ||
| && (integrityMethod.getReturnType() != void.class | ||
| || Modifier.isStatic(integrityMethod.getModifiers()))) { | ||
| throw new IllegalArgumentException( | ||
| "Celeborn integrity-accounting API must be an instance method returning void"); | ||
| } | ||
|
|
||
| this.shuffleClient = shuffleClient; | ||
| this.pushOrMergeData = pushMethod; | ||
| this.computeBatchCRC = integrityMethod; | ||
| this.shuffleId = shuffleId; | ||
| this.mapId = mapId; | ||
| this.encodedAttemptId = encodedAttemptId; | ||
| this.numMappers = numMappers; | ||
| this.numPartitions = numPartitions; | ||
| } | ||
|
|
||
| /** Sends exactly one complete, already-compressed Comet shuffle frame to Celeborn. */ | ||
| @Override | ||
| public void pushPartitionData(int partitionId, byte[] data, int length) throws IOException { | ||
| if (partitionId < 0 || partitionId >= numPartitions) { | ||
| throw new IOException("Celeborn output partition is outside this task's partition count"); | ||
| } | ||
| if (data == null) { | ||
| throw new IOException("Celeborn shuffle frame must not be null"); | ||
| } | ||
| if (length > Integer.MAX_VALUE - CELEBORN_BATCH_HEADER_BYTES) { | ||
| throw new IOException("Celeborn shuffle frame and transport header exceed the byte limit"); | ||
| } | ||
| if (length < MINIMUM_COMET_FRAME_BYTES || length > data.length) { | ||
| throw new IOException("Celeborn shuffle frame length must describe one complete frame"); | ||
| } | ||
|
|
||
| final long declaredBodyLength = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN).getLong(); | ||
| if (declaredBodyLength != (long) length - Long.BYTES) { | ||
| throw new IOException( | ||
| "Celeborn shuffle frame declares " | ||
| + declaredBodyLength | ||
| + " body bytes, but contains " | ||
| + (length - Long.BYTES)); | ||
| } | ||
|
|
||
| final int accepted; | ||
| try { | ||
| if (computeBatchCRC != null) { | ||
| computeBatchCRC.invoke( | ||
| shuffleClient, shuffleId, mapId, encodedAttemptId, partitionId, data, 0, length); | ||
| } | ||
|
|
||
| accepted = | ||
| (int) | ||
| pushOrMergeData.invoke( | ||
| shuffleClient, | ||
| shuffleId, | ||
| mapId, | ||
| encodedAttemptId, | ||
| partitionId, | ||
| data, | ||
| 0, | ||
| length, | ||
| numMappers, | ||
| numPartitions, | ||
| true, | ||
| true); | ||
| } catch (IllegalAccessException e) { | ||
| throw new IOException("Cannot invoke the public Celeborn raw-push API", e); | ||
| } catch (InvocationTargetException e) { | ||
| Throwable cause = e.getCause(); | ||
| if (cause instanceof IOException) { | ||
| throw (IOException) cause; | ||
| } | ||
| if (cause instanceof RuntimeException) { | ||
| throw (RuntimeException) cause; | ||
| } | ||
| if (cause instanceof Error) { | ||
| throw (Error) cause; | ||
| } | ||
| throw new IOException("Celeborn raw shuffle push failed", cause); | ||
| } | ||
|
|
||
| int minimumAccepted = length + CELEBORN_BATCH_HEADER_BYTES; | ||
| if (accepted < minimumAccepted) { | ||
| throw new IOException( | ||
| "Celeborn raw shuffle push accepted " | ||
| + accepted | ||
| + " bytes; expected at least " | ||
| + minimumAccepted | ||
| + " including its transport header"); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.