Skip to content

Commit a941ad4

Browse files
committed
wip
1 parent d0c3974 commit a941ad4

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

src/ra_log.erl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,14 +859,20 @@ handle_event({segments, TidRanges, NewSegs},
859859
end,
860860
{State, [{bg_work, Fun, fun (_Err) -> ok end}]};
861861
handle_event({compaction_result, Result},
862-
#?MODULE{reader = Reader0} = State) ->
862+
#?MODULE{cfg = #cfg{log_id = LogId},
863+
reader = Reader0} = State) ->
864+
?DEBUG("~ts: compaction result ~p", [LogId, Result]),
863865
{Reader, Effs} = ra_log_segments:handle_compaction_result(Result, Reader0),
864866
{State#?MODULE{reader = Reader}, Effs};
865-
handle_event(major_compaction, #?MODULE{reader = Reader0,
867+
handle_event(major_compaction, #?MODULE{cfg = #cfg{log_id = LogId},
868+
reader = Reader0,
866869
live_indexes = LiveIndexes,
867870
snapshot_state = SS} = State) ->
868871
case ra_snapshot:current(SS) of
869872
{SnapIdx, _} ->
873+
?DEBUG("~ts: ra_log: major_compaction requested at snapshot index ~b, "
874+
"~b live indexes",
875+
[LogId, SnapIdx, ra_seq:length(LiveIndexes)]),
870876
{Reader, Effs} = ra_log_segments:schedule_compaction(major, SnapIdx,
871877
LiveIndexes, Reader0),
872878
{State#?MODULE{reader = Reader}, Effs};
@@ -1159,6 +1165,7 @@ assert(#?MODULE{cfg = #cfg{log_id = LogId},
11591165
current_snapshot = CurrSnap,
11601166
live_indexes = LiveIndexes
11611167
} = State) ->
1168+
ra_log_segments:range/1
11621169
%% TODO: remove this at some point?
11631170
?DEBUG("~ts: ra_log: asserting Range ~p Snapshot ~p",
11641171
[LogId, Range, CurrSnap]),

src/ra_mt.erl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ info(#?MODULE{tid = Tid,
390390
size => ets:info(Tid, size),
391391
name => ets:info(Tid, name),
392392
range => range(State),
393+
previous => case Prev of
394+
undefined ->
395+
undefined;
396+
_ ->
397+
info(Prev)
398+
end,
393399
has_previous => Prev =/= undefined
394400
}.
395401

src/ra_server.erl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,17 +1640,18 @@ handle_receive_snapshot(#install_snapshot_rpc{term = Term,
16401640
OldMeta,
16411641
OldMacState),
16421642
State1 = update_term(Term,
1643-
State0#{cfg => Cfg,
1644-
log => Log,
1645-
commit_index => SnapIndex,
1646-
last_applied => SnapIndex,
1647-
%% this may not be the actual cluster index
1648-
cluster_index_term => {SnapIndex,
1649-
SnapTerm},
1650-
cluster => make_cluster(Id, ClusterIds),
1651-
membership =>
1652-
get_membership(ClusterIds, State0),
1653-
machine_state => MacState}),
1643+
State0#{cfg => Cfg,
1644+
log => Log,
1645+
commit_index => SnapIndex,
1646+
last_applied => SnapIndex,
1647+
%% this may not be the actual
1648+
%% cluster index
1649+
cluster_index_term => {SnapIndex,
1650+
SnapTerm},
1651+
cluster => make_cluster(Id, ClusterIds),
1652+
membership =>
1653+
get_membership(ClusterIds, State0),
1654+
machine_state => MacState}),
16541655
State = maps:remove(snapshot_phase, State1),
16551656
put_counter(Cfg, ?C_RA_SVR_METRIC_LAST_APPLIED, SnapIndex),
16561657
%% it was the last snapshot chunk so we can revert back to

test/ra_log_2_SUITE.erl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,6 @@ snapshot_installation_with_live_indexes(Config) ->
13621362
LW = ra_log:last_written(L),
13631363
{9, 2} == LW
13641364
end),
1365-
13661365
Log2 = Log1,
13671366

13681367
%% create snapshot chunk
@@ -1373,10 +1372,10 @@ snapshot_installation_with_live_indexes(Config) ->
13731372
Machine = {machine, ?MODULE, #{}},
13741373

13751374
%% write a sparse one
1375+
{ok, Log2b} = ra_log:write_sparse({14, 2, <<>>}, 9, Log2),
13761376
{SnapState, _, LiveIndexes, AEffs} = ra_snapshot:complete_accept(Chunk, 1, Machine,
13771377
SnapState1),
13781378
run_effs(AEffs),
1379-
{ok, Log2b} = ra_log:write_sparse({14, 2, <<>>}, 9, Log2),
13801379
{ok, Log3, Effs4} = ra_log:install_snapshot({15, 2}, ?MODULE, LiveIndexes,
13811380
ra_log:set_snapshot_state(SnapState, Log2b)),
13821381

@@ -1388,12 +1387,20 @@ snapshot_installation_with_live_indexes(Config) ->
13881387
%% write the next index, bearning in mind the last index the WAL saw
13891388
%% was 14
13901389
{ok, Log4} = ra_log:write([{16, 2, <<>>}], Log3),
1391-
Log = assert_log_events(Log4,
1392-
fun (L) ->
1393-
LW = ra_log:last_written(L),
1394-
{16, 2} == LW
1395-
end),
1390+
Log5 = assert_log_events(Log4,
1391+
fun (L) ->
1392+
LW = ra_log:last_written(L),
1393+
{16, 2} == LW
1394+
end),
1395+
ct:pal("o ~p", [ra_log:overview(Log5)]),
1396+
ra_log_wal:force_roll_over(ra_log_wal),
1397+
Log = assert_log_events(Log5,
1398+
fun (L) ->
1399+
#{mem_table_range := R} = ra_log:overview(L),
1400+
R == undefined
1401+
end),
13961402
ct:pal("o ~p", [ra_log:overview(Log)]),
1403+
flush(),
13971404
ok.
13981405

13991406
snapshot_installation(Config) ->

test/ra_server_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ follower_installs_snapshot_with_pre(_Config) ->
23122312

23132313
%% now send a pre message
23142314
ISRpcPre = ISRpcInit#install_snapshot_rpc{chunk_state = {0, pre},
2315-
data = [{2, 1, <<"e1">>}]},
2315+
data = [{2, 1, <<"e1">>}]},
23162316
{receive_snapshot, State3, [{reply, _}]} =
23172317
ra_server:handle_receive_snapshot(ISRpcPre, State2),
23182318

0 commit comments

Comments
 (0)