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

Backport "HBASE-27762 Include EventType and ProcedureV2 pid in logging via MDC (#5145)" to branch-2.5 #5186

Merged
Merged
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 @@ -27,6 +27,7 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

/**
* Abstract base class for all HBase event handlers. Subclasses should implement the
Expand Down Expand Up @@ -96,12 +97,16 @@ public EventHandler prepare() throws Exception {
public void run() {
Span span = TraceUtil.getGlobalTracer().spanBuilder(getClass().getSimpleName())
.setParent(Context.current().with(parent)).startSpan();
// assume that this is the top of an execution on a new or reused thread, that we're safe to
// blast any existing MDC state.
try (Scope scope = span.makeCurrent()) {
MDC.put("event_type", eventType.toString());
process();
} catch (Throwable t) {
handleException(t);
} finally {
span.end();
MDC.clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;

Expand Down Expand Up @@ -93,6 +94,7 @@ private void cleanUpAndReportFailure(IOException error) throws IOException {

@Override
public void process() throws IOException {
MDC.put("pid", Long.toString(openProcId));
HRegionServer rs = getServer();
String encodedName = regionInfo.getEncodedName();
byte[] encodedNameBytes = regionInfo.getEncodedNameAsBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

/**
* A event handler for running procedure.
Expand All @@ -46,6 +47,7 @@ public RSProcedureHandler(HRegionServer rs, long procId, RSProcedureCallable cal
public void process() {
Throwable error = null;
try {
MDC.put("pid", Long.toString(procId));
callable.call();
} catch (Throwable t) {
LOG.error("pid=" + this.procId, t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;

Expand Down Expand Up @@ -78,6 +79,7 @@ private HRegionServer getServer() {

@Override
public void process() throws IOException {
MDC.put("pid", Long.toString(closeProcId));
HRegionServer rs = getServer();
byte[] encodedNameBytes = Bytes.toBytes(encodedName);
Boolean previous = rs.getRegionsInTransitionInRS().putIfAbsent(encodedNameBytes, Boolean.FALSE);
Expand Down