diff options
author | Hans Bolinder <[email protected]> | 2010-09-21 14:40:18 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2010-10-21 08:51:13 +0200 |
commit | d98b14f2c2c808491e1a5942820cddaab4d65742 (patch) | |
tree | 189ab42a00b3095fda9e9d49154c678a4d13c8c5 | |
parent | dc7d2319691fa599717c066460cce53ce97b6b18 (diff) | |
download | otp-d98b14f2c2c808491e1a5942820cddaab4d65742.tar.gz otp-d98b14f2c2c808491e1a5942820cddaab4d65742.tar.bz2 otp-d98b14f2c2c808491e1a5942820cddaab4d65742.zip |
Fix a bug in dets:insert_new()
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'.
-rw-r--r-- | lib/stdlib/src/dets.erl | 3 | ||||
-rw-r--r-- | lib/stdlib/test/dets_SUITE.erl | 31 |
2 files changed, 28 insertions, 6 deletions
diff --git a/lib/stdlib/src/dets.erl b/lib/stdlib/src/dets.erl index 4584b8184f..cc1f35914a 100644 --- a/lib/stdlib/src/dets.erl +++ b/lib/stdlib/src/dets.erl @@ -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); diff --git a/lib/stdlib/test/dets_SUITE.erl b/lib/stdlib/test/dets_SUITE.erl index 760e610e00..b32d372889 100644 --- a/lib/stdlib/test/dets_SUITE.erl +++ b/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 @@ -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]). @@ -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) -> []; @@ -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 %% |