Permalink
Browse files

Review cleanups.

Thanks for review comments from Justin.
* Cleared iterating flag on itr cleanup.
* keydir_put_int now returns {error, iteration_in_progress).
  • Loading branch information...
1 parent 9e254b7 commit 9b82adfac387a35246042b34b124081a2868f8be @jonmeredith jonmeredith committed May 4, 2011
Showing with 10 additions and 3 deletions.
  1. +2 −1 c_src/bitcask_nifs.c
  2. +8 −2 src/bitcask_nifs.erl
View
@@ -391,7 +391,7 @@ ERL_NIF_TERM bitcask_nifs_keydir_put_int(ErlNifEnv* env, int argc, const ERL_NIF
if (keydir->keyfolders > 0)
{
UNLOCK(keydir);
- return ATOM_ITERATION_IN_PROCESS;
+ return enif_make_tuple2(env, ATOM_ERROR, ATOM_ITERATION_IN_PROCESS);
}
// Now that we've marshalled everything, see if the tstamp for this key is >=
@@ -753,6 +753,7 @@ ERL_NIF_TERM bitcask_nifs_keydir_itr_release(ErlNifEnv* env, int argc, const ERL
return enif_make_tuple2(env, ATOM_ERROR, ATOM_ITERATION_NOT_STARTED);
}
+ handle->iterating = 0;
handle->keydir->keyfolders--;
UNLOCK(handle->keydir);
return ATOM_OK;
View
@@ -163,7 +163,7 @@ keydir_put(Ref, Key, FileId, TotalSz, Offset, Tstamp) ->
try_keydir_put_int(Ref, Key, FileId, TotalSz, BinOffset, Tstamp, Reps) ->
case keydir_put_int(Ref, Key, FileId, TotalSz, BinOffset, Tstamp) of
- iteration_in_process ->
+ {error, iteration_in_process} ->
try_keydir_put_int(Ref, Key, FileId, TotalSz, BinOffset, Tstamp, Reps + 1);
R when Reps > 0 ->
put_retries(Reps),
@@ -411,7 +411,7 @@ keydir_named_not_ready_test() ->
{error, not_ready} = keydir_new("k2").
-keydir_double_itr_error_test() ->
+keydir_itr_while_itr_error_test() ->
{ok, Ref1} = keydir_new(),
ok = keydir_itr(Ref1),
try
@@ -420,6 +420,12 @@ keydir_double_itr_error_test() ->
keydir_itr_release(Ref1)
end.
+keydir_double_itr_test() -> % check iterating flag is cleared
+ {ok, Ref1} = keydir_new(),
+ Folder = fun(_,Acc) -> Acc end,
+ ?assertEqual(acc, keydir_fold(Ref1, Folder, acc)),
+ ?assertEqual(acc, keydir_fold(Ref1, Folder, acc)).
+
keydir_next_notstarted_error_test() ->
{ok, Ref1} = keydir_new(),
?assertEqual({error, iteration_not_started}, keydir_itr_next(Ref1)).

0 comments on commit 9b82adf

Please sign in to comment.