Skip to content

Commit

Permalink
Fix a bug in dets:insert_new()
Browse files Browse the repository at this point in the history
When several clients accessed a Dets table simultaneously, one of them
calling dets:insert_new/2, the Dets server could crash. Alternatively,
under the same conditions, 'ok' was sometimes returned instead of 'true'.
  • Loading branch information
uabboli committed Oct 21, 2010
1 parent dc7d231 commit d98b14f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
3 changes: 0 additions & 3 deletions lib/stdlib/src/dets.erl
Expand Up @@ -1381,9 +1381,6 @@ stream_op(Head, Pids, C, N, Pid, {lookup_keys,Keys}, Fxd) ->
stream_op(Head, Pids, C, N, Pid, {insert, _Objects} = Op, Fxd) ->
NC = [Op | C],
stream_loop(Head, [Pid | Pids], NC, N, Fxd);
stream_op(Head, Pids, C, N, Pid, {insert_new, _Objects} = Op, Fxd) ->
NC = [Op | C],
stream_loop(Head, [Pid | Pids], NC, N, Fxd);
stream_op(Head, Pids, C, N, Pid, {delete_key, _Keys} = Op, Fxd) ->
NC = [Op | C],
stream_loop(Head, [Pid | Pids], NC, N, Fxd);
Expand Down
31 changes: 28 additions & 3 deletions lib/stdlib/test/dets_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
%% Copyright Ericsson AB 1996-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
Expand Down Expand Up @@ -50,7 +50,7 @@
otp_4208/1, otp_4989/1, many_clients/1, otp_4906/1, otp_5402/1,
simultaneous_open/1, insert_new/1, repair_continuation/1,
otp_5487/1, otp_6206/1, otp_6359/1, otp_4738/1, otp_7146/1,
otp_8070/1]).
otp_8070/1, otp_8856/1]).

-export([dets_dirty_loop/0]).

Expand Down Expand Up @@ -108,7 +108,7 @@ all(suite) ->
cache_duplicate_bags_v9, otp_4208, otp_4989, many_clients,
otp_4906, otp_5402, simultaneous_open, insert_new,
repair_continuation, otp_5487, otp_6206, otp_6359, otp_4738,
otp_7146, otp_8070]}
otp_7146, otp_8070, otp_8856]}
end.

not_run(suite) -> [];
Expand Down Expand Up @@ -3701,6 +3701,31 @@ otp_8070(Config) when is_list(Config) ->
file:delete(File),
ok.

otp_8856(doc) ->
["OTP-8856. insert_new() bug."];
otp_8856(suite) ->
[];
otp_8856(Config) when is_list(Config) ->
Tab = otp_8856,
File = filename(Tab, Config),
file:delete(File),
Me = self(),
?line {ok, _} = dets:open_file(Tab, [{type, bag}, {file, File}]),
spawn(fun()-> Me ! {1, dets:insert(Tab, [])} end),
spawn(fun()-> Me ! {2, dets:insert_new(Tab, [])} end),
?line ok = dets:close(Tab),
?line receive {1, ok} -> ok end,
?line receive {2, true} -> ok end,
file:delete(File),

?line {ok, _} = dets:open_file(Tab, [{type, set}, {file, File}]),
spawn(fun() -> dets:delete(Tab, 0) end),
spawn(fun() -> Me ! {3, dets:insert_new(Tab, {0,0})} end),
?line ok = dets:close(Tab),
?line receive {3, true} -> ok end,
file:delete(File),
ok.

%%
%% Parts common to several test cases
%%
Expand Down

0 comments on commit d98b14f

Please sign in to comment.