From c56044b9eed76f19bb67a76645e3fd2d539cf5a3 Mon Sep 17 00:00:00 2001 From: Colin Patrick Mccabe Date: Wed, 20 Jan 2016 11:26:44 -0800 Subject: [PATCH] HDFS-9576: HTrace: collect position/length information on read operations (zhz via cmccabe) (cherry picked from commit 7905788db94d560e6668af0d4bed22b326961aaf) Conflicts: hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java --- .../org/apache/hadoop/hdfs/DFSClient.java | 19 +++++++++++ .../apache/hadoop/hdfs/DFSInputStream.java | 34 ++++++++++++++----- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java index ef5ec2dc468..17d31c558dd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java @@ -2947,6 +2947,25 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory, return scope; } + /** + * Full detailed tracing for read requests: path, position in the file, + * and length. + * + * @param reqLen requested length + */ + TraceScope newReaderTraceScope(String description, String path, long pos, + int reqLen) { + TraceScope scope = newPathTraceScope(description, path); + scope.addKVAnnotation("pos", Long.toString(pos)); + scope.addKVAnnotation("reqLen", Integer.toString(reqLen)); + return scope; + } + + /** Add the returned length info to the scope. */ + void addRetLenToReaderScope(TraceScope scope, int retLen) { + scope.addKVAnnotation("retLen", Integer.toString(retLen)); + } + Tracer getTracer() { return tracer; } diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java index f4dad121051..520b2161328 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java @@ -974,18 +974,29 @@ public class DFSInputStream extends FSInputStream public synchronized int read(@Nonnull final byte buf[], int off, int len) throws IOException { ReaderStrategy byteArrayReader = new ByteArrayStrategy(buf); - try (TraceScope ignored = - dfsClient.newPathTraceScope("DFSInputStream#byteArrayRead", src)) { - return readWithStrategy(byteArrayReader, off, len); + try (TraceScope scope = + dfsClient.newReaderTraceScope("DFSInputStream#byteArrayRead", + src, getPos(), len)) { + int retLen = readWithStrategy(byteArrayReader, off, len); + if (retLen < len) { + dfsClient.addRetLenToReaderScope(scope, retLen); + } + return retLen; } } @Override public synchronized int read(final ByteBuffer buf) throws IOException { ReaderStrategy byteBufferReader = new ByteBufferStrategy(buf); - try (TraceScope ignored = - dfsClient.newPathTraceScope("DFSInputStream#byteBufferRead", src)){ - return readWithStrategy(byteBufferReader, 0, buf.remaining()); + int reqLen = buf.remaining(); + try (TraceScope scope = + dfsClient.newReaderTraceScope("DFSInputStream#byteBufferRead", + src, getPos(), reqLen)){ + int retLen = readWithStrategy(byteBufferReader, 0, reqLen); + if (retLen < reqLen) { + dfsClient.addRetLenToReaderScope(scope, retLen); + } + return retLen; } } @@ -1461,9 +1472,14 @@ public class DFSInputStream extends FSInputStream @Override public int read(long position, byte[] buffer, int offset, int length) throws IOException { - try (TraceScope ignored = dfsClient. - newPathTraceScope("DFSInputStream#byteArrayPread", src)) { - return pread(position, buffer, offset, length); + try (TraceScope scope = dfsClient. + newReaderTraceScope("DFSInputStream#byteArrayPread", + src, position, length)) { + int retLen = pread(position, buffer, offset, length); + if (retLen < length) { + dfsClient.addRetLenToReaderScope(scope, retLen); + } + return retLen; } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 45449603e8c..83b60a15373 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -42,6 +42,9 @@ Release 2.9.0 - UNRELEASED HDFS-9624. DataNode start slowly due to the initial DU command operations. (Lin Yiqun via wang) + HDFS-9576: HTrace: collect position/length information on read operations + (zhz via cmccabe) + OPTIMIZATIONS BUG FIXES