class Cassandra::Execution::Trace

Constants

SELECT_EVENTS

@private

SELECT_SESSION

@private

Attributes

id[R]

@return [Cassandra::Uuid] trace id

Public Class Methods

new(id, client, load_balancing_policy) click to toggle source

@private

   # File lib/cassandra/execution/trace.rb
56 def initialize(id, client, load_balancing_policy)
57   @id            = id
58   @client        = client
59   @coordinator   = nil
60   @duration      = nil
61   @parameters    = nil
62   @request       = nil
63   @started_at    = nil
64   @events        = nil
65   @client_ip     = nil
66   @loaded        = false
67   @loaded_events = false
68   @load_balancing_policy = load_balancing_policy
69 
70   mon_initialize
71 end

Public Instance Methods

client() click to toggle source

Returns the ip of the client node, the node that ran the driver instance that started tracing.

@return [IPAddr, nil] ip of the client node running the driver

   # File lib/cassandra/execution/trace.rb
87 def client
88   load unless @loaded
89 
90   @client_ip
91 end
coordinator() click to toggle source

Returns the ip of coordinator node. Typically the same as {Cassandra::Execution::Info#hosts}`.last`

@return [IPAddr] ip of the coordinator node

   # File lib/cassandra/execution/trace.rb
77 def coordinator
78   load unless @loaded
79 
80   @coordinator
81 end
duration() click to toggle source
   # File lib/cassandra/execution/trace.rb
93 def duration
94   load unless @loaded
95 
96   @duration
97 end
events() click to toggle source

Returns all trace events

@return [Array<Cassandra::Execution::Trace::Event>] events

    # File lib/cassandra/execution/trace.rb
120 def events
121   load_events unless @loaded_events
122 
123   @events
124 end
inspect() click to toggle source

@private

    # File lib/cassandra/execution/trace.rb
127 def inspect
128   "#<#{self.class.name}:0x#{object_id.to_s(16)} @id=#{@id.inspect}>"
129 end
parameters() click to toggle source
    # File lib/cassandra/execution/trace.rb
 99 def parameters
100   load unless @loaded
101 
102   @parameters
103 end
request() click to toggle source
    # File lib/cassandra/execution/trace.rb
105 def request
106   load unless @loaded
107 
108   @request
109 end
started_at() click to toggle source
    # File lib/cassandra/execution/trace.rb
111 def started_at
112   load unless @loaded
113 
114   @started_at
115 end

Private Instance Methods

load() click to toggle source

@private

    # File lib/cassandra/execution/trace.rb
139 def load
140   synchronize do
141     return if @loaded
142 
143     attempt = 1
144     data    = @client.query(Statements::Simple.new(SELECT_SESSION % @id),
145                             VOID_OPTIONS.override(load_balancing_policy: @load_balancing_policy)).get.first
146 
147     while data.nil? && attempt <= 5
148       sleep(attempt * 0.4)
149       data = @client.query(Statements::Simple.new(SELECT_SESSION % @id),
150                            VOID_OPTIONS.override(load_balancing_policy: @load_balancing_policy)).get.first
151       break if data
152       attempt += 1
153     end
154 
155     raise ::RuntimeError, "unable to load trace #{@id}" if data.nil?
156 
157     @coordinator = data['coordinator']
158     @duration    = data['duration']
159     @parameters  = data['parameters']
160     @request     = data['request']
161     @started_at  = data['started_at']
162     @client_ip   = data['client']
163     @loaded      = true
164   end
165 
166   nil
167 end
load_events() click to toggle source

@private

    # File lib/cassandra/execution/trace.rb
170 def load_events
171   synchronize do
172     return if @loaded_events
173 
174     @events = []
175 
176     @client.query(Statements::Simple.new(SELECT_EVENTS % @id),
177                   VOID_OPTIONS.override(load_balancing_policy: @load_balancing_policy)).get.each do |row|
178       @events << Event.new(row['event_id'],
179                            row['activity'],
180                            row['source'],
181                            row['source_elapsed'],
182                            row['thread'])
183     end
184 
185     @events.freeze
186 
187     @loaded_events = true
188   end
189 end