-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21175] Reject OpenBlocks when memory shortage on shuffle service. #18388
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
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3cc29a7
Shuffle server will close connection when chunks being transferred is…
70aaf9a
remove blank line
7dd2cec
void chunkSent(long streamId)
ef89321
add config to configuration.md
98123ee
streamSent(String streamId);
4de417f
resolve zsxwing's comments.
3a018b1
unit test
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
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
134 changes: 134 additions & 0 deletions
134
...n/network-common/src/test/java/org/apache/spark/network/TransportRequestHandlerSuite.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,134 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import io.netty.channel.Channel; | ||
| import io.netty.channel.ChannelPromise; | ||
| import io.netty.channel.DefaultChannelPromise; | ||
| import io.netty.util.concurrent.Future; | ||
| import io.netty.util.concurrent.GenericFutureListener; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.mockito.Mockito.*; | ||
|
|
||
| import org.apache.commons.lang3.tuple.ImmutablePair; | ||
| import org.apache.commons.lang3.tuple.Pair; | ||
| import org.apache.spark.network.buffer.ManagedBuffer; | ||
| import org.apache.spark.network.client.TransportClient; | ||
| import org.apache.spark.network.protocol.*; | ||
| import org.apache.spark.network.server.NoOpRpcHandler; | ||
| import org.apache.spark.network.server.OneForOneStreamManager; | ||
| import org.apache.spark.network.server.RpcHandler; | ||
| import org.apache.spark.network.server.TransportRequestHandler; | ||
|
|
||
| public class TransportRequestHandlerSuite { | ||
|
|
||
| @Test | ||
| public void handleFetchRequestAndStreamRequest() throws Exception { | ||
| RpcHandler rpcHandler = new NoOpRpcHandler(); | ||
| OneForOneStreamManager streamManager = (OneForOneStreamManager) (rpcHandler.getStreamManager()); | ||
| Channel channel = mock(Channel.class); | ||
| List<Pair<Object, ExtendedChannelPromise>> responseAndPromisePairs = | ||
| new ArrayList<>(); | ||
| when(channel.writeAndFlush(any())) | ||
| .thenAnswer(invocationOnMock0 -> { | ||
| Object response = invocationOnMock0.getArguments()[0]; | ||
| ExtendedChannelPromise channelFuture = new ExtendedChannelPromise(channel); | ||
| responseAndPromisePairs.add(ImmutablePair.of(response, channelFuture)); | ||
| return channelFuture; | ||
| }); | ||
|
|
||
| // Prepare the stream. | ||
| List<ManagedBuffer> managedBuffers = new ArrayList<>(); | ||
| managedBuffers.add(new TestManagedBuffer(10)); | ||
| managedBuffers.add(new TestManagedBuffer(20)); | ||
| managedBuffers.add(new TestManagedBuffer(30)); | ||
| managedBuffers.add(new TestManagedBuffer(40)); | ||
| long streamId = streamManager.registerStream("test-app", managedBuffers.iterator()); | ||
| streamManager.registerChannel(channel, streamId); | ||
| TransportClient reverseClient = mock(TransportClient.class); | ||
| TransportRequestHandler requestHandler = new TransportRequestHandler(channel, reverseClient, | ||
| rpcHandler, 2L); | ||
|
|
||
| RequestMessage request0 = new ChunkFetchRequest(new StreamChunkId(streamId, 0)); | ||
| requestHandler.handle(request0); | ||
| assert responseAndPromisePairs.size() == 1; | ||
| assert responseAndPromisePairs.get(0).getLeft() instanceof ChunkFetchSuccess; | ||
| assert ((ChunkFetchSuccess) (responseAndPromisePairs.get(0).getLeft())).body() == | ||
| managedBuffers.get(0); | ||
|
|
||
| RequestMessage request1 = new ChunkFetchRequest(new StreamChunkId(streamId, 1)); | ||
| requestHandler.handle(request1); | ||
| assert responseAndPromisePairs.size() == 2; | ||
| assert responseAndPromisePairs.get(1).getLeft() instanceof ChunkFetchSuccess; | ||
| assert ((ChunkFetchSuccess) (responseAndPromisePairs.get(1).getLeft())).body() == | ||
| managedBuffers.get(1); | ||
|
|
||
| // Finish flushing the response for request0. | ||
| responseAndPromisePairs.get(0).getRight().finish(true); | ||
|
|
||
| RequestMessage request2 = new StreamRequest(String.format("%d_%d", streamId, 2)); | ||
| requestHandler.handle(request2); | ||
| assert responseAndPromisePairs.size() == 3; | ||
| assert responseAndPromisePairs.get(2).getLeft() instanceof StreamResponse; | ||
| assert ((StreamResponse) (responseAndPromisePairs.get(2).getLeft())).body() == | ||
| managedBuffers.get(2); | ||
|
|
||
| // Request3 will trigger the close of channel, because the number of max chunks being | ||
| // transferred is 2; | ||
| RequestMessage request3 = new StreamRequest(String.format("%d_%d", streamId, 3)); | ||
| requestHandler.handle(request3); | ||
| verify(channel, times(1)).close(); | ||
| assert responseAndPromisePairs.size() == 3; | ||
| } | ||
|
|
||
| private class ExtendedChannelPromise extends DefaultChannelPromise { | ||
|
|
||
| private List<GenericFutureListener> listeners = new ArrayList<>(); | ||
| private boolean success; | ||
|
|
||
| public ExtendedChannelPromise(Channel channel) { | ||
| super(channel); | ||
| success = false; | ||
| } | ||
|
|
||
| @Override | ||
| public ChannelPromise addListener( | ||
| GenericFutureListener<? extends Future<? super Void>> listener) { | ||
| listeners.add(listener); | ||
| return super.addListener(listener); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSuccess() { | ||
| return success; | ||
| } | ||
|
|
||
| public void finish(boolean success) { | ||
| this.success = success; | ||
| listeners.forEach(listener -> { | ||
| try { | ||
| listener.operationComplete(this); | ||
| } catch (Exception e) { } | ||
| }); | ||
| } | ||
| } | ||
| } |
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
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.
I think it makes more sense to have 2 methods:
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.
Yes, it would be much better