cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject cassandra git commit: Bring consistency to TraceKeyspace
Date Fri, 19 Dec 2014 19:09:16 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk f45a1941c -> c0e3f66d6


Bring consistency to TraceKeyspace


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

Branch: refs/heads/trunk
Commit: c0e3f66d60a77abec11afc8464abbcc7680139a1
Parents: f45a194
Author: Aleksey Yeschenko <aleksey@apache.org>
Authored: Fri Dec 19 22:08:41 2014 +0300
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Fri Dec 19 22:08:57 2014 +0300

----------------------------------------------------------------------
 .../org/apache/cassandra/db/SystemKeyspace.java |  3 +-
 .../cassandra/service/StorageService.java       |  2 +-
 .../apache/cassandra/tracing/TraceKeyspace.java | 65 ++++++++++----------
 .../apache/cassandra/tracing/TraceState.java    |  2 +-
 .../org/apache/cassandra/tracing/Tracing.java   |  5 +-
 5 files changed, 37 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c0e3f66d/src/java/org/apache/cassandra/db/SystemKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java b/src/java/org/apache/cassandra/db/SystemKeyspace.java
index 503dd7f..f492c39 100644
--- a/src/java/org/apache/cassandra/db/SystemKeyspace.java
+++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java
@@ -214,7 +214,8 @@ public final class SystemKeyspace
 
     private static CFMetaData compile(String name, String description, String schema)
     {
-        return CFMetaData.compile(String.format(schema, name), NAME).comment(description);
+        return CFMetaData.compile(String.format(schema, name), NAME)
+                         .comment(description);
     }
 
     public static KSMetaData definition()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c0e3f66d/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index 4d176e6..391f890 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -2641,7 +2641,7 @@ public class StorageService extends NotificationBroadcasterSupport implements
IE
                     throw new Exception("no tracestate");
 
                 String format = "select event_id, source, activity from %s.%s where session_id
= ? and event_id > ? and event_id < ?;";
-                String query = String.format(format, TraceKeyspace.NAME, TraceKeyspace.EVENTS_TABLE);
+                String query = String.format(format, TraceKeyspace.NAME, TraceKeyspace.EVENTS);
                 SelectStatement statement = (SelectStatement) QueryProcessor.parseStatement(query).prepare().statement;
 
                 ByteBuffer sessionIdBytes = ByteBufferUtil.bytes(sessionId);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c0e3f66d/src/java/org/apache/cassandra/tracing/TraceKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tracing/TraceKeyspace.java b/src/java/org/apache/cassandra/tracing/TraceKeyspace.java
index 72a7c47..8c13a81 100644
--- a/src/java/org/apache/cassandra/tracing/TraceKeyspace.java
+++ b/src/java/org/apache/cassandra/tracing/TraceKeyspace.java
@@ -39,13 +39,12 @@ public final class TraceKeyspace
 {
     public static final String NAME = "system_traces";
 
-    public static final String SESSIONS_TABLE = "sessions";
-    public static final String EVENTS_TABLE = "events";
+    public static final String SESSIONS = "sessions";
+    public static final String EVENTS = "events";
 
-    private static final int DAY = (int) TimeUnit.DAYS.toSeconds(1);
-
-    private static final CFMetaData SessionsTable =
-        compile(SESSIONS_TABLE, "tracing sessions",
+    private static final CFMetaData Sessions =
+        compile(SESSIONS,
+                "tracing sessions",
                 "CREATE TABLE %s ("
                 + "session_id uuid,"
                 + "command text,"
@@ -54,11 +53,11 @@ public final class TraceKeyspace
                 + "parameters map<text, text>,"
                 + "request text,"
                 + "started_at timestamp,"
-                + "PRIMARY KEY ((session_id)))")
-                .defaultTimeToLive(DAY);
+                + "PRIMARY KEY ((session_id)))");
 
-    private static final CFMetaData EventsTable =
-        compile(EVENTS_TABLE, "tracing events",
+    private static final CFMetaData Events =
+        compile(EVENTS,
+                "tracing events",
                 "CREATE TABLE %s ("
                 + "session_id uuid,"
                 + "event_id timeuuid,"
@@ -66,61 +65,59 @@ public final class TraceKeyspace
                 + "source inet,"
                 + "source_elapsed int,"
                 + "thread text,"
-                + "PRIMARY KEY ((session_id), event_id))")
-                .defaultTimeToLive(DAY);
+                + "PRIMARY KEY ((session_id), event_id))");
 
-    private static CFMetaData compile(String table, String comment, String cql)
+    private static CFMetaData compile(String name, String description, String schema)
     {
-        return CFMetaData.compile(String.format(cql, table), NAME).comment(comment);
+        return CFMetaData.compile(String.format(schema, name), NAME)
+                         .comment(description)
+                         .defaultTimeToLive((int) TimeUnit.DAYS.toSeconds(1));
     }
 
     public static KSMetaData definition()
     {
-        List<CFMetaData> tables = Arrays.asList(SessionsTable, EventsTable);
+        List<CFMetaData> tables = Arrays.asList(Sessions, Events);
         return new KSMetaData(NAME, SimpleStrategy.class, ImmutableMap.of("replication_factor",
"2"), true, tables);
     }
 
-    static Mutation toStopSessionMutation(ByteBuffer sessionId, int elapsed, int ttl)
+    static Mutation makeStartSessionMutation(ByteBuffer sessionId, Map<String, String>
parameters, String request, long startedAt, String command, int ttl)
     {
         Mutation mutation = new Mutation(NAME, sessionId);
-        ColumnFamily cells = mutation.addOrGet(SessionsTable);
+        ColumnFamily cells = mutation.addOrGet(TraceKeyspace.Sessions);
 
-        ttl = ttl == DAY ? 0 : ttl;
         CFRowAdder adder = new CFRowAdder(cells, cells.metadata().comparator.builder().build(),
FBUtilities.timestampMicros(), ttl);
-        adder.add("duration", elapsed);
+        adder.add("coordinator", FBUtilities.getBroadcastAddress())
+             .add("request", request)
+             .add("started_at", new Date(startedAt))
+             .add("command", command);
+        for (Map.Entry<String, String> entry : parameters.entrySet())
+            adder.addMapEntry("parameters", entry.getKey(), entry.getValue());
 
         return mutation;
     }
 
-    static Mutation toStartSessionMutation(ByteBuffer sessionId, Map<String, String>
parameters, String request, long startedAt, String command, int ttl)
+    static Mutation makeStopSessionMutation(ByteBuffer sessionId, int elapsed, int ttl)
     {
         Mutation mutation = new Mutation(NAME, sessionId);
-        ColumnFamily cells = mutation.addOrGet(TraceKeyspace.SessionsTable);
+        ColumnFamily cells = mutation.addOrGet(Sessions);
 
-        ttl = ttl == DAY ? 0 : ttl;
         CFRowAdder adder = new CFRowAdder(cells, cells.metadata().comparator.builder().build(),
FBUtilities.timestampMicros(), ttl);
-        adder.add("coordinator", FBUtilities.getBroadcastAddress());
-        for (Map.Entry<String, String> entry : parameters.entrySet())
-            adder.addMapEntry("parameters", entry.getKey(), entry.getValue());
-        adder.add("request", request);
-        adder.add("started_at", new Date(startedAt));
-        adder.add("command", command);
+        adder.add("duration", elapsed);
 
         return mutation;
     }
 
-    static Mutation toEventMutation(ByteBuffer sessionId, String message, int elapsed, String
threadName, int ttl)
+    static Mutation makeEventMutation(ByteBuffer sessionId, String message, int elapsed,
String threadName, int ttl)
     {
         Mutation mutation = new Mutation(NAME, sessionId);
-        ColumnFamily cells = mutation.addOrGet(EventsTable);
+        ColumnFamily cells = mutation.addOrGet(Events);
 
-        ttl = ttl == DAY ? 0 : ttl;
         CFRowAdder adder = new CFRowAdder(cells, cells.metadata().comparator.make(UUIDGen.getTimeUUID()),
FBUtilities.timestampMicros(), ttl);
-        adder.add("activity", message);
-        adder.add("source", FBUtilities.getBroadcastAddress());
+        adder.add("activity", message)
+             .add("source", FBUtilities.getBroadcastAddress())
+             .add("thread", threadName);
         if (elapsed >= 0)
             adder.add("source_elapsed", elapsed);
-        adder.add("thread", threadName);
 
         return mutation;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c0e3f66d/src/java/org/apache/cassandra/tracing/TraceState.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tracing/TraceState.java b/src/java/org/apache/cassandra/tracing/TraceState.java
index f7d2741..c67ad3e 100644
--- a/src/java/org/apache/cassandra/tracing/TraceState.java
+++ b/src/java/org/apache/cassandra/tracing/TraceState.java
@@ -172,7 +172,7 @@ public class TraceState
         {
             public void runMayThrow()
             {
-                Tracing.mutateWithCatch(TraceKeyspace.toEventMutation(sessionId, message,
elapsed, threadName, ttl));
+                Tracing.mutateWithCatch(TraceKeyspace.makeEventMutation(sessionId, message,
elapsed, threadName, ttl));
             }
         });
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c0e3f66d/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 5e76957..d0f496e 100644
--- a/src/java/org/apache/cassandra/tracing/Tracing.java
+++ b/src/java/org/apache/cassandra/tracing/Tracing.java
@@ -53,7 +53,6 @@ public class Tracing
 {
     public static final String TRACE_HEADER = "TraceSession";
     public static final String TRACE_TYPE = "TraceType";
-    public static final String TRACE_TTL = "TraceTTL";
 
     public enum TraceType
     {
@@ -173,7 +172,7 @@ public class Tracing
             {
                 public void run()
                 {
-                    mutateWithCatch(TraceKeyspace.toStopSessionMutation(sessionId, elapsed,
ttl));
+                    mutateWithCatch(TraceKeyspace.makeStopSessionMutation(sessionId, elapsed,
ttl));
                 }
             });
 
@@ -212,7 +211,7 @@ public class Tracing
         {
             public void run()
             {
-                mutateWithCatch(TraceKeyspace.toStartSessionMutation(sessionId, parameters,
request, startedAt, command, ttl));
+                mutateWithCatch(TraceKeyspace.makeStartSessionMutation(sessionId, parameters,
request, startedAt, command, ttl));
             }
         });
 


Mime
View raw message