-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HADOOP-15327. Upgrade MR ShuffleHandler to use Netty4 #3259. Contribu…
…ted by Szilard Nemeth.
- Loading branch information
1 parent
552ee44
commit 5bb11ce
Showing
11 changed files
with
1,602 additions
and
571 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
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
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
106 changes: 106 additions & 0 deletions
106
...uce-client-shuffle/src/main/java/org/apache/hadoop/mapred/LoggingHttpResponseEncoder.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,106 @@ | ||
/* | ||
* 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.hadoop.mapred; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelPromise; | ||
import io.netty.handler.codec.http.HttpHeaders; | ||
import io.netty.handler.codec.http.HttpResponse; | ||
import io.netty.handler.codec.http.HttpResponseEncoder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
class LoggingHttpResponseEncoder extends HttpResponseEncoder { | ||
private static final Logger LOG = LoggerFactory.getLogger(LoggingHttpResponseEncoder.class); | ||
private final boolean logStacktraceOfEncodingMethods; | ||
|
||
LoggingHttpResponseEncoder(boolean logStacktraceOfEncodingMethods) { | ||
this.logStacktraceOfEncodingMethods = logStacktraceOfEncodingMethods; | ||
} | ||
|
||
@Override | ||
public boolean acceptOutboundMessage(Object msg) throws Exception { | ||
printExecutingMethod(); | ||
LOG.info("OUTBOUND MESSAGE: " + msg); | ||
return super.acceptOutboundMessage(msg); | ||
} | ||
|
||
@Override | ||
protected void encodeInitialLine(ByteBuf buf, HttpResponse response) throws Exception { | ||
LOG.debug("Executing method: {}, response: {}", | ||
getExecutingMethodName(), response); | ||
logStacktraceIfRequired(); | ||
super.encodeInitialLine(buf, response); | ||
} | ||
|
||
@Override | ||
protected void encode(ChannelHandlerContext ctx, Object msg, | ||
List<Object> out) throws Exception { | ||
LOG.debug("Encoding to channel {}: {}", ctx.channel(), msg); | ||
printExecutingMethod(); | ||
logStacktraceIfRequired(); | ||
super.encode(ctx, msg, out); | ||
} | ||
|
||
@Override | ||
protected void encodeHeaders(HttpHeaders headers, ByteBuf buf) { | ||
printExecutingMethod(); | ||
super.encodeHeaders(headers, buf); | ||
} | ||
|
||
@Override | ||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise | ||
promise) throws Exception { | ||
LOG.debug("Writing to channel {}: {}", ctx.channel(), msg); | ||
printExecutingMethod(); | ||
super.write(ctx, msg, promise); | ||
} | ||
|
||
private void logStacktraceIfRequired() { | ||
if (logStacktraceOfEncodingMethods) { | ||
LOG.debug("Stacktrace: ", new Throwable()); | ||
} | ||
} | ||
|
||
private void printExecutingMethod() { | ||
String methodName = getExecutingMethodName(1); | ||
LOG.debug("Executing method: {}", methodName); | ||
} | ||
|
||
private String getExecutingMethodName() { | ||
return getExecutingMethodName(0); | ||
} | ||
|
||
private String getExecutingMethodName(int additionalSkipFrames) { | ||
try { | ||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); | ||
// Array items (indices): | ||
// 0: java.lang.Thread.getStackTrace(...) | ||
// 1: TestShuffleHandler$LoggingHttpResponseEncoder.getExecutingMethodName(...) | ||
int skipFrames = 2 + additionalSkipFrames; | ||
String methodName = stackTrace[skipFrames].getMethodName(); | ||
String className = this.getClass().getSimpleName(); | ||
return className + "#" + methodName; | ||
} catch (Throwable t) { | ||
LOG.error("Error while getting execution method name", t); | ||
return "unknown"; | ||
} | ||
} | ||
} |
Oops, something went wrong.