forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 1
Demo of implementation to the local directory #6
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
Closed
ifilonenko
wants to merge
32
commits into
mccheah:operation-remote-shuffles
from
ifilonenko:SPARK-25299-v3
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
06bf9f9
initial merge
ifilonenko e3e9d68
working version
ifilonenko 458b2be
added shuffle location discovery
ifilonenko 646f1bf
running tests on driver and executor logic
ifilonenko 5555bc9
testing executor writing
ifilonenko 7fabde7
added index file write and data read
ifilonenko 109fbaa
fixing read issues
ifilonenko bce2ed0
investigating issue with correctness bug
ifilonenko 28714b3
refactored executor specific logic and began fixing transport client …
ifilonenko d598e00
remove client issues
ifilonenko 90f3804
added hashcode
ifilonenko 7f30751
small changes to replica-based shuffle service implementation
ifilonenko cffc20c
solved read issue in terms of deserialization
ifilonenko c91574d
IT WORKSSSSSSSS
ifilonenko 7f1b215
scratch
yifeih d0c8f29
attempt 1
yifeih c2231a0
resolving a few of the initial comments while still preserving correc…
ifilonenko 45343fa
fix serialization
yifeih a301d24
basic cleanup
yifeih 9a17589
Merge branch 'SPARK-25299-v3' of github.com:ifilonenko/spark into yh/…
yifeih 3ba25ab
compiles
yifeih d7919f2
Bypass Merge sort works
yifeih 0befe41
small refactors
yifeih 4fba8d2
done refactoring
yifeih a5ee746
more cleanup
yifeih 6e86ac0
more housekeeping
yifeih 4a12c93
sweep sweep
yifeih 40ab79f
Merge pull request #12 from yifeih/yh/ess-metadata-v1
ifilonenko 75ecb66
Update ShuffleLocation to be part of the read API too
yifeih af58978
Changes to ByteBuffer and serialization logic
vanzin 1381f55
resolve some comments regarding BlockManager and slight style
ifilonenko 7c0fa1d
Fix UnsafeShuffleWriter (#15)
yifeih 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
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
150 changes: 150 additions & 0 deletions
150
...work-shuffle/src/main/java/org/apache/spark/network/shuffle/FileWriterStreamCallback.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,150 @@ | ||
package org.apache.spark.network.shuffle; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.channels.WritableByteChannel; | ||
import java.nio.file.StandardOpenOption; | ||
|
||
import org.apache.spark.network.client.StreamCallbackWithID; | ||
|
||
public class FileWriterStreamCallback implements StreamCallbackWithID { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(FileWriterStreamCallback.class); | ||
|
||
public enum FileType { | ||
DATA("shuffle-data"), | ||
INDEX("shuffle-index"); | ||
|
||
private final String typeString; | ||
|
||
FileType(String typeString) { | ||
this.typeString = typeString; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return typeString; | ||
} | ||
} | ||
|
||
private final String appId; | ||
private final int shuffleId; | ||
private final int mapId; | ||
private final File file; | ||
private final FileType fileType; | ||
private WritableByteChannel fileOutputChannel = null; | ||
|
||
public FileWriterStreamCallback( | ||
String appId, | ||
int shuffleId, | ||
int mapId, | ||
File file, | ||
FileWriterStreamCallback.FileType fileType) { | ||
this.appId = appId; | ||
this.shuffleId = shuffleId; | ||
this.mapId = mapId; | ||
this.file = file; | ||
this.fileType = fileType; | ||
} | ||
|
||
public void open() { | ||
logger.info( | ||
"Opening {} for remote writing. File type: {}", file.getAbsolutePath(), fileType); | ||
if (fileOutputChannel != null) { | ||
throw new IllegalStateException( | ||
String.format( | ||
"File %s for is already open for writing (type: %s).", | ||
file.getAbsolutePath(), | ||
fileType)); | ||
} | ||
if (!file.exists()) { | ||
try { | ||
if (!file.getParentFile().isDirectory() && !file.getParentFile().mkdirs()) { | ||
throw new IOException( | ||
String.format( | ||
"Failed to create shuffle file directory at" | ||
+ file.getParentFile().getAbsolutePath() + "(type: %s).", fileType)); | ||
} | ||
|
||
if (!file.createNewFile()) { | ||
throw new IOException( | ||
String.format( | ||
"Failed to create shuffle file (type: %s).", fileType)); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException( | ||
String.format( | ||
"Failed to create shuffle file at %s for backup (type: %s).", | ||
file.getAbsolutePath(), | ||
fileType), | ||
e); | ||
} | ||
} | ||
try { | ||
// TODO encryption | ||
fileOutputChannel = FileChannel.open(file.toPath(), StandardOpenOption.APPEND); | ||
} catch (IOException e) { | ||
throw new RuntimeException( | ||
String.format( | ||
"Failed to find file for writing at %s (type: %s).", | ||
file.getAbsolutePath(), | ||
fileType), | ||
e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getID() { | ||
return String.format("%s-%d-%d-%s", | ||
appId, | ||
shuffleId, | ||
mapId, | ||
fileType); | ||
} | ||
|
||
@Override | ||
public void onData(String streamId, ByteBuffer buf) throws IOException { | ||
verifyShuffleFileOpenForWriting(); | ||
while (buf.hasRemaining()) { | ||
fileOutputChannel.write(buf); | ||
} | ||
} | ||
|
||
@Override | ||
public void onComplete(String streamId) throws IOException { | ||
logger.info( | ||
"Finished writing {}. File type: {}", file.getAbsolutePath(), fileType); | ||
fileOutputChannel.close(); | ||
} | ||
|
||
@Override | ||
public void onFailure(String streamId, Throwable cause) throws IOException { | ||
logger.warn("Failed to write shuffle file at {} (type: %s).", | ||
file.getAbsolutePath(), | ||
fileType, | ||
cause); | ||
fileOutputChannel.close(); | ||
// TODO delete parent dirs too | ||
if (!file.delete()) { | ||
logger.warn( | ||
"Failed to delete incomplete remote shuffle file at %s (type: %s)", | ||
file.getAbsolutePath(), | ||
fileType); | ||
} | ||
} | ||
|
||
private void verifyShuffleFileOpenForWriting() { | ||
if (fileOutputChannel == null) { | ||
throw new RuntimeException( | ||
String.format( | ||
"Shuffle file at %s not open for writing (type: %s).", | ||
file.getAbsolutePath(), | ||
fileType)); | ||
} | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
...e/src/main/java/org/apache/spark/network/shuffle/k8s/KubernetesExternalShuffleClient.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,125 @@ | ||
/* | ||
* 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.spark.network.shuffle.k8s; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import org.apache.spark.network.shuffle.protocol.ShuffleServiceHeartbeat; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.spark.network.client.RpcResponseCallback; | ||
import org.apache.spark.network.client.TransportClient; | ||
import org.apache.spark.network.sasl.SecretKeyHolder; | ||
import org.apache.spark.network.shuffle.ExternalShuffleClient; | ||
import org.apache.spark.network.shuffle.protocol.RegisterDriver; | ||
import org.apache.spark.network.util.TransportConf; | ||
|
||
/** | ||
* A client for talking to the external shuffle service in Kubernetes coarse-grained mode. | ||
* | ||
* This is used by the Spark driver to register with each external shuffle service on the cluster. | ||
* The reason why the driver has to talk to the service is for cleaning up shuffle files reliably | ||
* after the application exits. Kubernetes does not provide a great alternative to do this, so Spark | ||
* has to detect this itself. | ||
*/ | ||
public class KubernetesExternalShuffleClient extends ExternalShuffleClient { | ||
private static final Logger logger = | ||
LoggerFactory.getLogger(KubernetesExternalShuffleClient.class); | ||
|
||
private final ScheduledExecutorService heartbeaterThread = | ||
Executors.newSingleThreadScheduledExecutor( | ||
new ThreadFactoryBuilder() | ||
.setDaemon(true) | ||
.setNameFormat("kubernetes-external-shuffle-client-heartbeater") | ||
.build()); | ||
|
||
/** | ||
* Creates a Kubernetes external shuffle client that wraps the {@link ExternalShuffleClient}. | ||
* Please refer to docs on {@link ExternalShuffleClient} for more information. | ||
*/ | ||
public KubernetesExternalShuffleClient( | ||
TransportConf conf, | ||
SecretKeyHolder secretKeyHolder, | ||
boolean authEnabled, | ||
long registrationTimeoutMs) { | ||
super(conf, secretKeyHolder, authEnabled, registrationTimeoutMs); | ||
} | ||
|
||
public void registerDriverWithShuffleService( | ||
String host, | ||
int port, | ||
long heartbeatTimeoutMs, | ||
long heartbeatIntervalMs) throws IOException, InterruptedException { | ||
|
||
checkInit(); | ||
ByteBuffer registerDriver = new RegisterDriver(appId, heartbeatTimeoutMs).toByteBuffer(); | ||
logger.info("Registering with external shuffle service at " + host + ":" + port); | ||
TransportClient client = clientFactory.createClient(host, port); | ||
client.sendRpc(registerDriver, new RegisterDriverCallback(client, heartbeatIntervalMs)); | ||
} | ||
|
||
private class RegisterDriverCallback implements RpcResponseCallback { | ||
private final TransportClient client; | ||
private final long heartbeatIntervalMs; | ||
|
||
private RegisterDriverCallback(TransportClient client, long heartbeatIntervalMs) { | ||
this.client = client; | ||
this.heartbeatIntervalMs = heartbeatIntervalMs; | ||
} | ||
|
||
@Override | ||
public void onSuccess(ByteBuffer response) { | ||
heartbeaterThread.scheduleAtFixedRate( | ||
new Heartbeater(client), 0, heartbeatIntervalMs, TimeUnit.MILLISECONDS); | ||
logger.info("Successfully registered app " + appId + " with external shuffle service."); | ||
} | ||
|
||
@Override | ||
public void onFailure(Throwable e) { | ||
logger.warn("Unable to register app " + appId + " with external shuffle service. " + | ||
"Please manually remove shuffle data after driver exit. Error: " + e); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
heartbeaterThread.shutdownNow(); | ||
super.close(); | ||
} | ||
|
||
private class Heartbeater implements Runnable { | ||
|
||
private final TransportClient client; | ||
|
||
private Heartbeater(TransportClient client) { | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// TODO: Stop sending heartbeats if the shuffle service has lost the app due to timeout | ||
client.send(new ShuffleServiceHeartbeat(appId).toByteBuffer()); | ||
} | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks odd at least to me - why is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is for the case in which a stream, that is handled by the
KubernetesExternalShuffleBlockResolver
, is malformed and would be then be defaulted to this class via a super.handleStream() request. I can take this out, it isn't necessary