nickva commented on code in PR #5150:
URL: https://github.com/apache/couchdb/pull/5150#discussion_r1688998931
##########
src/rexi/src/rexi_buffer.erl:
##########
@@ -18,55 +18,76 @@
init/1,
handle_call/3,
handle_cast/2,
- handle_info/2
+ handle_info/2,
+ terminate/2
]).
-export([
send/2,
- start_link/1
+ start_link/1,
+ get_buffered_count/1,
+ erase_buffer/1
]).
+-define(BUFFER_COUNT_DEFAULT, 2000).
+-define(COUNTER, counter).
+
-record(state, {
+ server_id,
buffer = queue:new(),
sender = nil,
count = 0,
+ counter,
max_count
}).
start_link(ServerId) ->
- gen_server:start_link({local, ServerId}, ?MODULE, nil, []).
+ gen_server:start_link({local, ServerId}, ?MODULE, [ServerId], []).
send(Dest, Msg) ->
Server = list_to_atom(lists:concat([rexi_buffer, "_", get_node(Dest)])),
gen_server:cast(Server, {deliver, Dest, Msg}).
-init(_) ->
+get_buffered_count(ServerId) when is_atom(ServerId) ->
+ case persistent_term:get(counter_key(ServerId), undefined) of
+ undefined -> 0;
+ Ref -> counters:get(Ref, 1)
+ end.
+
+erase_buffer(ServerId) ->
+ gen_server:call(ServerId, erase_buffer, infinity).
+
+init([ServerId]) ->
%% TODO Leverage os_mon to discover available memory in the system
- Max = list_to_integer(config:get("rexi", "buffer_count", "2000")),
- {ok, #state{max_count = Max}}.
+ Counter = counters:new(1, []),
+ persistent_term:put(counter_key(ServerId), Counter),
+ Max = config:get_integer("rexi", "buffer_count", ?BUFFER_COUNT_DEFAULT),
Review Comment:
Yeah, agree, I would have called with something having `max` or `limit` in
it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]