|
7 | 7 | %% @hidden
|
8 | 8 | -module(ra_log).
|
9 | 9 |
|
| 10 | +-include_lib("stdlib/include/assert.hrl"). |
10 | 11 | -compile([inline_list_funcs]).
|
11 | 12 |
|
12 | 13 | -export([pre_init/1,
|
|
50 | 51 | delete_everything/1,
|
51 | 52 | release_resources/3,
|
52 | 53 |
|
53 |
| - tick/2 |
| 54 | + tick/2, |
| 55 | + assert/1 |
54 | 56 | ]).
|
55 | 57 |
|
56 | 58 | -include("ra.hrl").
|
@@ -335,8 +337,7 @@ init(#{uid := UId,
|
335 | 337 | {SnapIdx, SnapTerm},
|
336 | 338 | State#?MODULE.last_written_index_term
|
337 | 339 | ]),
|
338 |
| - State. |
339 |
| - % element(1, delete_segments(SnapIdx, State)). |
| 340 | + assert(State). |
340 | 341 |
|
341 | 342 | -spec close(state()) -> ok.
|
342 | 343 | close(#?MODULE{cfg = #cfg{uid = _UId},
|
@@ -1086,6 +1087,26 @@ tick(Now, #?MODULE{cfg = #cfg{wal = Wal},
|
1086 | 1087 | State
|
1087 | 1088 | end.
|
1088 | 1089 |
|
| 1090 | +assert(#?MODULE{cfg = #cfg{log_id = LogId}, |
| 1091 | + range = Range, |
| 1092 | + snapshot_state = SnapState, |
| 1093 | + current_snapshot = CurrSnap, |
| 1094 | + live_indexes = LiveIndexes, |
| 1095 | + mem_table = _Mt |
| 1096 | + } = State) -> |
| 1097 | + %% TODO: remove this at some point? |
| 1098 | + ?DEBUG("~ts: ra_log: asserting Range ~p Snapshot ~p LiveIndexes ~p", |
| 1099 | + [LogId, Range, CurrSnap, LiveIndexes]), |
| 1100 | + %% perform assertions to ensure log state is correct |
| 1101 | + ?assert(CurrSnap =:= ra_snapshot:current(SnapState)), |
| 1102 | + ?assert(Range == undefined orelse |
| 1103 | + CurrSnap == undefined orelse |
| 1104 | + element(1, Range) - 1 == element(1, CurrSnap)), |
| 1105 | + ?assert(CurrSnap == undefined orelse |
| 1106 | + LiveIndexes == [] orelse |
| 1107 | + ra_seq:last(LiveIndexes) =< element(1, CurrSnap)), |
| 1108 | + State. |
| 1109 | + |
1089 | 1110 | suggest_snapshot0(SnapKind, Idx, Cluster, MacModule, MacState, State0) ->
|
1090 | 1111 | case should_snapshot(SnapKind, Idx, State0) of
|
1091 | 1112 | true ->
|
|
0 commit comments