Skip to content
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

[SPARK-32658][CORE] Fix PartitionWriterStream partition length overflow #29474

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.shuffle.sort;

import java.nio.channels.Channels;
import java.util.Arrays;
import java.util.Optional;
import javax.annotation.Nullable;
import java.io.*;
Expand Down Expand Up @@ -274,6 +275,8 @@ private long[] mergeSpills(SpillInfo[] spills) throws IOException {
// Here, we don't need to perform any metrics updates because the bytes written to this
// output file would have already been counted as shuffle bytes written.
partitionLengths = spills[0].partitionLengths;
logger.debug("Merge shuffle spills for mapId {} with length {}", mapId,
partitionLengths.length);
maybeSingleFileWriter.get().transferMapSpillFile(spills[0].file, partitionLengths);
} else {
partitionLengths = mergeSpillsUsingStandardWriter(spills);
Expand Down Expand Up @@ -360,6 +363,7 @@ private void mergeSpillsWithFileStream(
SpillInfo[] spills,
ShuffleMapOutputWriter mapWriter,
@Nullable CompressionCodec compressionCodec) throws IOException {
logger.debug("Merge shuffle spills with FileStream for mapId {}", mapId);
final int numPartitions = partitioner.numPartitions();
final InputStream[] spillInputStreams = new InputStream[spills.length];

Expand All @@ -369,6 +373,11 @@ private void mergeSpillsWithFileStream(
spillInputStreams[i] = new NioBufferedFileInputStream(
spills[i].file,
inputBufferSizeInBytes);
// Only convert the partitionLengths when debug level is enabled.
if (logger.isDebugEnabled()) {
logger.debug("Partition lengths for mapId {} in Spill {}: {}", mapId, i,
Arrays.toString(spills[i].partitionLengths));
}
}
for (int partition = 0; partition < numPartitions; partition++) {
boolean copyThrewException = true;
Expand Down Expand Up @@ -431,6 +440,7 @@ private void mergeSpillsWithFileStream(
private void mergeSpillsWithTransferTo(
SpillInfo[] spills,
ShuffleMapOutputWriter mapWriter) throws IOException {
logger.debug("Merge shuffle spills with TransferTo for mapId {}", mapId);
final int numPartitions = partitioner.numPartitions();
final FileChannel[] spillInputChannels = new FileChannel[spills.length];
final long[] spillInputChannelPositions = new long[spills.length];
Expand All @@ -439,6 +449,11 @@ private void mergeSpillsWithTransferTo(
try {
for (int i = 0; i < spills.length; i++) {
spillInputChannels[i] = new FileInputStream(spills[i].file).getChannel();
// Only convert the partitionLengths when debug level is enabled.
if (logger.isDebugEnabled()) {
logger.debug("Partition lengths for mapId {} in Spill {}: {}", mapId, i,
Arrays.toString(spills[i].partitionLengths));
}
}
for (int partition = 0; partition < numPartitions; partition++) {
boolean copyThrewException = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public MapOutputCommitMessage commitAllPartitions() throws IOException {
}
cleanUp();
File resolvedTmp = outputTempFile != null && outputTempFile.isFile() ? outputTempFile : null;
log.debug("Writing shuffle index file for mapId {} with length {}", mapId,
partitionLengths.length);
blockResolver.writeIndexFileAndCommit(shuffleId, mapId, partitionLengths, resolvedTmp);
return MapOutputCommitMessage.of(partitionLengths);
}
Expand Down Expand Up @@ -211,14 +213,14 @@ public long getNumBytesWritten() {

private class PartitionWriterStream extends OutputStream {
private final int partitionId;
private int count = 0;
private long count = 0;
private boolean isClosed = false;

PartitionWriterStream(int partitionId) {
this.partitionId = partitionId;
}

public int getCount() {
public long getCount() {
return count;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ private[spark] class IndexShuffleBlockResolver(
}
}
} finally {
logDebug(s"Shuffle index for mapId $mapId: ${lengths.mkString("[", ",", "]")}")
if (indexTmp.exists() && !indexTmp.delete()) {
logError(s"Failed to delete temporary index file at ${indexTmp.getAbsolutePath}")
}
Expand Down