From ef3d8b5f6b3f789a9504b60cbe928cb6f83c9647 Mon Sep 17 00:00:00 2001 From: jbewing Date: Tue, 28 Jan 2025 15:14:03 -0500 Subject: [PATCH] HBASE-29099 Avoid expensive BlockCacheKey.toString() calls when tracing is disabled (#6642) Signed-off-by: Ray Mattingly --- .../org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java index ace662414f40..b6a061043070 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.java @@ -1291,13 +1291,17 @@ public HFileBlock readBlock(long dataBlockOffset, long onDiskBlockSize, final bo BlockCacheKey cacheKey = new BlockCacheKey(path, dataBlockOffset, this.isPrimaryReplicaReader(), expectedBlockType); - Attributes attributes = Attributes.of(BLOCK_CACHE_KEY_KEY, cacheKey.toString()); boolean cacheable = cacheBlock && cacheIfCompactionsOff(); boolean useLock = false; IdLock.Entry lockEntry = null; final Span span = Span.current(); + // BlockCacheKey#toString() is quite expensive to call, so if tracing isn't enabled, don't + // record + Attributes attributes = span.isRecording() + ? Attributes.of(BLOCK_CACHE_KEY_KEY, cacheKey.toString()) + : Attributes.empty(); try { while (true) { // Check cache for block. If found return.