cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [1/2] git commit: use original session stopwatch on callback thread
Date Thu, 25 Oct 2012 14:50:23 GMT
Updated Branches:
  refs/heads/trunk e93eacec7 -> 6adf52c94


use original session stopwatch on callback thread


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ec9af99d
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ec9af99d
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ec9af99d

Branch: refs/heads/trunk
Commit: ec9af99dabe27c67f87d61c2f998771c4f2a2d90
Parents: e93eace
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Wed Oct 24 20:53:30 2012 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Thu Oct 25 09:50:19 2012 -0500

----------------------------------------------------------------------
 src/java/org/apache/cassandra/tracing/Tracing.java |   31 ++++++++------
 1 files changed, 18 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec9af99d/src/java/org/apache/cassandra/tracing/Tracing.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tracing/Tracing.java b/src/java/org/apache/cassandra/tracing/Tracing.java
index 5e6b3d0..c158b10 100644
--- a/src/java/org/apache/cassandra/tracing/Tracing.java
+++ b/src/java/org/apache/cassandra/tracing/Tracing.java
@@ -20,14 +20,15 @@
  */
 package org.apache.cassandra.tracing;
 
-import static com.google.common.base.Preconditions.checkState;
-import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
-
 import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import org.apache.cassandra.concurrent.Stage;
 import org.apache.cassandra.concurrent.StageManager;
@@ -48,8 +49,7 @@ import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
 import org.apache.cassandra.utils.WrappedRunnable;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
 
 /**
  * A trace session context. Able to track and store trace sessions. A session is usually
a user initiated query, and may
@@ -80,6 +80,9 @@ public class Tracing
 
     private final ThreadLocal<TraceState> state = new ThreadLocal<TraceState>();
 
+    /** sessions that were initiated on this node */
+    private final Map<UUID, TraceState> initiatedSessions = new ConcurrentHashMap<UUID,
TraceState>();
+
     public static void addColumn(ColumnFamily cf, ByteBuffer name, Object value)
     {
         cf.addColumn(new ExpiringColumn(name, ByteBufferUtil.bytes(value.toString()), System.currentTimeMillis(),
TTL));
@@ -141,11 +144,6 @@ public class Tracing
         return instance != null && instance.state.get() != null;
     }
 
-    public void reset()
-    {
-        state.set(null);
-    }
-
     public UUID newSession()
     {
         return newSession(TimeUUIDType.instance.compose(ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes())));
@@ -157,6 +155,7 @@ public class Tracing
 
         TraceState ts = new TraceState(localAddress, sessionId);
         state.set(ts);
+        initiatedSessions.put(sessionId, ts);
 
         return sessionId;
     }
@@ -187,7 +186,8 @@ public class Tracing
                 }
             });
 
-            reset();
+            initiatedSessions.remove(state.sessionId);
+            this.state.set(null);
         }
     }
 
@@ -247,7 +247,12 @@ public class Tracing
             return;
         }
 
-        checkState(sessionBytes.length == 16);
-        state.set(new TraceState(message.from, UUIDGen.getUUID(ByteBuffer.wrap(sessionBytes))));
+        assert sessionBytes.length == 16;
+
+        UUID sessionId = UUIDGen.getUUID(ByteBuffer.wrap(sessionBytes));
+        TraceState ts = initiatedSessions.get(sessionId);
+        if (ts == null)
+            ts = new TraceState(message.from, sessionId);
+        state.set(ts);
     }
 }


Mime
View raw message