@@ -223,6 +223,8 @@ init(#{uid := UId,
223223 % this queries the segment writer and thus blocks until any
224224 % segments it is currently processed have been finished
225225 MtRange = ra_mt :range (Mt0 ),
226+ % % TODO: init ra_log_reader here instead and let it take care of range
227+ % % calulation and segref compaction
226228 {{FirstIdx , LastIdx0 }, SegRefs } = case recover_ranges (UId , MtRange , SegWriter ) of
227229 {undefined , SRs } ->
228230 {{- 1 , - 1 }, SRs };
@@ -938,31 +940,30 @@ install_snapshot({SnapIdx, SnapTerm} = IdxTerm, MacMod, LiveIndexes,
938940 put_counter (Cfg , ? C_RA_SVR_METRIC_LAST_INDEX , SnapIdx ),
939941 put_counter (Cfg , ? C_RA_SVR_METRIC_LAST_WRITTEN_INDEX , SnapIdx ),
940942
941- CompEffs = schedule_compaction (SnapIdx , State0 ),
942-
943943 {SnapState , Checkpoints } =
944944 ra_snapshot :take_older_checkpoints (SnapIdx , SnapState0 ),
945945 CPEffects = [{delete_snapshot ,
946946 ra_snapshot :directory (SnapState , checkpoint ),
947947 Checkpoint } || Checkpoint <- Checkpoints ],
948- State = State0 #? MODULE {snapshot_state = SnapState ,
949- first_index = SnapIdx + 1 ,
950- last_index = SnapIdx ,
951- last_term = SnapTerm ,
952- last_written_index_term = IdxTerm },
953- % % TODO: more mt entries could potentially be cleared up in the
954- % % mem table here
955948 SmallestLiveIndex = case ra_seq :first (LiveIndexes ) of
956949 undefined ->
957950 SnapIdx + 1 ;
958951 I ->
959952 I
960953 end ,
954+ % % TODO: more mt entries could potentially be cleared up in the
955+ % % mem table here
961956 {Spec , Mt } = ra_mt :set_first (SmallestLiveIndex , Mt0 ),
962957 ok = exec_mem_table_delete (Names , UId , Spec ),
963- {ok , State #? MODULE {live_indexes = LiveIndexes ,
964- mem_table = Mt },
965- CompEffs ++ CPEffects }.
958+ State = State0 #? MODULE {snapshot_state = SnapState ,
959+ first_index = SnapIdx + 1 ,
960+ last_index = SnapIdx ,
961+ last_term = SnapTerm ,
962+ live_indexes = LiveIndexes ,
963+ mem_table = Mt ,
964+ last_written_index_term = IdxTerm },
965+ CompEffs = schedule_compaction (SnapIdx , State ),
966+ {ok , State , CompEffs ++ CPEffects }.
966967
967968
968969- spec recover_snapshot (State :: state ()) ->
@@ -1261,6 +1262,9 @@ schedule_compaction(SnapIdx, #?MODULE{cfg = #cfg{},
12611262 end , lists :reverse (Compactable )),
12621263 SnapDir = ra_snapshot :current_snapshot_dir (SnapState ),
12631264
1265+ % % TODO: minor compactions should also delete / truncate
1266+ % % segments with completely overwritten indexes
1267+
12641268 Self = self (),
12651269 Fun = fun () ->
12661270 {ok , Indexes } = ra_snapshot :indexes (SnapDir ),
0 commit comments