-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-15074][Shuffle] Cache shuffle index file to speedup shuffle fetch #12944
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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 com.google.common.cache.LoadingCache; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import sun.nio.ch.IOUtil; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doh, it looks like this unused import is breaking things. Let me hotfix to remove it. |
||
|
||
import java.io.DataInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.LongBuffer; | ||
|
||
/** | ||
* Keeps the index information for a particular map output | ||
* as an in-memory LongBuffer. | ||
*/ | ||
public class ShuffleIndexInformation { | ||
/** offsets as long buffer */ | ||
private final LongBuffer offsets; | ||
|
||
public ShuffleIndexInformation(File indexFile) throws IOException { | ||
int size = (int)indexFile.length(); | ||
ByteBuffer buffer = ByteBuffer.allocate(size); | ||
offsets = buffer.asLongBuffer(); | ||
DataInputStream dis = null; | ||
try { | ||
dis = new DataInputStream(new FileInputStream(indexFile)); | ||
dis.readFully(buffer.array()); | ||
} finally { | ||
if (dis != null) { | ||
dis.close(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get index offset for a particular reducer. | ||
*/ | ||
public ShuffleIndexRecord getIndex(int reduceId) { | ||
long offset = offsets.get(reduceId); | ||
long nextOffset = offsets.get(reduceId + 1); | ||
return new ShuffleIndexRecord(offset, nextOffset - offset); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Contains offset and length of the shuffle block data. | ||
*/ | ||
public class ShuffleIndexRecord { | ||
private final long offset; | ||
private final long length; | ||
|
||
public ShuffleIndexRecord(long offset, long length) { | ||
this.offset = offset; | ||
this.length = length; | ||
} | ||
|
||
public long getOffset() { | ||
return offset; | ||
} | ||
|
||
public long getLength() { | ||
return length; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And a newline at the end of this file maybe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will fix, thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The convention seems to be to not have newlines at the end of files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems it was rebased but I guess I meant below:
meaning EDITED: Oh, i just found https://github.com/apache/spark/blob/master/scalastyle-config.xml#L281-L282 and https://github.com/apache/spark/blob/master/scalastyle-config.xml#L117 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
|
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.
It turns out that this call will fail with
ArrayIndexOutOfBoundsException
if thereduceId
is too large. In the old code, an invalidreduceId
would lead to anIOException
because we'd skip past the end of the input stream and try to read.However, I don't think that this subtle change in behavior is going to necessarily cause problems from the caller's perspective since
ArrayIndexOutOfBoundsException
is also aRuntimeException
and this code was already throwingRuntimeException
in the "index file is missing" error case. Therefore, this looks good to me!