Skip to content

Commit

Permalink
Merge branch 'hb/stdlib/dets_init/OTP-8923' into dev
Browse files Browse the repository at this point in the history
* hb/stdlib/dets_init/OTP-8923:
  Fix badly formed Dets file after initialization
  • Loading branch information
uabboli committed Nov 8, 2010
2 parents f8ac585 + 1d3edd9 commit cbdf6d5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/stdlib/src/dets_v8.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,8 @@ wl([], _Type, Del, Lookup, I, Objs) ->
[{Del, Lookup, Objs} | I].

%% -> {NewHead, ok} | {NewHead, Error}
may_grow(Head, 0, once) ->
{Head, ok};
may_grow(Head, _N, _How) when Head#head.fixed =/= false ->
{Head, ok};
may_grow(#head{access = read}=Head, _N, _How) ->
Expand Down
5 changes: 4 additions & 1 deletion lib/stdlib/src/dets_v9.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2001-2009. All Rights Reserved.
%% Copyright Ericsson AB 2001-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 @@ -1908,6 +1908,9 @@ write_cache(Head) ->
end.

%% -> {NewHead, ok} | {NewHead, Error}
may_grow(Head, 0, once) ->
%% Do not re-hash if there is a chance that the file is not dirty.
{Head, ok};
may_grow(Head, _N, _How) when Head#head.fixed =/= false ->
{Head, ok};
may_grow(#head{access = read}=Head, _N, _How) ->
Expand Down
39 changes: 37 additions & 2 deletions lib/stdlib/test/dets_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
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_8856/1, otp_8898/1, otp_8899/1, otp_8903/1]).
otp_8070/1, otp_8856/1, otp_8898/1, otp_8899/1, otp_8903/1,
otp_8923/1]).

-export([dets_dirty_loop/0]).

Expand Down Expand Up @@ -108,7 +109,8 @@ 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_8856, otp_8898, otp_8899, otp_8903]}
otp_7146, otp_8070, otp_8856, otp_8898, otp_8899, otp_8903,
otp_8923]}
end.

not_run(suite) -> [];
Expand Down Expand Up @@ -3805,6 +3807,39 @@ otp_8903(Config) when is_list(Config) ->
file:delete(File),
ok.

otp_8923(doc) ->
["OTP-8923. rehash due to lookup after initialization."];
otp_8923(suite) ->
[];
otp_8923(Config) when is_list(Config) ->
Tab = otp_8923,
File = filename(Tab, Config),
%% Create a file with more than 256 keys:
file:delete(File),
Bin = list_to_binary([ 0 || _ <- lists:seq(1, 400) ]),
BigBin = list_to_binary([ 0 ||_ <- lists:seq(1, 4000)]),
Ets = ets:new(temp, [{keypos,1}]),
?line [ true = ets:insert(Ets, {C,Bin}) || C <- lists:seq(1, 700) ],
?line true = ets:insert(Ets, {helper_data,BigBin}),
?line true = ets:insert(Ets, {prim_btree,BigBin}),
?line true = ets:insert(Ets, {sec_btree,BigBin}),
%% Note: too few slots; re-hash will take place
?line {ok, Tab} = dets:open_file(Tab, [{file,File}]),
?line Tab = ets:to_dets(Ets, Tab),
?line ok = dets:close(Tab),
?line true = ets:delete(Ets),

?line {ok,Ref} = dets:open_file(File),
?line [{1,_}] = dets:lookup(Ref, 1),
?line ok = dets:close(Ref),

?line {ok,Ref2} = dets:open_file(File),
?line [{helper_data,_}] = dets:lookup(Ref2, helper_data),
?line ok = dets:close(Ref2),

file:delete(File),
ok.

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

0 comments on commit cbdf6d5

Please sign in to comment.