Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CORE] Updates to remote cache reads
Covered by tests in DistributedSuite
- Loading branch information
Showing
15 changed files
with
299 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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
47 changes: 47 additions & 0 deletions
47
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/DownloadFile.java
This file contains 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,47 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A handle on the file used when fetching remote data to disk. Used to ensure the lifecycle of | ||
* writing the data, reading it back, and then cleaning it up is followed. Specific implementations | ||
* may also handle encryption. The data can be read only via DownloadFileWritableChannel, | ||
* which ensures data is not read until after the writer is closed. | ||
*/ | ||
public interface DownloadFile { | ||
/** | ||
* Delete the file. | ||
* | ||
* @return <code>true</code> if and only if the file or directory is | ||
* successfully deleted; <code>false</code> otherwise | ||
*/ | ||
public boolean delete(); | ||
|
||
/** | ||
* A channel for writing data to the file. This special channel allows access to the data for | ||
* reading, after the channel is closed, via {@link DownloadFileWritableChannel#closeAndRead()}. | ||
*/ | ||
public DownloadFileWritableChannel openForWriting() throws IOException; | ||
|
||
/** | ||
* The path of the file, intended only for debug purposes. | ||
*/ | ||
public String path(); | ||
} |
This file contains 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
31 changes: 31 additions & 0 deletions
31
...k-shuffle/src/main/java/org/apache/spark/network/shuffle/DownloadFileWritableChannel.java
This file contains 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,31 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.spark.network.buffer.ManagedBuffer; | ||
|
||
import java.io.OutputStream; | ||
import java.nio.channels.WritableByteChannel; | ||
|
||
/** | ||
* A channel for writing data which is fetched to disk, which allows access to the written data only | ||
* after the writer has been closed. Used with DownloadFile and DownloadFileManager. | ||
*/ | ||
public interface DownloadFileWritableChannel extends WritableByteChannel { | ||
public ManagedBuffer closeAndRead(); | ||
} |
This file contains 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 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 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
91 changes: 91 additions & 0 deletions
91
...on/network-shuffle/src/main/java/org/apache/spark/network/shuffle/SimpleDownloadFile.java
This file contains 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,91 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.Channels; | ||
import java.nio.channels.WritableByteChannel; | ||
|
||
import org.apache.spark.network.buffer.FileSegmentManagedBuffer; | ||
import org.apache.spark.network.buffer.ManagedBuffer; | ||
import org.apache.spark.network.util.TransportConf; | ||
|
||
/** | ||
* A DownloadFile that does not take any encryption settings into account for reading and | ||
* writing data. | ||
* | ||
* This does *not* mean the data in the file is un-encrypted -- it could be that the data is | ||
* already encrypted when its written, and subsequent layer is responsible for decrypting. | ||
*/ | ||
public class SimpleDownloadFile implements DownloadFile { | ||
|
||
private final File file; | ||
private final TransportConf transportConf; | ||
|
||
public SimpleDownloadFile(File file, TransportConf transportConf) { | ||
this.file = file; | ||
this.transportConf = transportConf; | ||
} | ||
|
||
@Override | ||
public boolean delete() { | ||
return file.delete(); | ||
} | ||
|
||
@Override | ||
public DownloadFileWritableChannel openForWriting() throws IOException { | ||
return new SimpleDownloadWritableChannel(); | ||
} | ||
|
||
@Override | ||
public String path() { | ||
return file.getAbsolutePath(); | ||
} | ||
|
||
private class SimpleDownloadWritableChannel implements DownloadFileWritableChannel { | ||
|
||
private final WritableByteChannel channel; | ||
|
||
SimpleDownloadWritableChannel() throws FileNotFoundException { | ||
channel = Channels.newChannel(new FileOutputStream(file)); | ||
} | ||
|
||
@Override | ||
public ManagedBuffer closeAndRead() { | ||
return new FileSegmentManagedBuffer(transportConf, file, 0, file.length()); | ||
} | ||
|
||
@Override | ||
public int write(ByteBuffer src) throws IOException { | ||
return channel.write(src); | ||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return channel.isOpen(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
channel.close(); | ||
} | ||
} | ||
} |
This file contains 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 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.