Browse Source

HDFS-11583. Parent spans are not initialized to NullScope for every DFSPacket. Contributed by Masatake Iwasaki.

Akira Ajisaka 8 years ago
parent
commit
f36da00c1f

+ 3 - 0
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

+ 2 - 0
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;
           }
         }
       }

+ 35 - 0
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);