diff options
| author | Tim Fox <tim@rabbitmq.com> | 2011-02-10 16:32:03 +0000 |
|---|---|---|
| committer | Tim Fox <tim@rabbitmq.com> | 2011-02-10 16:32:03 +0000 |
| commit | 4c2afec2ee1a8b858017543b0531bc759b9e39e2 (patch) | |
| tree | 3ff06336d5ae42c1ed4cecee33f78672acc8211a | |
| parent | 0aa1f7e5b8c6eafca9ed19acf9b729403066625a (diff) | |
| download | rabbitmq-server-git-4c2afec2ee1a8b858017543b0531bc759b9e39e2.tar.gz | |
Added code to raise or clear alarm "file_descriptor_limit" when transitions between
being able to obtain file descriptors (e.g. for sockets) or not, and vice versa, occur.
Method adjust_alarm contains the logic to set/clear alarm based on previous and new state.
| -rw-r--r-- | src/file_handle_cache.erl | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/src/file_handle_cache.erl b/src/file_handle_cache.erl index 1e1f37cb3d..a1b8efc1f5 100644 --- a/src/file_handle_cache.erl +++ b/src/file_handle_cache.erl @@ -869,13 +869,13 @@ handle_call({obtain, Pid}, From, State = #fhc_state { obtain_count = Count, {noreply, reduce(State #fhc_state { obtain_pending = pending_in(Item, Pending) })}; false -> - {noreply, run_pending_item(Item, State)} + {noreply, adjust_alarm(State, run_pending_item(Item, State))} end; handle_call({set_limit, Limit}, _From, State) -> {reply, ok, maybe_reduce( - process_pending(State #fhc_state { + adjust_alarm(State, process_pending(State #fhc_state { limit = Limit, - obtain_limit = obtain_limit(Limit) }))}; + obtain_limit = obtain_limit(Limit) })))}; handle_call(get_limit, _From, State = #fhc_state { limit = Limit }) -> {reply, Limit, State}. @@ -900,9 +900,9 @@ handle_cast({close, Pid, EldestUnusedSince}, _ -> dict:store(Pid, EldestUnusedSince, Elders) end, ets:update_counter(Clients, Pid, {#cstate.pending_closes, -1, 0, 0}), - {noreply, process_pending( + {noreply, adjust_alarm(State, process_pending( update_counts(open, Pid, -1, - State #fhc_state { elders = Elders1 }))}; + State #fhc_state { elders = Elders1 })))}; handle_cast({transfer, FromPid, ToPid}, State) -> ok = track_client(ToPid, State#fhc_state.clients), @@ -924,13 +924,15 @@ handle_info({'DOWN', _MRef, process, Pid, _Reason}, ets:lookup(Clients, Pid), true = ets:delete(Clients, Pid), FilterFun = fun (#pending { pid = Pid1 }) -> Pid1 =/= Pid end, - {noreply, process_pending( - State #fhc_state { - open_count = OpenCount - Opened, - open_pending = filter_pending(FilterFun, OpenPending), - obtain_count = ObtainCount - Obtained, - obtain_pending = filter_pending(FilterFun, ObtainPending), - elders = dict:erase(Pid, Elders) })}. + {noreply, adjust_alarm( + State, + process_pending( + State #fhc_state { + open_count = OpenCount - Opened, + open_pending = filter_pending(FilterFun, OpenPending), + obtain_count = ObtainCount - Obtained, + obtain_pending = filter_pending(FilterFun, ObtainPending), + elders = dict:erase(Pid, Elders) }))}. terminate(_Reason, State = #fhc_state { clients = Clients }) -> ets:delete(Clients), @@ -990,6 +992,18 @@ obtain_limit(Limit) -> case ?OBTAIN_LIMIT(Limit) of OLimit -> OLimit end. +obtain_limit_reached(#fhc_state { obtain_limit = Limit, + obtain_count = Count}) -> + Limit =/= infinity andalso Count >= Limit. + +adjust_alarm(OldState, NewState) -> + case {obtain_limit_reached(OldState), obtain_limit_reached(NewState)} of + {false, true} -> alarm_handler:set_alarm({file_descriptor_limit, []}); + {true, false} -> alarm_handler:clear_alarm(file_descriptor_limit); + _ -> ok + end, + NewState. + requested({_Kind, _Pid, Requested, _From}) -> Requested. |
