Permalink
Browse files

Merge pull request #70 from basho/slf-dialyzer20121116

Clear all Dialyzer warnings
  • Loading branch information...
2 parents e42900f + 8dc6f34 commit f706badb592b51f2e5e09e4ac6869414c4bb896d @slfritchie slfritchie committed Nov 16, 2012
Showing with 24 additions and 107 deletions.
  1. +1 −1 src/bitcask.erl
  2. +1 −1 src/bitcask_fileops.erl
  3. +22 −105 src/bitcask_nifs.erl
View
2 src/bitcask.erl
@@ -738,7 +738,7 @@ expired_threshold(Cutoff) ->
-spec is_empty_estimate(reference()) -> boolean().
is_empty_estimate(Ref) ->
State = get_state(Ref),
- {KeyCount, _, _} = bitcask_nifs:keydir_info(State#bc_state.keydir),
+ {KeyCount, _, _, _} = bitcask_nifs:keydir_info(State#bc_state.keydir),
KeyCount == 0.
-spec status(reference()) -> {integer(), [{string(), integer(), integer(), integer()}]}.
View
2 src/bitcask_fileops.erl
@@ -236,7 +236,7 @@ fold_keys(fresh, _Fun, Acc) -> Acc;
fold_keys(State, Fun, Acc) ->
fold_keys(State, Fun, Acc, default).
--spec fold_keys(fresh | #filestate{}, fun((binary(), integer(), {integer(), integer()}, any()) -> any()), any(), datafile | hintfile | default) ->
+-spec fold_keys(fresh | #filestate{}, fun((binary(), integer(), {integer(), integer()}, any()) -> any()), any(), datafile | hintfile | default | recovery) ->
any() | {error, any()}.
fold_keys(#filestate { fd = Fd } = State, Fun, Acc, Mode) ->
case Mode of
View
127 src/bitcask_nifs.erl
@@ -88,7 +88,7 @@
integer(), integer(), integer(), integer()) ->
ok | already_exists.
-spec keydir_put_int(reference(), binary(), integer(), integer(),
- binary(), integer(), boolean(), integer(), binary()) ->
+ binary(), integer(), 0 | 1, integer(), binary()) ->
ok | already_exists.
-spec keydir_get(reference(), binary()) ->
not_found | #bitcask_entry{}.
@@ -112,7 +112,9 @@
any() | {error, any()}.
-spec keydir_info(reference()) ->
{integer(), integer(),
- [{integer(), integer(), integer(), integer(), integer()}], integer(), boolean()}.
+ [{integer(), integer(), integer(), integer(), integer(),
+ integer(), integer()}],
+ {integer(), integer(), boolean()}}.
-spec keydir_release(reference()) ->
ok.
-spec lock_acquire(string(), integer()) ->
@@ -144,10 +146,7 @@ init() ->
-ifdef(PULSE).
set_pulse_pid(_Pid) ->
- case random:uniform(999999999999) of
- 666 -> ok;
- 667 -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
-endif.
%% ===================================================================
@@ -161,25 +160,13 @@ set_pulse_pid(_Pid) ->
keydir_new() ->
- case random:uniform(999999999999) of
- 666 -> {ok, make_ref()};
- 667 -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_new(Name) when is_list(Name) ->
- case random:uniform(999999999999) of
- 666 -> {ok, make_ref()};
- 667 -> {error, not_ready};
- 668 -> {ready, make_ref()};
- 669 -> {not_ready, make_ref()};
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_mark_ready(_Ref) ->
- case random:uniform(999999999999) of
- 666 -> ok;
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_put(Ref, Key, FileId, TotalSz, Offset, Tstamp) ->
keydir_put(Ref, Key, FileId, TotalSz, Offset, Tstamp, false).
@@ -201,11 +188,7 @@ keydir_put(Ref, Key, FileId, TotalSz, Offset, Tstamp, NewestPutB,
keydir_put_int(_Ref, _Key, _FileId, _TotalSz, _Offset, _Tstamp, _NewestPutI,
_OldFileId, _OldOffset) ->
- case random:uniform(999999999999) of
- 666 -> ok;
- 667 -> already_exists;
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_get(Ref, Key) ->
case keydir_get_int(Ref, Key) of
@@ -216,46 +199,28 @@ keydir_get(Ref, Key) ->
not_found
end.
-keydir_get_int(_Ref, Key) ->
- case random:uniform(999999999999) of
- 666 -> make_bogus_bitcask_entry(Key);
- 667 -> not_found;
- _ -> exit("NIF library not loaded")
- end.
+keydir_get_int(_Ref, _Key) ->
+ erlang:nif_error({error, not_loaded}).
keydir_remove(_Ref, _Key) ->
- case random:uniform(999999999999) of
- 666 -> ok;
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_remove(Ref, Key, Tstamp, FileId, Offset) ->
keydir_remove_int(Ref, Key, Tstamp, FileId, <<Offset:64/unsigned-native>>).
keydir_remove_int(_Ref, _Key, _Tstamp, _FileId, _Offset) ->
- case random:uniform(999999999999) of
- 666 -> ok;
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_copy(_Ref) ->
- case random:uniform(999999999999) of
- 666 -> {ok, make_ref()};
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_itr(Ref, MaxAge, MaxPuts) ->
{Mega,Secs,Micro} = os:timestamp(),
TS = <<((Mega * 1000000 + Secs) * 1000000 + Micro):64/unsigned-native>>,
keydir_itr_int(Ref, TS, MaxAge, MaxPuts).
keydir_itr_int(_Ref, _Ts, _MaxAge, _MaxPuts) ->
- case random:uniform(999999999999) of
- 666 -> {error, iteration_in_process};
- 667 -> out_of_date;
- 668 -> ok;
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_itr_next(Ref) ->
case keydir_itr_next_int(Ref) of
@@ -267,13 +232,7 @@ keydir_itr_next(Ref) ->
end.
keydir_itr_next_int(_Ref) ->
- case random:uniform(999999999999) of
- 666 -> {error, iteration_not_started};
- 667 -> allocation_error;
- 668 -> make_bogus_bitcask_entry(<<"BogusKey">>);
- 669 -> not_found;
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_itr_release(_Ref) ->
ok.
@@ -320,66 +279,39 @@ keydir_wait_pending(Ref) ->
end.
keydir_info(_Ref) ->
- case random:uniform(999999999999) of
- 666 -> {make_bogus_non_neg(), make_bogus_non_neg(), [{make_bogus_non_neg(), random:uniform(4242), random:uniform(4242), random:uniform(4242), random:uniform(4242)}]};
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
keydir_release(_Ref) ->
- case random:uniform(999999999999) of
- 666 -> ok;
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
lock_acquire(Filename, IsWriteLock) ->
bitcask_bump:big(),
lock_acquire_int(Filename, IsWriteLock).
lock_acquire_int(_Filename, _IsWriteLock) ->
- case random:uniform(999999999999) of
- 666 -> {ok, make_ref()};
- 667 -> {error, enoent};
- 668 -> {error, eexist};
- 669 -> {error, eio}; %% arbitrary choice that isn't a previous atom
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
lock_release(Ref) ->
bitcask_bump:big(),
lock_release_int(Ref).
lock_release_int(_Ref) ->
- case random:uniform(999999999999) of
- 666 -> ok;
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
lock_readdata(Ref) ->
bitcask_bump:big(),
lock_readdata_int(Ref).
lock_readdata_int(_Ref) ->
- case random:uniform(999999999999) of
- 666 -> {fstat_error, random:uniform(4242)};
- 667 -> {error, allocation_error};
- 668 -> {pread_error, random:uniform(4242)};
- 669 -> {ok, <<"BogusBinary">>};
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
lock_writedata(Ref, Data) ->
bitcask_bump:big(),
lock_writedata_int(Ref, Data).
lock_writedata_int(_Ref, _Data) ->
- case random:uniform(999999999999) of
- 666 -> {ftruncate_error, random:uniform(4242)};
- 667 -> {pwrite_error, random:uniform(4242)};
- 668 -> ok;
- 669 -> {error, lock_not_writable};
- _ -> exit("NIF library not loaded")
- end.
+ erlang:nif_error({error, not_loaded}).
file_open(Filename, Opts) ->
bitcask_bump:big(),
@@ -448,21 +380,6 @@ keydir_fold_cont(Curr, Ref, Fun, Acc0) ->
Acc = Fun(Curr, Acc0),
keydir_fold_cont(keydir_itr_next(Ref), Ref, Fun, Acc).
-%%-spec make_bogus_bitcask_entry(Key::binary()) -> #bitcask_entry{}.
-make_bogus_bitcask_entry(Key) ->
- #bitcask_entry{key = Key,
- file_id = make_bogus_non_neg(),
- total_sz = random:uniform(4242),
- offset = <<(4242):64/unsigned-native>>,
- tstamp = random:uniform(4242)
- }.
-
-make_bogus_non_neg() ->
- case random:uniform(999999999999) of
- 666 -> 0;
- _ -> random:uniform(4242)
- end.
-
%% ===================================================================
%% EUnit tests
%% ===================================================================

0 comments on commit f706bad

Please sign in to comment.