summaryrefslogtreecommitdiff
path: root/src/fsyncport.erl
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2014-10-24 15:32:58 +0200
committerMagnus Ahltorp <map@kth.se>2014-10-24 15:36:36 +0200
commitb968cb1330ecb13f26e35d948c0511882b89ab2a (patch)
treeeecbb90a07b7b932d0c957ee04d8b0c57e15fb19 /src/fsyncport.erl
parent729c7410504252d7c33e8fd2f43e662725186960 (diff)
Added lager for logging
Diffstat (limited to 'src/fsyncport.erl')
-rw-r--r--src/fsyncport.erl7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/fsyncport.erl b/src/fsyncport.erl
index 7e2bf11..5084fdd 100644
--- a/src/fsyncport.erl
+++ b/src/fsyncport.erl
@@ -22,11 +22,13 @@ call_port(Msg) ->
end.
init(ExtPrg) ->
+ lager:debug("starting fsync service"),
register(fsyncport, self()),
process_flag(trap_exit, true),
Ports = lists:map(fun(_N) -> open_port({spawn_executable, ExtPrg},
[{packet, 2}]) end,
lists:seq(1, 32)),
+ lager:debug("fsync service started", []),
loop(Ports).
loop(Ports) ->
@@ -34,12 +36,14 @@ loop(Ports) ->
loop(IdlePorts, BusyPorts, Waiting) ->
receive
{call, Caller, {fsync, Path}} ->
+ lager:debug("fsync incoming request: ~p", [Path]),
case IdlePorts of
[] ->
loop(IdlePorts,
BusyPorts,
queue:in({Caller, Path}, Waiting));
[Port | Rest] ->
+ lager:debug("fsync port ~p assigned to request ~p", [Port, Path]),
Port ! {self(), {command, Path}},
loop(Rest,
dict:store(Port, {Caller, os:timestamp()}, BusyPorts),
@@ -47,6 +51,7 @@ loop(IdlePorts, BusyPorts, Waiting) ->
end;
{Port, {data, Data}} when is_port(Port) ->
+ lager:debug("fsync request finished: ~p", [Port]),
{Caller, Starttime} = dict:fetch(Port, BusyPorts),
Stoptime = os:timestamp(),
statreport({fsync, Stoptime, Starttime}),
@@ -65,6 +70,7 @@ loop(IdlePorts, BusyPorts, Waiting) ->
NewWaiting)
end;
stop ->
+ lager:debug("fsync stop request received"),
lists:foreach(fun (Port) ->
Port ! {self(), close}
end,
@@ -78,6 +84,7 @@ loop(IdlePorts, BusyPorts, Waiting) ->
exit(normal) %% XXX exits when first port is closed
end;
{'EXIT', Port, _Reason} when is_port(Port) ->
+ lager:debug("fsync port ~p exited, exiting", [Port]),
%% XXX supervisor doesn't restart fsyncport, why?
exit(port_terminated)
end.