From f36da00c1f67f68ee7ef17cbfd2ed74bb70ade4f Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Thu, 15 Jun 2017 14:15:36 +0900 Subject: [PATCH] HDFS-11583. Parent spans are not initialized to NullScope for every DFSPacket. Contributed by Masatake Iwasaki. --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../apache/hadoop/hdfs/DFSOutputStream.java | 2 ++ .../apache/hadoop/tracing/TestTracing.java | 35 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 06776005e9f..b8ac822f1a7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -355,6 +355,9 @@ Release 2.7.4 - UNRELEASED HDFS-11736. OIV tests should not write outside 'target' directory. (Yiqun Lin via aajisaka) + HDFS-11583. Parent spans are not initialized to NullScope for every + DFSPacket. (Masatake Iwasaki via aajisaka) + Release 2.7.3 - 2016-08-25 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java index 1289b302268..f26b8837472 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSOutputStream.java @@ -674,6 +674,7 @@ public class DFSOutputStream extends FSOutputSummer } } finally { scope.close(); + scope = NullScope.INSTANCE; } } closeInternal(); @@ -945,6 +946,7 @@ public class DFSOutputStream extends FSOutputSummer } } finally { scope.close(); + scope = NullScope.INSTANCE; } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tracing/TestTracing.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tracing/TestTracing.java index 348c87d77bc..f33e82f5868 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tracing/TestTracing.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/tracing/TestTracing.java @@ -68,6 +68,41 @@ public class TestTracing { readWithTracing(); } + @Test + public void testTracingInDataStreamer() throws Exception { + DistributedFileSystem fs = cluster.getFileSystem(); + FSDataOutputStream os = fs.create(new Path("/testTracingInDataStreamer")); + byte[] bytes = "foo-bar-baz".getBytes(); + + try (TraceScope ts = Trace.startSpan("top level", Sampler.ALWAYS)) { + os.write(bytes); + os.hflush(); + } + assertSpanNamesFound(new String[]{ "writeTo" }); + int spans1 = 0; + for (Span s : SetSpanReceiver.SetHolder.spans.values()) { + if (s.getDescription().equals("writeTo")) { + spans1++; + } + } + Assert.assertEquals(1, spans1); + + os.write(bytes); + os.hflush(); + os.close(); + + int spans2 = 0; + for (Span s : SetSpanReceiver.SetHolder.spans.values()) { + if (s.getDescription().equals("writeTo")) { + spans2++; + } + } + + // If there are multiple "writeTo" spans, + // spans are started in DataStreamer even after "top level" span is closed. + Assert.assertEquals(spans1, spans2); + } + public void writeWithTracing() throws Exception { long startTime = System.currentTimeMillis(); TraceScope ts = Trace.startSpan("testWriteTraceHooks", Sampler.ALWAYS);