get_nextkey no longer used
So removed. Also now, no reason to call read_next_key directly - and all errors all seem to be try/caught.
This commit is contained in:
parent
ae70af5eec
commit
31505c1f5f
1 changed files with 7 additions and 75 deletions
|
@ -916,39 +916,6 @@ get_mem(Key, Handle, HashTree, BinaryMode, QuickCheck) ->
|
||||||
extract_kvpair(Handle, ListToCheck, Key, BinaryMode)
|
extract_kvpair(Handle, ListToCheck, Key, BinaryMode)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_nextkey(list()|file:io_device()) ->
|
|
||||||
nomorekeys|
|
|
||||||
{any(), nomorekeys}|
|
|
||||||
{any(), file:io_device(), {integer(), integer()}}.
|
|
||||||
%% @doc
|
|
||||||
%% Get the next key at a position in the file (or the first key if no position
|
|
||||||
%% is passed). Will return both a key and the next position, or nomorekeys if
|
|
||||||
%% the end has been reached (either in place of the result if there are no
|
|
||||||
%% more keys, or in place of the position if the returned key is the last key)
|
|
||||||
get_nextkey(Filename) when is_list(Filename) ->
|
|
||||||
{ok, Handle} = file:open(Filename, [binary, raw, read]),
|
|
||||||
get_nextkey(Handle);
|
|
||||||
get_nextkey(Handle) ->
|
|
||||||
{ok, _} = file:position(Handle, bof),
|
|
||||||
{FirstHashPosition, _} = read_next_2_integers(Handle),
|
|
||||||
get_nextkey(Handle, {256 * ?DWORD_SIZE, FirstHashPosition}).
|
|
||||||
|
|
||||||
get_nextkey(Handle, {Position, FirstHashPosition}) ->
|
|
||||||
{ok, Position} = file:position(Handle, Position),
|
|
||||||
case read_next_2_integers(Handle) of
|
|
||||||
{KeyLength, ValueLength} ->
|
|
||||||
NextKey = read_next_key(Handle, KeyLength),
|
|
||||||
NextPosition = Position + KeyLength + ValueLength + ?DWORD_SIZE,
|
|
||||||
case NextPosition of
|
|
||||||
FirstHashPosition ->
|
|
||||||
{NextKey, nomorekeys};
|
|
||||||
_ ->
|
|
||||||
{NextKey, Handle, {NextPosition, FirstHashPosition}}
|
|
||||||
end;
|
|
||||||
eof ->
|
|
||||||
nomorekeys
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec hashtable_calc(ets:tid(), integer()) -> {list(), binary()}.
|
-spec hashtable_calc(ets:tid(), integer()) -> {list(), binary()}.
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Create a binary representation of the hash table to be written to the end
|
%% Create a binary representation of the hash table to be written to the end
|
||||||
|
@ -1010,7 +977,7 @@ find_lastkey(Handle, IndexCache) ->
|
||||||
_ ->
|
_ ->
|
||||||
{ok, _} = file:position(Handle, LastPosition),
|
{ok, _} = file:position(Handle, LastPosition),
|
||||||
{KeyLength, _ValueLength} = read_next_2_integers(Handle),
|
{KeyLength, _ValueLength} = read_next_2_integers(Handle),
|
||||||
read_next_key(Handle, KeyLength)
|
safe_read_next_key(Handle, KeyLength)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1241,12 +1208,8 @@ calc_crc(Value) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_next_key(Handle, Length) ->
|
read_next_key(Handle, Length) ->
|
||||||
case file:read(Handle, Length) of
|
{ok, Bin} = file:read(Handle, Length),
|
||||||
{ok, Bin} ->
|
binary_to_term(Bin).
|
||||||
binary_to_term(Bin);
|
|
||||||
ReadError ->
|
|
||||||
ReadError
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
%% Read next string where the string has a CRC prepended - stripping the crc
|
%% Read next string where the string has a CRC prepended - stripping the crc
|
||||||
|
@ -1899,32 +1862,9 @@ search_hash_table_findinslot_test() ->
|
||||||
?assertMatch(missing, get("../test/hashtable1_test.cdb", Key1, false)),
|
?assertMatch(missing, get("../test/hashtable1_test.cdb", Key1, false)),
|
||||||
ok = file:delete("../test/hashtable1_test.cdb").
|
ok = file:delete("../test/hashtable1_test.cdb").
|
||||||
|
|
||||||
getnextkey_inclemptyvalue_test() ->
|
|
||||||
L = [{"K9", "V9"}, {"K2", "V2"}, {"K3", ""},
|
|
||||||
{"K4", "V4"}, {"K5", "V5"}, {"K6", "V6"}, {"K7", "V7"},
|
|
||||||
{"K8", "V8"}, {"K1", "V1"}],
|
|
||||||
ok = create("../test/hashtable2_test.cdb", L),
|
|
||||||
{FirstKey, Handle, P1} = get_nextkey("../test/hashtable2_test.cdb"),
|
|
||||||
io:format("Next position details of ~w~n", [P1]),
|
|
||||||
?assertMatch("K9", FirstKey),
|
|
||||||
{SecondKey, Handle, P2} = get_nextkey(Handle, P1),
|
|
||||||
?assertMatch("K2", SecondKey),
|
|
||||||
{ThirdKeyNoValue, Handle, P3} = get_nextkey(Handle, P2),
|
|
||||||
?assertMatch("K3", ThirdKeyNoValue),
|
|
||||||
{_, Handle, P4} = get_nextkey(Handle, P3),
|
|
||||||
{_, Handle, P5} = get_nextkey(Handle, P4),
|
|
||||||
{_, Handle, P6} = get_nextkey(Handle, P5),
|
|
||||||
{_, Handle, P7} = get_nextkey(Handle, P6),
|
|
||||||
{_, Handle, P8} = get_nextkey(Handle, P7),
|
|
||||||
{LastKey, nomorekeys} = get_nextkey(Handle, P8),
|
|
||||||
?assertMatch("K1", LastKey),
|
|
||||||
ok = file:delete("../test/hashtable2_test.cdb").
|
|
||||||
|
|
||||||
newactivefile_test() ->
|
newactivefile_test() ->
|
||||||
{LastPosition, _, _} = open_active_file("../test/activefile_test.cdb"),
|
{LastPosition, _, _} = open_active_file("../test/activefile_test.cdb"),
|
||||||
?assertMatch(256 * ?DWORD_SIZE, LastPosition),
|
?assertMatch(256 * ?DWORD_SIZE, LastPosition),
|
||||||
Response = get_nextkey("../test/activefile_test.cdb"),
|
|
||||||
?assertMatch(nomorekeys, Response),
|
|
||||||
ok = file:delete("../test/activefile_test.cdb").
|
ok = file:delete("../test/activefile_test.cdb").
|
||||||
|
|
||||||
emptyvalue_fromdict_test() ->
|
emptyvalue_fromdict_test() ->
|
||||||
|
@ -2215,7 +2155,7 @@ safe_read_test() ->
|
||||||
<<KeyL:32/integer, ValueL:32/integer, Key/binary, ValToWrite/binary>>,
|
<<KeyL:32/integer, ValueL:32/integer, Key/binary, ValToWrite/binary>>,
|
||||||
|
|
||||||
TestCorruptedWriteFun =
|
TestCorruptedWriteFun =
|
||||||
fun(BitNumber, ok) ->
|
fun(BitNumber) ->
|
||||||
<<PreBin:BitNumber/bitstring,
|
<<PreBin:BitNumber/bitstring,
|
||||||
Bit:1/integer,
|
Bit:1/integer,
|
||||||
PostBin/bitstring>> = BinToWrite,
|
PostBin/bitstring>> = BinToWrite,
|
||||||
|
@ -2227,19 +2167,11 @@ safe_read_test() ->
|
||||||
{ok, Handle} = file:open(TestFN, ?WRITE_OPS),
|
{ok, Handle} = file:open(TestFN, ?WRITE_OPS),
|
||||||
ok = file:pwrite(Handle, 0, AltBin),
|
ok = file:pwrite(Handle, 0, AltBin),
|
||||||
{ok, _} = file:position(Handle, bof),
|
{ok, _} = file:position(Handle, bof),
|
||||||
case saferead_keyvalue(Handle) of
|
?assertMatch(false, saferead_keyvalue(Handle))
|
||||||
false ->
|
|
||||||
ok;
|
|
||||||
{Key, Value, KeyL, ValueL} ->
|
|
||||||
ok
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
Check = lists:foldl(TestCorruptedWriteFun,
|
lists:foreach(TestCorruptedWriteFun,
|
||||||
ok,
|
|
||||||
lists:seq(1, -1 + 8 * (KeyL + ValueL + 8))),
|
lists:seq(1, -1 + 8 * (KeyL + ValueL + 8))),
|
||||||
|
|
||||||
?assertMatch(ok, Check),
|
|
||||||
file:delete(TestFN).
|
file:delete(TestFN).
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue