Fix read_chunk op in b_b driver

This commit is contained in:
Scott Lystig Fritchie 2016-03-28 18:42:04 +09:00
parent a739b5265c
commit e63db8dedc
2 changed files with 12 additions and 9 deletions

View file

@ -21,7 +21,7 @@
%% @doc Now 4GiBytes, could be up to 64bit due to PB message limit of %% @doc Now 4GiBytes, could be up to 64bit due to PB message limit of
%% chunk size %% chunk size
-define(DEFAULT_MAX_FILE_SIZE, ((1 bsl 32) - 1)). -define(DEFAULT_MAX_FILE_SIZE, ((1 bsl 32) - 1)).
-define(MINIMUM_OFFSET, 1024). -define(MINIMUM_OFFSET, 0).
%% 0th draft of checksum typing with 1st byte. %% 0th draft of checksum typing with 1st byte.
-define(CSUM_TAG_NONE, 0). % No csum provided by client -define(CSUM_TAG_NONE, 0). % No csum provided by client

View file

@ -60,6 +60,7 @@
-export([new/1, run/4]). -export([new/1, run/4]).
-record(m, { -record(m, {
id,
conn, conn,
max_key max_key
}). }).
@ -90,7 +91,7 @@ new(Id) ->
true -> true ->
ok ok
end, end,
{ok, #m{conn=Conn}}. {ok, #m{id=Id, conn=Conn}}.
run(append, KeyGen, ValueGen, #m{conn=Conn}=S) -> run(append, KeyGen, ValueGen, #m{conn=Conn}=S) ->
Prefix = KeyGen(), Prefix = KeyGen(),
@ -114,7 +115,7 @@ run(read, KeyGen, _ValueGen, #m{conn=Conn, max_key=MaxKey}=S) ->
Idx = KeyGen() rem MaxKey, Idx = KeyGen() rem MaxKey,
%% {File, Offset, Size, _CSum} = ets:lookup_element(?ETS_TAB, Idx, 2), %% {File, Offset, Size, _CSum} = ets:lookup_element(?ETS_TAB, Idx, 2),
{File, Offset, Size} = ets:lookup_element(?ETS_TAB, Idx, 2), {File, Offset, Size} = ets:lookup_element(?ETS_TAB, Idx, 2),
case machi_cr_client:read_chunk(Conn, File, Offset, Size, undefined, ?THE_TIMEOUT) of case machi_cr_client:read_chunk(Conn, undefined, File, Offset, Size, undefined, ?THE_TIMEOUT) of
{ok, _Chunk} -> {ok, _Chunk} ->
{ok, S}; {ok, S};
{error, _}=Err -> {error, _}=Err ->
@ -141,12 +142,14 @@ load_ets_table(Conn, ETS) ->
PosList = machi_csum_table:split_checksum_list_blob_decode(InfoBin), PosList = machi_csum_table:split_checksum_list_blob_decode(InfoBin),
?INFO("File ~s len PosList ~p\n", [File, length(PosList)]), ?INFO("File ~s len PosList ~p\n", [File, length(PosList)]),
StartKey = ets:update_counter(ETS, max_key, 0), StartKey = ets:update_counter(ETS, max_key, 0),
{_, Bytes} = lists:foldl(fun({Off,Sz,_CSum}, {K, Bs}) -> {_, C, Bytes} = lists:foldl(fun({_Off,0,_CSum}, {_K, _C, _Bs}=Acc) ->
V = {File, Off, Sz}, Acc;
ets:insert(ETS, {K, V}), ({Off,Sz,_CSum}, {K, C, Bs}) ->
{K + 1, Bs + Sz} V = {File, Off, Sz},
end, {StartKey, 0}, PosList), ets:insert(ETS, {K, V}),
ets:update_counter(ETS, max_key, length(PosList)), {K + 1, C + 1, Bs + Sz}
end, {StartKey, 0, 0}, PosList),
ets:update_counter(ETS, max_key, C),
ets:update_counter(ETS, total_bytes, Bytes) ets:update_counter(ETS, total_bytes, Bytes)
end || {_Size, File} <- Fs], end || {_Size, File} <- Fs],
ets:update_counter(?ETS_TAB, max_key, 0). ets:update_counter(?ETS_TAB, max_key, 0).