@@ -41,7 +41,8 @@ all_tests() ->
4141 my_segments ,
4242 upgrade_segment_name_format ,
4343 skip_entries_lower_than_snapshot_index ,
44- skip_all_entries_lower_than_snapshot_index
44+ skip_all_entries_lower_than_snapshot_index ,
45+ live_indexes_1
4546 ].
4647
4748groups () ->
@@ -839,6 +840,47 @@ skip_all_entries_lower_than_snapshot_index(Config) ->
839840 ok = gen_server :stop (TblWriterPid ),
840841 ok .
841842
843+ live_indexes_1 (Config ) ->
844+ Dir = ? config (wal_dir , Config ),
845+ UId = ? config (uid , Config ),
846+ {ok , TblWriterPid } = ra_log_segment_writer :start_link (#{system => default ,
847+ name => ? SEGWR ,
848+ data_dir => Dir }),
849+ % first batch
850+ Entries = [{1 , 42 , a },
851+ {2 , 42 , b },
852+ {3 , 43 , c },
853+ {4 , 43 , d },
854+ {5 , 43 , e },
855+ {6 , 43 , f }
856+ ],
857+ Mt = make_mem_table (UId , Entries ),
858+ Ranges = #{UId => [{ra_mt :tid (Mt ), [ra_mt :range (Mt )]}]},
859+ % % update snapshot state table
860+ ra_log_snapshot_state :insert (ra_log_snapshot_state , UId , 4 , 2 , [4 , 2 ]),
861+ ok = ra_log_segment_writer :accept_mem_tables (? SEGWR , Ranges ,
862+ make_wal (Config , " w1.wal" )),
863+ receive
864+ {ra_log_event , {segments , _Tid , [{Fn , {2 , 6 }}]}} ->
865+ SegmentFile = filename :join (? config (server_dir , Config ), Fn ),
866+ {ok , Seg } = ra_log_segment :open (SegmentFile , #{mode => read }),
867+ % assert only entries with a higher index than the snapshot
868+ % have been written
869+ ok = gen_server :stop (TblWriterPid ),
870+ ? assertExit ({missing_key , 3 }, read_sparse (Seg , [2 , 3 , 4 ])),
871+ [
872+ {2 , _ , _ },
873+ {4 , _ , _ },
874+ {5 , _ , _ },
875+ {6 , _ , _ }
876+ ] = read_sparse (Seg , [2 , 4 , 5 , 6 ])
877+ after 3000 ->
878+ flush (),
879+ ok = gen_server :stop (TblWriterPid ),
880+ throw (ra_log_event_timeout )
881+ end ,
882+ ok .
883+
842884% %% Internal
843885
844886fake_mem_table (UId , Dir , Entries ) ->
0 commit comments