You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2020/01/22 18:18:48 UTC
[cassandra] branch trunk updated: Make it easier to add trace
headers to messages
This is an automated email from the ASF dual-hosted git repository.
aleksey pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 0e3a906 Make it easier to add trace headers to messages
0e3a906 is described below
commit 0e3a90698a94772e57df39e7461efe6b7e09d678
Author: yifan-c <yc...@gmail.com>
AuthorDate: Sun Jan 12 13:55:54 2020 -0800
Make it easier to add trace headers to messages
patch by Yifan Cai; reviewed by David Capwell for CASSANDRA-15499
---
CHANGES.txt | 1 +
src/java/org/apache/cassandra/net/Message.java | 12 +++++++++
.../unit/org/apache/cassandra/net/MessageTest.java | 31 ++++++++++++++++++++++
3 files changed, 44 insertions(+)
diff --git a/CHANGES.txt b/CHANGES.txt
index 1860e63..85ddd53 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
4.0-alpha3
+ * Make it easier to add trace headers to messages (CASSANDRA-15499)
* Fix and optimise partial compressed sstable streaming (CASSANDRA-13938)
* Improve error when JVM 11 can't access required modules (CASSANDRA-15468)
* Better handling of file deletion failures by DiskFailurePolicy (CASSANDRA-15143)
diff --git a/src/java/org/apache/cassandra/net/Message.java b/src/java/org/apache/cassandra/net/Message.java
index 05c1bfa..0eb7710 100644
--- a/src/java/org/apache/cassandra/net/Message.java
+++ b/src/java/org/apache/cassandra/net/Message.java
@@ -461,6 +461,18 @@ public class Message<T>
return this;
}
+ /**
+ * A shortcut to add tracing params.
+ * Effectively, it is the same as calling {@link #withParam(ParamType, Object)} with tracing params
+ * If there is already tracing params, calling this method overrides any existing ones.
+ */
+ public Builder<T> withTracingParams()
+ {
+ if (Tracing.isTracing())
+ Tracing.instance.addTraceHeaders(params);
+ return this;
+ }
+
public Builder<T> withoutParam(ParamType type)
{
params.remove(type);
diff --git a/test/unit/org/apache/cassandra/net/MessageTest.java b/test/unit/org/apache/cassandra/net/MessageTest.java
index 78eb4c0..6a9d23f 100644
--- a/test/unit/org/apache/cassandra/net/MessageTest.java
+++ b/test/unit/org/apache/cassandra/net/MessageTest.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -34,8 +35,10 @@ import org.apache.cassandra.io.util.DataInputPlus;
import org.apache.cassandra.io.util.DataOutputBuffer;
import org.apache.cassandra.io.util.DataOutputPlus;
import org.apache.cassandra.locator.InetAddressAndPort;
+import org.apache.cassandra.tracing.Tracing;
import org.apache.cassandra.tracing.Tracing.TraceType;
import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.UUIDGen;
import static org.apache.cassandra.net.Message.serializer;
import static org.apache.cassandra.net.MessagingService.VERSION_3014;
@@ -195,6 +198,34 @@ public class MessageTest
testCycle(msg);
}
+ @Test
+ public void testBuilderAddTraceHeaderWhenTraceSessionPresent()
+ {
+ Stream.of(TraceType.values()).forEach(this::testAddTraceHeaderWithType);
+ }
+
+ @Test
+ public void testBuilderNotAddTraceHeaderWithNoTraceSession()
+ {
+ Message<NoPayload> msg = Message.builder(Verb._TEST_1, noPayload).withTracingParams().build();
+ assertNull(msg.header.traceSession());
+ }
+
+ private void testAddTraceHeaderWithType(TraceType traceType)
+ {
+ try
+ {
+ UUID sessionId = Tracing.instance.newSession(traceType);
+ Message<NoPayload> msg = Message.builder(Verb._TEST_1, noPayload).withTracingParams().build();
+ assertEquals(sessionId, msg.header.traceSession());
+ assertEquals(traceType, msg.header.traceType());
+ }
+ finally
+ {
+ Tracing.instance.stopSession();
+ }
+ }
+
private void testCycle(Message msg) throws IOException
{
testCycle(msg, VERSION_30);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org