Skip to content

Commit e1b8dcb

Browse files
Merge pull request #265 from EasyPost:log_in_protocol
pass through logger to CqlProtocolHandler; log information about heartbeats; send heartbeats even if one fails Co-authored-by: Danilo Caballero Chinchilla <[email protected]>
1 parent 8fdcfd2 commit e1b8dcb

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/cassandra/cluster/connector.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ def do_connect(host)
126126
@connection_options.nodelay? ? 1 : 0)
127127

128128
Protocol::CqlProtocolHandler.new(connection,
129+
host,
129130
@reactor,
131+
@logger,
130132
@connection_options.protocol_version,
131133
@connection_options.compressor,
132134
@connection_options.heartbeat_interval,

lib/cassandra/protocol/cql_protocol_handler.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class CqlProtocolHandler
4141
attr_reader :protocol_version
4242

4343
def initialize(connection,
44+
host,
4445
scheduler,
46+
logger,
4547
protocol_version,
4648
compressor = nil,
4749
heartbeat_interval = 30,
@@ -50,10 +52,12 @@ def initialize(connection,
5052
custom_type_handlers = {})
5153
@protocol_version = protocol_version
5254
@connection = connection
55+
@host = host
5356
@scheduler = scheduler
5457
@compressor = compressor
5558
@connection.on_data(&method(:receive_data))
5659
@connection.on_closed(&method(:socket_closed))
60+
@logger = logger
5761

5862
@streams = Array.new(requests_per_connection) {|i| i}
5963

@@ -414,7 +418,8 @@ def schedule_heartbeat
414418
end
415419

416420
timer.on_value do
417-
send_request(HEARTBEAT, nil, false).on_value do
421+
@logger.debug("sending heartbeat to #{@host}")
422+
send_request(HEARTBEAT, nil, false).on_complete do
418423
schedule_heartbeat
419424
end
420425
end
@@ -432,6 +437,7 @@ def reschedule_termination
432437
end
433438

434439
timer.on_value do
440+
@logger.info("#{@host} has had no activity in the last #{@idle_timeout}s; marking as failed")
435441
@terminate = nil
436442
@connection.close(TERMINATED)
437443
end

spec/cassandra/protocol/cql_protocol_handler_spec.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
module Cassandra
2323
module Protocol
2424
describe CqlProtocolHandler do
25+
let :host do
26+
'example.com'
27+
end
28+
let :logger do
29+
Cassandra::NullLogger.new
30+
end
2531
let :protocol_handler do
26-
described_class.new(connection, scheduler, 1, nil, 30, 60, 36)
32+
described_class.new(connection, host, scheduler, 1, logger, nil, 30, 60, 36)
2733
end
2834

2935
let :connection do
@@ -52,6 +58,8 @@ module Protocol
5258
connection.stub(:on_connected) do |&h|
5359
connection.stub(:connected_listener).and_return(h)
5460
end
61+
connection.stub(:host).and_return(host)
62+
5563
protocol_handler
5664
end
5765

@@ -87,7 +95,6 @@ module Protocol
8795

8896
describe '#host' do
8997
it 'delegates to the connection' do
90-
connection.stub(:host).and_return('example.com')
9198
protocol_handler.host.should == 'example.com'
9299
end
93100
end
@@ -175,7 +182,7 @@ module Protocol
175182

176183
context 'when a compressor is specified' do
177184
let :protocol_handler do
178-
described_class.new(connection, scheduler, 1, compressor)
185+
described_class.new(connection, host, scheduler, 1, logger, compressor)
179186
end
180187

181188
let :compressor do
@@ -215,7 +222,7 @@ module Protocol
215222

216223
context 'when a protocol version is specified' do
217224
let :protocol_handler do
218-
described_class.new(connection, scheduler, 7)
225+
described_class.new(connection, host, scheduler, 7, logger)
219226
end
220227

221228
it 'sets the protocol version in the header' do

0 commit comments

Comments
 (0)