Skip to content

Commit

Permalink
Another round of trying to eliminate PULSE nondeterminism.
Browse files Browse the repository at this point in the history
* PULSE side-effect for all bitcask_nifs functions, !@#$!.  The
function-by-function declaration is too specific and thus too brittle.
Every time a new NIF is added or an existing NIF arity is changed,
everyone (myself included) forgets to change rebar.config.script.
Instead, we'll use a blanket wildcard statement, and for the few
non-NIF functions in bitcask_nifs.erl, they'll get instrumented too.

* Move make_merge_file() from bitcask_pulse.erl -> bitcask.erl,
because bitcask_pulse has an explicit `pulse_no_side_effect`
directive for file:'_' calls.
  • Loading branch information
slfritchie committed May 26, 2014
1 parent 633b913 commit 12bf665
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 51 deletions.
34 changes: 1 addition & 33 deletions rebar.config.script
Expand Up @@ -9,39 +9,7 @@ case PulseBuild of
PulseOpts =
[{pulse_no_side_effect,[{erlang,display,1}]},
{pulse_side_effect,
[ {bitcask_nifs, keydir_new, 0}
, {bitcask_nifs, keydir_new, 1}
, {bitcask_nifs, maybe_keydir_new, 1}
, {bitcask_nifs, keydir_mark_ready, 1}
, {bitcask_nifs, keydir_put_int, 10}
, {bitcask_nifs, keydir_get_int, 3}
, {bitcask_nifs, keydir_remove, 3}
, {bitcask_nifs, keydir_remove_int, 6}
, {bitcask_nifs, keydir_copy, 1}
, {bitcask_nifs, keydir_itr_int, 4}
, {bitcask_nifs, keydir_itr_next_int, 1}
, {bitcask_nifs, keydir_itr_release, 1}
, {bitcask_nifs, keydir_info, 1}
, {bitcask_nifs, keydir_release, 1}
, {bitcask_nifs, keydir_trim_fstats, 2}

, {bitcask_nifs, increment_file_id, 1}
, {bitcask_nifs, increment_file_id, 2}

, {bitcask_nifs, lock_acquire_int, 2}
, {bitcask_nifs, lock_release_int, 1}
, {bitcask_nifs, lock_readdata_int, 1}
, {bitcask_nifs, lock_writedata_int, 2}

, {bitcask_nifs, file_open_int, 2}
, {bitcask_nifs, file_close_int, 1}
, {bitcask_nifs, file_sync_int, 1}
, {bitcask_nifs, file_pread_int, 3}
, {bitcask_nifs, file_pwrite_int, 3}
, {bitcask_nifs, file_read_int, 2}
, {bitcask_nifs, file_write_int, 2}
, {bitcask_nifs, file_position_int, 2}
, {bitcask_nifs, file_seekbof_int, 1}
[ {bitcask_nifs, '_', '_'}

, {bitcask_file, '_', '_'}
, {bitcask_time, tstamp, 0}
Expand Down
17 changes: 17 additions & 0 deletions src/bitcask.erl
Expand Up @@ -3178,4 +3178,21 @@ legacy_tombstones_test() ->
bitcask:close(B),
?assertEqual([Last], AllFiles3).

make_merge_file(Dir, Seed, Probability) ->
random:seed(Seed),
case filelib:is_dir(Dir) of
true ->
DataFiles = filelib:wildcard("*.data", Dir),
{ok, FH} = file:open(Dir ++ "/merge.txt", [write]),
[case random:uniform(100) < Probability of
true ->
io:format(FH, "~s\n", [DF]);
false ->
ok
end || DF <- DataFiles],
ok = file:close(FH);
false ->
ok
end.

-endif.
19 changes: 1 addition & 18 deletions test/bitcask_pulse.erl
Expand Up @@ -802,7 +802,7 @@ fold_keys(H) ->
bc_open(Writer, {MakeMergeFileP, Seed, Probability}) ->
erlang:put(?BITCASK_TESTING_KEY, ?MODULE),
if MakeMergeFileP ->
make_merge_file(?BITCASK, Seed, Probability);
bitcask:make_merge_file(?BITCASK, Seed, Probability);
true ->
ok
end,
Expand Down Expand Up @@ -1133,21 +1133,4 @@ mangle_temporal_relation_with_finite_time([H|T]) ->
%% {check_no_tombstones, Else}
%% end.

make_merge_file(Dir, Seed, Probability) ->
random:seed(Seed),
case filelib:is_dir(Dir) of
true ->
DataFiles = filelib:wildcard("*.data", Dir),
{ok, FH} = file:open(Dir ++ "/merge.txt", [write]),
[case random:uniform(100) < Probability of
true ->
io:format(FH, "~s\n", [DF]);
false ->
ok
end || DF <- DataFiles],
ok = file:close(FH);
false ->
ok
end.

-endif.

0 comments on commit 12bf665

Please sign in to comment.