Skip to content

[SPARK-25299] Make UnsafeShuffleWriter use the new API#9

Merged
ifilonenko merged 13 commits intoshuffle-writer-default-implfrom
shuffle-writer-default-impl-unsafe
Apr 16, 2019
Merged

[SPARK-25299] Make UnsafeShuffleWriter use the new API#9
ifilonenko merged 13 commits intoshuffle-writer-default-implfrom
shuffle-writer-default-impl-unsafe

Conversation

@ifilonenko
Copy link
Collaborator

What changes were proposed in this pull request?

Make UnsafeShuffleWriter use the new API

Shuffle Writes [4/6]

How was this patch tested?

Compiled and unit tests

@ifilonenko
Copy link
Collaborator Author

@mccheah @yifeih for initial opinions

@ifilonenko ifilonenko force-pushed the shuffle-writer-default-impl branch from 91fea02 to 6f0c44b Compare April 7, 2019 17:19
@ifilonenko ifilonenko force-pushed the shuffle-writer-default-impl-unsafe branch from c6cd4c7 to 3ee7d73 Compare April 7, 2019 17:26
@ifilonenko ifilonenko changed the title [SPARK-25299][WIP] Make UnsafeShuffleWriter use the new API [SPARK-25299] Make UnsafeShuffleWriter use the new API Apr 9, 2019
@ifilonenko
Copy link
Collaborator Author

@mccheah @yifeih this PR is ready for merge after approval

ShufflePartitionWriter writer = null;
try {
writer = mapWriter.getNextPartitionWriter();
writer.toStream();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this the file does not get created and it fails UnsafeShuffleWriter.writeEmptyIterator

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we commit all partitions, should we not check that we never created a writer; if we never did then we need to make the file?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I believe we talked about this in the first writer PR where the empty file was made by blockResolver.writeIndexFileAndCommit()?

Copy link
Collaborator Author

@ifilonenko ifilonenko Apr 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the test is expecting a file.... idk why, so maybe we should bring that create file method back?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've always expected a file, that's correct. The question is why do we have to call writer.toStream to ensure the file is created? I'm fairly certain the error is in how we wrote the plugin.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is why, i think on commit we might need to create an empty file if a file does not exist. As we initially wrote but decided to take out

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We thought that blockIndexResolver.writeIndexFileAndCommit should create the file. Why is it not doing so in this case?

final CountingOutputStream mergedFileOutputStream = new CountingOutputStream(bos);

boolean threwException = true;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this blank line

FileChannel mergedFileOutputChannel = null;

boolean threwException = true;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for blank line

writeMetrics.incWriteTime(System.nanoTime() - writeStartTime);
}
} catch (IOException e) {
throw e;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to throw e here?

outputFileChannel.close();
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for blank line


Random rand = new Random();
TaskContext$.MODULE$.setTaskContext(new TaskContextImpl(
0, 0, 0, rand.nextInt(10000), 0, taskMemoryManager, new Properties(), null, taskMetrics));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we can't use a fixed number instead of a random one?

Copy link

@yifeih yifeih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few questions and comments, other than that, looks good to me!

ShufflePartitionWriter writer = null;
try {
writer = mapWriter.getNextPartitionWriter();
writer.toStream();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I believe we talked about this in the first writer PR where the empty file was made by blockResolver.writeIndexFileAndCommit()?


@Override
public void close() throws IOException {
flush();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, why did we get rid of this?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On one hand it's inconsequential because the contract is the writer above this never closes this stream - it leaves it up to the partition writer to close this.

On the other hand, this is to preserve an optimization we discovered in UnsafeShuffleWriter that encourages us to minimize the number of times we flush the buffer to the underlying file.

We can get correctness by just flushing the merged buffered file stream at the very end when we commit all the partitions.

when(taskContext.taskMemoryManager()).thenReturn(taskMemoryManager);

Random rand = new Random();
TaskContext$.MODULE$.setTaskContext(new TaskContextImpl(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused about this because there's already a taskContext object that's mocked. why can't you just set it to that?

public void commitAllPartitions() throws IOException {
cleanUp();
blockResolver.writeIndexFileAndCommit(shuffleId, mapId, partitionLengths, outputTempFile);
if (!outputFile.exists()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't blockResolver#writeIndexFileAndCommit creating the file?

final boolean encryptionEnabled = blockManager.serializerManager().encryptionEnabled();
final int numPartitions = partitioner.numPartitions();
long[] partitionLengths = new long[numPartitions];
logger.error(mapWriter.toString());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meep, i left a log statement :(

// output file would have already been counted as shuffle bytes written.
Files.move(spills[0].file, outputFile);
return spills[0].partitionLengths;
ShufflePartitionWriter writer = null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need to commitAllPartitions here? I'd think we wouldn't need to create getNextPartitionWriter either.

@mccheah
Copy link

mccheah commented Apr 16, 2019

Ok this looks fine. Please squash and merge into your branch and we'll cherry-pick to our fork. Thanks!

@ifilonenko ifilonenko merged commit 1fe33a9 into shuffle-writer-default-impl Apr 16, 2019
bulldozer-bot bot pushed a commit to palantir/spark that referenced this pull request Apr 17, 2019
mccheah added a commit to palantir/spark that referenced this pull request Jun 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants