Skip to content

Commit

Permalink
HBASE-27762 Include EventType and ProcedureV2 pid in logging via MDC (#…
Browse files Browse the repository at this point in the history
…5145)

Signed-off-by: Duo Zhang <[email protected]>
  • Loading branch information
ndimiduk committed May 1, 2023
1 parent b50022d commit 07bdc09
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hbase-logging/src/test/resources/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ appender.console.target = SYSTEM_ERR
appender.console.name = Console
appender.console.maxSize = 1G
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{ISO8601} %-5p [%t] %C{2}(%L): %m%n
appender.console.layout.pattern = %d{ISO8601} %-5p [%t (%X)] %C{2}(%L): %m%n

rootLogger = INFO,Console

Expand Down
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

0 comments on commit 07bdc09

Please sign in to comment.