Navigation Menu

Skip to content

Commit

Permalink
Report watchers to the log
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 23, 2015
1 parent cd849cb commit 1951c71
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 86 deletions.
8 changes: 3 additions & 5 deletions lib/droonga/command/droonga_engine.rb
Expand Up @@ -758,19 +758,17 @@ def initialize(loop)
def start
logger.trace("start: stert")
@async_watcher = Coolio::AsyncWatcher.new
on_signal = lambda do
@async_watcher.on_signal do
commands = @commands.uniq
@commands.clear
until commands.empty?
command = commands.shift
@on_command.call(command) if @on_command
end
end
@async_watcher.on_signal do
on_signal.call
end
@loop.attach(@async_watcher)
# logger.trace("start: new watcher attached", :watcher => @async_watcher)
logger.trace("start: async watcher attached",
:watcher => @async_watcher)
logger.trace("start: done")
end

Expand Down
12 changes: 6 additions & 6 deletions lib/droonga/file_observer.rb
Expand Up @@ -47,16 +47,16 @@ def start
end
end
@loop.attach(@timer)
# logger.trace("start: new file watcher attached",
# :watcher => @timer,
# :path => @path)
logger.trace("start: timer attached",
:watcher => @timer,
:path => @path)
end

def stop
@timer.detach if @timer
# logger.trace("stop: file watcher detached",
# :watcher => @timer,
# :path => @path)
logger.trace("stop: timer detached",
:watcher => @timer,
:path => @path)
@timer = nil
end

Expand Down
24 changes: 12 additions & 12 deletions lib/droonga/fluent_message_receiver.rb
Expand Up @@ -114,10 +114,10 @@ def start_server
@clients << client
end
@loop.attach(@server)
# logger.trace("start_server: new server watcher attached",
# :watcher => @server,
# :listen_fd => @listen_fd,
# :heartbeat_fd => @heartbeat_fd)
logger.trace("start_server: server watcher attached",
:watcher => @server,
:listen_fd => @listen_fd,
:heartbeat_fd => @heartbeat_fd)

logger.trace("start_server: done")
end
Expand All @@ -129,8 +129,8 @@ def create_server(&block)
def shutdown_server
logger.trace("shutdown_server: start")
@server.close
# logger.trace("shutdown_server: server watcher detached",
# :watcher => @server)
logger.trace("shutdown_server: server watcher detached",
:watcher => @server)
logger.trace("shutdown_server: done")
end

Expand All @@ -154,17 +154,17 @@ def start
receive_heartbeat
end
@loop.attach(@watcher)
# logger.trace("start: new heartbeat watcher attached",
# :watcher => @watcher,
# :fd => @fd)
logger.trace("start: heartbeat IO watcher attached",
:watcher => @watcher,
:fd => @fd)
end

def shutdown
@socket.close
@watcher.detach
# logger.trace("shutdown: heartbeat watcher detached",
# :watcher => @watcher,
# :fd => @fd)
logger.trace("shutdown: heartbeat watcher detached",
:watcher => @watcher,
:fd => @fd)
end

private
Expand Down
10 changes: 5 additions & 5 deletions lib/droonga/job_pusher.rb
Expand Up @@ -37,16 +37,16 @@ def start
end
FileUtils.chmod(0600, @socket_path)
@loop.attach(@server)
# logger.trace("connect: new server watcher attached",
# :watcher => @socket,
# :socket_path => @socket_path)
logger.trace("connect: socket watcher attached",
:watcher => @socket,
:socket_path => @socket_path)
end

def close
return unless @server
@server.close
# logger.trace("close: server watcher detached",
# :watcher => @socket)
logger.trace("close: socket watcher detached",
:watcher => @socket)
end

def shutdown
Expand Down
10 changes: 5 additions & 5 deletions lib/droonga/job_receiver.rb
Expand Up @@ -33,17 +33,17 @@ def start
@receiver = Coolio::UNIXSocket.connect(@socket_path)
setup_receive_handler(@receiver)
@loop.attach(@receiver)
# logger.trace("start: new receiver watcher attached",
# :watcher => @receiver,
# :socket_path => @socket_path)
logger.trace("start: socket watcher attached",
:watcher => @receiver,
:socket_path => @socket_path)
logger.trace("start: done")
end

def shutdown
logger.trace("shutdown: start")
@receiver.close
# logger.trace("shutdown: receiver watcher attached",
# :watcher => @receiver)
logger.trace("shutdown: socket watcher attached",
:watcher => @receiver)
logger.trace("shutdown: done")
end

Expand Down
11 changes: 6 additions & 5 deletions lib/droonga/plugins/dump.rb
Expand Up @@ -89,20 +89,21 @@ def start
runner.resume
rescue
timer.detach
# logger.trace("start: watcher detached on unexpected exception",
# :watcher => timer)
logger.trace("start: timer detached by unexpected exception",
:watcher => timer)
logger.exception(error_message, $!)
error(error_name, error_message)
end
else
timer.detach
# logger.trace("start: watcher detached on unexpected exception",
# :watcher => timer)
logger.trace("start: timer detached by unexpected exception",
:watcher => timer)
logger.exception(error_message, $!)
end
end

@loop.attach(timer)
logger.trace("start: new watcher attached",
logger.trace("start: timer attached",
:watcher => timer)
end

Expand Down
9 changes: 5 additions & 4 deletions lib/droonga/plugins/system/absorb_data.rb
Expand Up @@ -177,15 +177,16 @@ def ensure_completely_restored(&block)
runner.resume
rescue
timer.detach
# logger.trace("start: watcher detached on unexpected exception",
# :watcher => timer)
logger.trace("start: timer detached on unexpected exception",
:watcher => timer)
logger.exception(error_message, $!)
error(error_name, error_message)
end
else
timer.detach
# logger.trace("start: watcher detached on unexpected exception",
# :watcher => timer)
logger.trace("start: timer detached on unexpected exception",
:watcher => timer)
logger.exception(error_message, $!)
end
end
@loop.attach(timer)
Expand Down
16 changes: 8 additions & 8 deletions lib/droonga/process_supervisor.rb
Expand Up @@ -36,20 +36,20 @@ def initialize(loop, input, output)

def start
@loop.attach(@input)
# logger.trace("start: new input watcher attached",
# :watcher => @input)
logger.trace("start: input watcher attached",
:watcher => @input)
@loop.attach(@output)
# logger.trace("start: new output watcher attached",
# :watcher => @output)
logger.trace("start: output watcher attached",
:watcher => @output)
end

def stop
@input.close
# logger.trace("start: input watcher detached",
# :watcher => @input)
logger.trace("stop: input watcher detached",
:watcher => @input)
@output.close
# logger.trace("start: output watcher detached",
# :watcher => @output)
logger.trace("stop: output watcher detached",
:watcher => @output)
end

def stop_gracefully
Expand Down
31 changes: 11 additions & 20 deletions lib/droonga/serf/agent.rb
Expand Up @@ -195,42 +195,33 @@ def start_ready_check

checker = Coolio::TCPSocket.connect(@host, @bind_port)

on_connect = lambda do
checker.on_connect do
on_ready
checker.close
# logger.trace("start_ready_check: checker watcher detached",
# :watcher => checker)
end
checker.on_connect do
on_connect.call
logger.trace("start_ready_check: socket detached",
:watcher => scoket)
end

on_connect_failed = lambda do
checker.on_connect_failed do
if @n_ready_checks >= MAX_N_READ_CHECKS
on_failure
else
timer = Coolio::TimerWatcher.new(1)
on_timer = lambda do
timer.on_timer do
start_ready_check
timer.detach
# logger.trace("start_ready_check: timer watcher detached",
# :watcher => timer)
end
timer.on_timer do
on_timer.call
logger.trace("start_ready_check: timer detached",
:watcher => timer)
end
@loop.attach(timer)
# logger.trace("start_ready_check: new timer watcher attached",
# :watcher => timer)
logger.trace("start_ready_check: timer attached",
:watcher => timer)
end
end
checker.on_connect_failed do
on_connect_failed.call
end

@loop.attach(checker)
# logger.trace("start_ready_check: new checker watcher attached",
# :watcher => checker)
logger.trace("start_ready_check: socket attached",
:watcher => checker)
end

def log_tag
Expand Down
23 changes: 7 additions & 16 deletions lib/droonga/worker_process_agent.rb
Expand Up @@ -48,15 +48,15 @@ def stop
output.write(Messages::FINISH)
output.on_write_complete do
output.close
# logger.trace("stop: output watcher detached",
# :watcher => output)
logger.trace("stop: output detached",
:watcher => output)
end
end
if @input
@input, input = nil, @input
input.close
# logger.trace("stop: input watcher detached",
# :watcher => input)
logger.trace("stop: input detached",
:watcher => input)
end
logger.trace("stop: done")
end
Expand Down Expand Up @@ -84,7 +84,7 @@ def on_refresh_node_reference=(callback)
private
def create_input(raw_input)
@input = Coolio::IO.new(raw_input)
on_read = lambda do |data|
@input.on_read do |data|
line_buffer = LineBuffer.new
line_buffer.feed(data) do |line|
logger.trace("line buffer feeded", :line => line);
Expand All @@ -100,31 +100,22 @@ def create_input(raw_input)
end
end
end
@input.on_read do |data|
on_read.call(data)
end
on_close = lambda do
@input.on_close do
if @input
@input = nil
on_stop_immediately
end
end
@input.on_close do
on_close.call
end
end

def create_output(raw_output)
@output = Coolio::IO.new(raw_output)
on_close = lambda do
@output.on_close do
if @output
@output = nil
on_stop_immediately
end
end
@output.on_close do
on_close.call
end
end

def on_stop_gracefully
Expand Down

0 comments on commit 1951c71

Please sign in to comment.