11% % -------------------------------------------------------------------
22% %
33% % Copyright (c) 2012-2017 Basho Technologies, Inc.
4+ % % Copyright (c) 2024 Workday, Inc.
45% %
56% % This file is provided to you under the Apache License,
67% % Version 2.0 (the "License"); you may not use this file
@@ -182,7 +183,8 @@ delete_files(Files) ->
182183-ifdef (TEST ).
183184
184185multiple_merges_during_fold_test_ () ->
185- {timeout , 60 , fun multiple_merges_during_fold_body /0 }.
186+ [{timeout , 60 , fun multiple_merges_during_fold_body /0 },
187+ {timeout , 60 , fun multiple_merges_during_fold_body_with_corrupt_hintfiles /0 }].
186188
187189multiple_merges_during_fold_body () ->
188190 Dir = filename :join (? TEST_FILEPATH , " bc.multiple-merges-fold" ),
@@ -212,7 +214,7 @@ multiple_merges_during_fold_body() ->
212214 PutSome (),
213215 Count1 = merge_until (Dir , 0 , CountSetuids ),
214216 PutSome (),
215- bitcask :merge (Dir ),
217+ ok = bitcask :merge (Dir ),
216218 PutSome (),
217219 merge_until (Dir , Count1 , CountSetuids ),
218220
@@ -223,8 +225,44 @@ multiple_merges_during_fold_body() ->
223225
224226 ok .
225227
228+ multiple_merges_during_fold_body_with_corrupt_hintfiles () ->
229+ Dir = filename :join (? TEST_FILEPATH , " bc.multiple-merges-fold-hintfile" ),
230+ B = bitcask :open (Dir , [read_write , {max_file_size , 50 }]),
231+ PutSome = fun () ->
232+ [bitcask :put (B , <<X :32 >>, <<" yo this is a value" >>) ||
233+ X <- lists :seq (1 ,5 )]
234+ end ,
235+ PutSome (),
236+ PutSome (),
237+ Bstuff = get (B ),
238+ FoldFun = fun (_K , _V , 0 ) ->
239+ receive go_ahead -> ok end ,
240+ 1 ;
241+ (_K , _V , 1 ) ->
242+ 1
243+ end ,
244+ _SlowPid = spawn (fun () ->
245+ put (B , Bstuff ),
246+ bitcask :fold (B , FoldFun , 0 )
247+ end ),
248+ CountSetuids = fun () ->
249+ Fs = filelib :wildcard (Dir ++ " /*" ),
250+ length ([F || F <- Fs ,
251+ bitcask :has_pending_delete_bit (F )])
252+ end ,
253+ PutSome (),
254+ _DeletedHints = [file :delete (H ) || H <- filelib :wildcard (Dir ++ " /*.hint" )],
255+ _Count1 = merge_until (Dir , 0 , CountSetuids ),
256+ PutSome (),
257+ ok = bitcask :merge (Dir ),
258+
259+ ok = ? MODULE :testonly__delete_trigger (),
260+ 0 = CountSetuids (),
261+
262+ ok .
263+
226264merge_until (Dir , MinCount , CountSetuids ) ->
227- bitcask :merge (Dir ),
265+ ok = bitcask :merge (Dir ),
228266 Count = CountSetuids (),
229267 if (Count > MinCount ) ->
230268 Count ;
@@ -571,7 +609,7 @@ fork_merge(H, Dir) ->
571609merge_these (_H , TestDir , Ids ) ->
572610 Files = [lists :flatten (io_lib :format (" ~s /~w .bitcask.data" , [TestDir ,Id ])) ||
573611 Id <- Ids ],
574- bitcask :merge (TestDir , [], Files ).
612+ ok = bitcask :merge (TestDir , [], Files ).
575613
576614incr_clock () ->
577615 bitcask_time :test__incr_fudge (1 ).
0 commit comments