htrace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmcc...@apache.org
Subject incubator-htrace git commit: HTRACE-359. TraceRunnable and TraceCallable should be built using parent spanId not scope (Mike Drob via cmccabe)
Date Thu, 05 May 2016 17:34:26 GMT
Repository: incubator-htrace
Updated Branches:
  refs/heads/master 4a101e0d1 -> 699ee9918


HTRACE-359. TraceRunnable and TraceCallable should be built using parent spanId not scope
(Mike Drob via cmccabe)


Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/699ee991
Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/699ee991
Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/699ee991

Branch: refs/heads/master
Commit: 699ee9918f18f7f06fcff99f39952dc09e1ab8c7
Parents: 4a101e0
Author: Colin P. Mccabe <cmccabe@apache.org>
Authored: Thu May 5 10:30:45 2016 -0700
Committer: Colin P. Mccabe <cmccabe@apache.org>
Committed: Thu May 5 10:30:45 2016 -0700

----------------------------------------------------------------------
 .../org/apache/htrace/core/TraceCallable.java   |  8 +++----
 .../org/apache/htrace/core/TraceRunnable.java   | 15 ++++++++++---
 .../java/org/apache/htrace/core/Tracer.java     |  2 +-
 .../apache/htrace/core/TestTraceExecutor.java   | 22 ++++++++++++++++++++
 4 files changed, 39 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/699ee991/htrace-core4/src/main/java/org/apache/htrace/core/TraceCallable.java
----------------------------------------------------------------------
diff --git a/htrace-core4/src/main/java/org/apache/htrace/core/TraceCallable.java b/htrace-core4/src/main/java/org/apache/htrace/core/TraceCallable.java
index 9cf478d..2318552 100644
--- a/htrace-core4/src/main/java/org/apache/htrace/core/TraceCallable.java
+++ b/htrace-core4/src/main/java/org/apache/htrace/core/TraceCallable.java
@@ -24,14 +24,14 @@ import java.util.concurrent.Callable;
 public class TraceCallable<V> implements Callable<V> {
   private final Tracer tracer;
   private final Callable<V> impl;
-  private final TraceScope parent;
+  private final SpanId parentId;
   private final String description;
 
-  TraceCallable(Tracer tracer, TraceScope parent, Callable<V> impl,
+  public TraceCallable(Tracer tracer, SpanId parentId, Callable<V> impl,
       String description) {
     this.tracer = tracer;
     this.impl = impl;
-    this.parent = parent;
+    this.parentId = parentId;
     this.description = description;
   }
 
@@ -41,7 +41,7 @@ public class TraceCallable<V> implements Callable<V> {
     if (description == null) {
       description = Thread.currentThread().getName();
     }
-    try (TraceScope chunk = tracer.newScope(description, parent.getSpan().getSpanId())) {
+    try (TraceScope chunk = tracer.newScope(description, parentId)) {
       return impl.call();
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/699ee991/htrace-core4/src/main/java/org/apache/htrace/core/TraceRunnable.java
----------------------------------------------------------------------
diff --git a/htrace-core4/src/main/java/org/apache/htrace/core/TraceRunnable.java b/htrace-core4/src/main/java/org/apache/htrace/core/TraceRunnable.java
index f2db5c2..ad5b36a 100644
--- a/htrace-core4/src/main/java/org/apache/htrace/core/TraceRunnable.java
+++ b/htrace-core4/src/main/java/org/apache/htrace/core/TraceRunnable.java
@@ -21,14 +21,23 @@ package org.apache.htrace.core;
  */
 public class TraceRunnable implements Runnable {
   private final Tracer tracer;
-  private final TraceScope parent;
+  private final SpanId parentId;
   private final Runnable runnable;
   private final String description;
 
+  /**
+   * @deprecated Use {@link #TraceRunnable(Tracer, SpanId, Runnable, String)} instead.
+   */
+  @Deprecated
   public TraceRunnable(Tracer tracer, TraceScope parent,
       Runnable runnable, String description) {
+    this(tracer, parent.getSpanId(), runnable, description);
+  }
+
+  public TraceRunnable(Tracer tracer, SpanId parentId,
+      Runnable runnable, String description) {
     this.tracer = tracer;
-    this.parent = parent;
+    this.parentId = parentId;
     this.runnable = runnable;
     this.description = description;
   }
@@ -39,7 +48,7 @@ public class TraceRunnable implements Runnable {
     if (description == null) {
       description = Thread.currentThread().getName();
     }
-    try (TraceScope chunk = tracer.newScope(description, parent.getSpan().getSpanId())) {
+    try (TraceScope chunk = tracer.newScope(description, parentId)) {
       runnable.run();
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/699ee991/htrace-core4/src/main/java/org/apache/htrace/core/Tracer.java
----------------------------------------------------------------------
diff --git a/htrace-core4/src/main/java/org/apache/htrace/core/Tracer.java b/htrace-core4/src/main/java/org/apache/htrace/core/Tracer.java
index a04c9b9..f78e0a0 100644
--- a/htrace-core4/src/main/java/org/apache/htrace/core/Tracer.java
+++ b/htrace-core4/src/main/java/org/apache/htrace/core/Tracer.java
@@ -446,7 +446,7 @@ public class Tracer implements Closeable {
     if (parentScope == null) {
       return callable;
     }
-    return new TraceCallable<V>(this, parentScope, callable, description);
+    return new TraceCallable<V>(this, parentScope.getSpanId(), callable, description);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/699ee991/htrace-core4/src/test/java/org/apache/htrace/core/TestTraceExecutor.java
----------------------------------------------------------------------
diff --git a/htrace-core4/src/test/java/org/apache/htrace/core/TestTraceExecutor.java b/htrace-core4/src/test/java/org/apache/htrace/core/TestTraceExecutor.java
index bf98a1a..dbdd27c 100644
--- a/htrace-core4/src/test/java/org/apache/htrace/core/TestTraceExecutor.java
+++ b/htrace-core4/src/test/java/org/apache/htrace/core/TestTraceExecutor.java
@@ -66,6 +66,28 @@ public class TestTraceExecutor {
     }
   }
 
+  @Test
+  public void testWrappingFromSpan() throws Exception {
+    HTraceConfiguration conf = HTraceConfiguration.fromKeyValuePairs("sampler.classes", "AlwaysSampler");
+
+    ExecutorService es = Executors.newSingleThreadExecutor();
+    try (Tracer tracer = new Tracer.Builder("TestTraceExecutor").conf(conf).build()) {
+      SpanId random = SpanId.fromRandom();
+      try (TraceScope parentScope = tracer.newScope("parent")) {
+        Callable<SpanId> callable = new TraceCallable<SpanId>(tracer, random,
new Callable<SpanId>() {
+          @Override
+          public SpanId call() throws Exception {
+            return Tracer.getCurrentSpan().getParents()[0];
+          }
+        }, "child");
+        SpanId result = es.submit(callable).get(WAIT_TIME_SECONDS, TimeUnit.SECONDS);
+        assertEquals(random, result);
+      }
+    } finally {
+      es.shutdown();
+    }
+  }
+
   /*
    * Inspired by org.apache.solr.util.DefaultSolrThreadFactory
    */


Mime
View raw message