diff --git a/src/machi_admin_util.erl b/src/machi_admin_util.erl index 20cfbfe..770a566 100644 --- a/src/machi_admin_util.erl +++ b/src/machi_admin_util.erl @@ -95,7 +95,7 @@ verify_file_checksums_common(Sock1, EpochID, File, ReadChunk) -> try case ?FLU_C:checksum_list(Sock1, EpochID, File) of {ok, InfoBin} -> - {Info, _} = machi_checksums:split_checksum_list_blob_decode(InfoBin), + {Info, _} = machi_csum_table:split_checksum_list_blob_decode(InfoBin), Res = lists:foldl(verify_chunk_checksum(File, ReadChunk), [], Info), {ok, Res}; diff --git a/src/machi_csum_table.erl b/src/machi_csum_table.erl index e45dc5e..9720ddc 100644 --- a/src/machi_csum_table.erl +++ b/src/machi_csum_table.erl @@ -59,11 +59,12 @@ open(CSumFilename, _Opts) -> -spec find(table(), machi_dt:chunk_pos(), machi_dt:chunk_size()) -> {ok, machi_dt:chunk_csum()} | {error, trimmed|notfound}. find(#machi_csum_table{table=T}, Offset, Size) -> + %% TODO: Check whether all bytes here are written or not case ets:lookup(T, Offset) of [{Offset, Size, trimmed}] -> {error, trimmed}; [{Offset, Size, Checksum}] -> {ok, Checksum}; - [{Offset, _, Checksum}] -> {ok, Checksum}; - [] -> {error, notfound} + [{Offset, _, _}] -> {error, unknown_chunk}; + [] -> {error, unknown_chunk} end. -spec write(table(), machi_dt:chunk_pos(), machi_dt:chunk_size(), diff --git a/src/machi_file_proxy.erl b/src/machi_file_proxy.erl index 40193ee..8a850de 100644 --- a/src/machi_file_proxy.erl +++ b/src/machi_file_proxy.erl @@ -597,9 +597,10 @@ handle_write(FHd, CsumTable, Filename, TaggedCsum, Offset, Data, U) -> case machi_csum_table:find(CsumTable, Offset, Size) of {error, trimmed} = Error -> Error; - {error, notfound} -> - %% Just unknown pair of {offset, size} - %% given. Trust U and return as it is used + {error, unknown_chunk} -> + %% The specified has some bytes written, while + %% it's not in the checksum table. Trust U and + %% return as it is used. {error, written}; {ok, TaggedCsum} -> case do_read(FHd, Filename, TaggedCsum, Offset, Size) of diff --git a/test/machi_csum_table_test.erl b/test/machi_csum_table_test.erl index a9535af..9846e1a 100644 --- a/test/machi_csum_table_test.erl +++ b/test/machi_csum_table_test.erl @@ -3,27 +3,29 @@ smoke_test() -> Filename = "./temp-checksum-dumb-file", - {ok, MC} = machi_checksums:new(Filename), + _ = file:delete(Filename), + {ok, MC} = machi_csum_table:open(Filename, []), {Offset, Size, Checksum} = {64, 34, <<"deadbeef">>}, - {error, unwritten} = machi_checksums:find(MC, Offset, Size), - ok = machi_checksums:write(MC, Offset, Size, Checksum), - {ok, Checksum} = machi_checksums:find(MC, Offset, Size), - ok = machi_checksums:trim(MC, Offset, Size), - {error, trimmed} = machi_checksums:find(MC, Offset, Size), - ok = machi_checksums:destroy(MC), - ok = machi_checksums:delete_file(MC). + {error, unknown_chunk} = machi_csum_table:find(MC, Offset, Size), + ok = machi_csum_table:write(MC, Offset, Size, Checksum), + {ok, Checksum} = machi_csum_table:find(MC, Offset, Size), + ok = machi_csum_table:trim(MC, Offset, Size), + {error, trimmed} = machi_csum_table:find(MC, Offset, Size), + ok = machi_csum_table:close(MC), + ok = machi_csum_table:delete(MC). close_test() -> Filename = "./temp-checksum-dumb-file-2", - {ok, MC} = machi_checksums:new(Filename), + _ = file:delete(Filename), + {ok, MC} = machi_csum_table:open(Filename, []), {Offset, Size, Checksum} = {64, 34, <<"deadbeef">>}, - {error, unwritten} = machi_checksums:find(MC, Offset, Size), - ok = machi_checksums:write(MC, Offset, Size, Checksum), - {ok, Checksum} = machi_checksums:find(MC, Offset, Size), - ok = machi_checksums:destroy(MC), + {error, unknown_chunk} = machi_csum_table:find(MC, Offset, Size), + ok = machi_csum_table:write(MC, Offset, Size, Checksum), + {ok, Checksum} = machi_csum_table:find(MC, Offset, Size), + ok = machi_csum_table:close(MC), - {ok, MC2} = machi_checksums:new(Filename), - {ok, Checksum} = machi_checksums:find(MC2, Offset, Size), - ok = machi_checksums:trim(MC2, Offset, Size), - {error, trimmed} = machi_checksums:find(MC2, Offset, Size), - ok = machi_checksums:delete_file(MC2). + {ok, MC2} = machi_csum_table:open(Filename, []), + {ok, Checksum} = machi_csum_table:find(MC2, Offset, Size), + ok = machi_csum_table:trim(MC2, Offset, Size), + {error, trimmed} = machi_csum_table:find(MC2, Offset, Size), + ok = machi_csum_table:delete(MC2).