Skip to content

Commit 6940b57

Browse files
committed
fix badkey
1 parent 3418318 commit 6940b57

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

src/ra_seq.erl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@ floor(FloorIdxIncl, Seq) when is_list(Seq) ->
7171

7272

7373
-spec limit(ra:index(), state()) -> state().
74-
limit(CeilIdx, [Last | Rem])
74+
limit(CeilIdxIncl, [Last | Rem])
7575
when is_integer(Last) andalso
76-
Last > CeilIdx ->
77-
limit(CeilIdx, Rem);
78-
limit(CeilIdx, [{_, _} = T | Rem]) ->
79-
case ra_range:limit(CeilIdx + 1, T) of
76+
Last > CeilIdxIncl ->
77+
limit(CeilIdxIncl, Rem);
78+
limit(CeilIdxIncl, [{_, _} = T | Rem]) ->
79+
case ra_range:limit(CeilIdxIncl + 1, T) of
8080
undefined ->
81-
limit(CeilIdx, Rem);
81+
limit(CeilIdxIncl, Rem);
8282
{I, I} ->
8383
[I | Rem];
8484
{I, I2} when I == I2 - 1 ->
8585
[I2, I | Rem];
8686
NewRange ->
8787
[NewRange | Rem]
8888
end;
89-
limit(_CeilIdx, Seq) ->
89+
limit(_CeilIdxIncl, Seq) ->
9090
Seq.
9191

9292
%% @doc adds two sequences together where To is

src/ra_server_proc.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ do_init(#{id := Id,
329329
true = ets:insert(ra_state, {Key, init, unknown}),
330330
process_flag(trap_exit, true),
331331
Config = #{counter := Counter,
332-
system_config := #{names := Names} = SysConf} = maps:merge(config_defaults(Id),
333-
Config0),
332+
system_config := #{names := Names} = SysConf} =
333+
maps:merge(config_defaults(Id), Config0),
334334
MsgQData = maps:get(message_queue_data, SysConf, off_heap),
335335
MinBinVheapSize = maps:get(server_min_bin_vheap_size, SysConf,
336336
?MIN_BIN_VHEAP_SIZE),

src/ra_snapshot.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,9 @@ complete_accept(Chunk, Num, Machine,
549549
current = IdxTerm},
550550
{ok, #{machine_version := SnapMacVer}, MacState} = recover(State),
551551
SnapMacMod = ra_machine:which_module(Machine, SnapMacVer),
552-
LiveIndexes = ra_machine:live_indexes(SnapMacMod, MacState),
552+
%% TODO: allow the ra machine to return a re_seq instead of a plain list
553+
LiveIndexes = ra_seq:from_list(
554+
ra_machine:live_indexes(SnapMacMod, MacState)),
553555
SnapDir = make_snapshot_dir(Dir, Idx, Term),
554556
ok = write_indexes(SnapDir, LiveIndexes),
555557
%% delete accepting marker file

src/ra_worker.erl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-module(ra_worker).
99
-behaviour(gen_server).
1010

11+
-include("ra.hrl").
1112
-export([start_link/1,
1213
queue_work/3]).
1314

@@ -18,7 +19,8 @@
1819
terminate/2,
1920
code_change/3]).
2021

21-
-record(state, {}).
22+
-record(state, {log_id = "" :: unicode:chardata()
23+
}).
2224

2325
%%% ra worker responsible for doing background work for a ra server.
2426
%%%
@@ -39,9 +41,11 @@ queue_work(Pid, FunOrMfa, ErrFun) when is_pid(Pid) ->
3941
%%% gen_server callbacks
4042
%%%===================================================================
4143

42-
init(Config) when is_map(Config) ->
44+
init(#{id := Id} = Config) when is_map(Config) ->
4345
process_flag(trap_exit, true),
44-
{ok, #state{}}.
46+
LogId = maps:get(friendly_name, Config,
47+
lists:flatten(io_lib:format("~w", [Id]))),
48+
{ok, #state{log_id = LogId}}.
4549

4650
handle_call(_, _From, State) ->
4751
{reply, ok, State}.
@@ -52,17 +56,19 @@ handle_cast({work, FunOrMfa, ErrFun}, State) ->
5256
try erlang:apply(M, F, Args) of
5357
_ ->
5458
ok
55-
catch Type:Err:_Stack ->
56-
%% TODO: log
59+
catch Type:Err:Stack ->
60+
?WARN("~ts: worker encounted error ~0p of type ~s, Stack:~n~p",
61+
[State#state.log_id, Err, Type, Stack]),
5762
ErrFun({Type, Err}),
5863
ok
5964
end;
6065
_ when is_function(FunOrMfa) ->
6166
try FunOrMfa() of
6267
_ ->
6368
ok
64-
catch Type:Err:_Stack ->
65-
%% TODO: log
69+
catch Type:Err:Stack ->
70+
?WARN("~ts: worker encounted error ~0p of type ~s, Stack:~n~p",
71+
[State#state.log_id, Err, Type, Stack]),
6672
ErrFun({Type, Err})
6773
end,
6874
ok

0 commit comments

Comments
 (0)