Skip to content

Commit 3d7bd1e

Browse files
authored
HBASE-26130 Backport HBASE-25455 "Add trace support for HRegion read/… (#3594)
7/17 commits of HBASE-22120, original commit 03e12bf Co-authored-by: Duo Zhang <[email protected]> Signed-off-by: Duo Zhang <[email protected]>
1 parent a618459 commit 3d7bd1e

File tree

9 files changed

+393
-138
lines changed

9 files changed

+393
-138
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ private <T> CompletableFuture<T> tracedLocationFuture(Supplier<CompletableFuture
102102
CompletableFuture<T> future = action.get();
103103
FutureUtils.addListener(future, (resp, error) -> {
104104
if (error != null) {
105-
span.recordException(error);
106-
span.setStatus(StatusCode.ERROR);
105+
TraceUtil.setError(span, error);
107106
} else {
108107
List<String> regionNames = getRegionNames.apply(resp);
109108
if (!regionNames.isEmpty()) {

hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/AbstractRpcClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,7 @@ public void run(Call call) {
424424
onCallFinished(call, hrc, addr, callback);
425425
} finally {
426426
if (hrc.failed()) {
427-
span.setStatus(StatusCode.ERROR);
428-
span.recordException(hrc.getFailed());
427+
TraceUtil.setError(span, hrc.getFailed());
429428
} else {
430429
span.setStatus(StatusCode.OK);
431430
}

hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
2727
import io.opentelemetry.context.Context;
2828
import io.opentelemetry.context.Scope;
29+
import java.io.IOException;
2930
import java.util.List;
3031
import java.util.concurrent.CompletableFuture;
3132
import java.util.function.Supplier;
@@ -58,6 +59,9 @@ public final class TraceUtil {
5859

5960
public static final AttributeKey<Long> REMOTE_PORT_KEY = SemanticAttributes.NET_PEER_PORT;
6061

62+
public static final AttributeKey<Boolean> ROW_LOCK_READ_LOCK_KEY =
63+
AttributeKey.booleanKey("db.hbase.rowlock.readlock");
64+
6165
private TraceUtil() {
6266
}
6367

@@ -139,14 +143,18 @@ public static <T> List<CompletableFuture<T>> tracedFutures(
139143
}
140144
}
141145

146+
public static void setError(Span span, Throwable error) {
147+
span.recordException(error);
148+
span.setStatus(StatusCode.ERROR);
149+
}
150+
142151
/**
143152
* Finish the {@code span} when the given {@code future} is completed.
144153
*/
145154
private static void endSpan(CompletableFuture<?> future, Span span) {
146155
FutureUtils.addListener(future, (resp, error) -> {
147156
if (error != null) {
148-
span.recordException(error);
149-
span.setStatus(StatusCode.ERROR);
157+
setError(span, error);
150158
} else {
151159
span.setStatus(StatusCode.OK);
152160
}
@@ -164,8 +172,32 @@ public static void trace(Runnable action, Supplier<Span> creator) {
164172
action.run();
165173
span.setStatus(StatusCode.OK);
166174
} catch (Throwable e) {
167-
span.recordException(e);
168-
span.setStatus(StatusCode.ERROR);
175+
setError(span, e);
176+
throw e;
177+
} finally {
178+
span.end();
179+
}
180+
}
181+
182+
@FunctionalInterface
183+
public interface IOExceptionCallable<V> {
184+
V call() throws IOException;
185+
}
186+
187+
public static <T> T trace(IOExceptionCallable<T> callable, String spanName) throws IOException {
188+
return trace(callable, () -> createSpan(spanName));
189+
}
190+
191+
public static <T> T trace(IOExceptionCallable<T> callable, Supplier<Span> creator)
192+
throws IOException {
193+
Span span = creator.get();
194+
try (Scope scope = span.makeCurrent()) {
195+
T ret = callable.call();
196+
span.setStatus(StatusCode.OK);
197+
return ret;
198+
} catch (Throwable e) {
199+
setError(span, e);
200+
throw e;
169201
} finally {
170202
span.end();
171203
}

hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/CallRunner.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,10 @@ public void run() {
136136
resultPair = this.rpcServer.call(call, this.status);
137137
} catch (TimeoutIOException e){
138138
RpcServer.LOG.warn("Can not complete this request in time, drop it: " + call);
139-
span.recordException(e);
140-
span.setStatus(StatusCode.ERROR);
139+
TraceUtil.setError(span, e);
141140
return;
142141
} catch (Throwable e) {
143-
span.recordException(e);
144-
span.setStatus(StatusCode.ERROR);
142+
TraceUtil.setError(span, e);
145143
if (e instanceof ServerNotRunningYetException) {
146144
// If ServerNotRunningYetException, don't spew stack trace.
147145
if (RpcServer.LOG.isTraceEnabled()) {

hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerCall.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.hadoop.hbase.io.ByteBufferListOutputStream;
3434
import org.apache.hadoop.hbase.ipc.RpcServer.CallCleanup;
3535
import org.apache.hadoop.hbase.security.User;
36+
import org.apache.hadoop.hbase.trace.TraceUtil;
3637
import org.apache.hadoop.hbase.util.ByteBufferUtils;
3738
import org.apache.hadoop.hbase.util.Bytes;
3839
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
@@ -232,8 +233,7 @@ public synchronized void setResponse(Message m, final CellScanner cells, Throwab
232233
}
233234
if (t != null) {
234235
this.isError = true;
235-
span.recordException(t);
236-
span.setStatus(StatusCode.ERROR);
236+
TraceUtil.setError(span, t);
237237
} else {
238238
span.setStatus(StatusCode.OK);
239239
}

0 commit comments

Comments
 (0)