diff --git a/src/machi_admin_util.erl b/src/machi_admin_util.erl index 4698e1a..ea0f3bf 100644 --- a/src/machi_admin_util.erl +++ b/src/machi_admin_util.erl @@ -32,6 +32,7 @@ -compile(export_all). -include("machi.hrl"). +-include("machi_projection.hrl"). -define(FLU_C, machi_flu1_client). @@ -73,7 +74,8 @@ verify_file_checksums_local2(Sock1, Path0) -> verify_file_checksums_remote2(Sock1, File) -> ReadChunk = fun(File_name, Offset, Size) -> - ?FLU_C:read_chunk(Sock1, File_name, Offset, Size) + ?FLU_C:read_chunk(Sock1, ?DUMMY_PV1_EPOCH, + File_name, Offset, Size) end, verify_file_checksums_common(Sock1, File, ReadChunk). diff --git a/src/machi_flu1.erl b/src/machi_flu1.erl index 5a8ba7e..6bea7ec 100644 --- a/src/machi_flu1.erl +++ b/src/machi_flu1.erl @@ -107,35 +107,23 @@ net_server_loop(Sock, #state{reg_name=RegName, data_dir=DataDir}=S) -> case gen_tcp:recv(Sock, 0, 60*1000) of {ok, Line} -> %% machi_util:verb("Got: ~p\n", [Line]), - PrefixLenLF = byte_size(Line) - 2 - 8 - 1 - 1, PrefixLenLF_E = byte_size(Line) - 2 - ?EpochIDSpace - 8 - 1, - PrefixLenCRLF = byte_size(Line) - 2 - 8 - 1 - 2, - FileLenLF = byte_size(Line) - 2 - 16 - 1 - 8 - 1 - 1, - FileLenCRLF = byte_size(Line) - 2 - 16 - 1 - 8 - 1 - 2, + FileLenLF_E = byte_size(Line) - 2 - ?EpochIDSpace - 16 - 8 - 1, CSumFileLenLF = byte_size(Line) - 2 - 1, CSumFileLenCRLF = byte_size(Line) - 2 - 2, WriteFileLenLF = byte_size(Line) - 7 - 16 - 1 - 8 - 1 - 1, DelFileLenLF = byte_size(Line) - 14 - 1, case Line of %% For normal use - <<"A ", LenHex:8/binary, " ", - Prefix:PrefixLenLF/binary, "\n">> -> - do_net_server_append(RegName, Sock, LenHex, Prefix); -%% BEGIN epoch-id hack <<"A ", _EpochIDRaw:(?EpochIDSpace)/binary, LenHex:8/binary, Prefix:PrefixLenLF_E/binary, "\n">> -> do_net_server_append(RegName, Sock, LenHex, Prefix); -%% END epoch-id hack - <<"A ", LenHex:8/binary, " ", - Prefix:PrefixLenCRLF/binary, "\r\n">> -> - do_net_server_append(RegName, Sock, LenHex, Prefix); - <<"R ", OffsetHex:16/binary, " ", LenHex:8/binary, " ", - File:FileLenLF/binary, "\n">> -> - do_net_server_read(Sock, OffsetHex, LenHex, File, DataDir); - <<"R ", OffsetHex:16/binary, " ", LenHex:8/binary, " ", - File:FileLenCRLF/binary, "\r\n">> -> + <<"R ", + _EpochIDRaw:(?EpochIDSpace)/binary, + OffsetHex:16/binary, LenHex:8/binary, + File:FileLenLF_E/binary, "\n">> -> do_net_server_read(Sock, OffsetHex, LenHex, File, DataDir); <<"L\n">> -> do_net_server_listing(Sock, DataDir); diff --git a/src/machi_flu1_client.erl b/src/machi_flu1_client.erl index 1bbc06d..331b0d1 100644 --- a/src/machi_flu1_client.erl +++ b/src/machi_flu1_client.erl @@ -24,7 +24,7 @@ -export([ append_chunk/4, append_chunk/5, - read_chunk/4, read_chunk/5, + read_chunk/5, read_chunk/6, checksum_list/2, checksum_list/3, list_files/1, list_files/2, quit/1 @@ -77,21 +77,22 @@ append_chunk(Host, TcpPort, EpochID, Prefix, Chunk) -> %% @doc Read a chunk of data of size `Size' from `File' at `Offset'. --spec read_chunk(port(), file_name(), file_offset(), chunk_size()) -> +-spec read_chunk(port(), epoch_id(), file_name(), file_offset(), chunk_size()) -> {ok, chunk_s()} | {error, term()}. -read_chunk(Sock, File, Offset, Size) +read_chunk(Sock, EpochID, File, Offset, Size) when Offset >= ?MINIMUM_OFFSET, Size >= 0 -> - read_chunk2(Sock, File, Offset, Size). + read_chunk2(Sock, EpochID, File, Offset, Size). %% @doc Read a chunk of data of size `Size' from `File' at `Offset'. --spec read_chunk(inet_host(), inet_port(), file_name(), file_offset(), chunk_size()) -> +-spec read_chunk(inet_host(), inet_port(), epoch_id(), + file_name(), file_offset(), chunk_size()) -> {ok, chunk_s()} | {error, term()}. -read_chunk(Host, TcpPort, File, Offset, Size) +read_chunk(Host, TcpPort, EpochID, File, Offset, Size) when Offset >= ?MINIMUM_OFFSET, Size >= 0 -> Sock = machi_util:connect(Host, TcpPort), try - read_chunk2(Sock, File, Offset, Size) + read_chunk2(Sock, EpochID, File, Offset, Size) after catch gen_tcp:close(Sock) end. @@ -244,11 +245,13 @@ append_chunk2(Sock, EpochID, Prefix0, Chunk0) -> {error, {badmatch, BadMatch, erlang:get_stacktrace()}} end. -read_chunk2(Sock, File0, Offset, Size) -> +read_chunk2(Sock, EpochID, File0, Offset, Size) -> + {EpochNum, EpochCSum} = EpochID, + EpochIDRaw = <>, File = machi_util:make_binary(File0), PrefixHex = machi_util:int_to_hexbin(Offset, 64), SizeHex = machi_util:int_to_hexbin(Size, 32), - CmdLF = [$R, 32, PrefixHex, 32, SizeHex, 32, File, 10], + CmdLF = [$R, 32, EpochIDRaw, PrefixHex, SizeHex, File, 10], ok = gen_tcp:send(Sock, CmdLF), case gen_tcp:recv(Sock, 3) of {ok, <<"OK\n">>} -> diff --git a/test/machi_flu1_test.erl b/test/machi_flu1_test.erl index e006adc..e23f33d 100644 --- a/test/machi_flu1_test.erl +++ b/test/machi_flu1_test.erl @@ -58,7 +58,8 @@ flu_smoke_test() -> {ok, {Off1,Len1,File1}} = ?FLU_C:append_chunk(Host, TcpPort, ?DUMMY_PV1_EPOCH, Prefix, Chunk1), - {ok, Chunk1} = ?FLU_C:read_chunk(Host, TcpPort, File1, Off1, Len1), + {ok, Chunk1} = ?FLU_C:read_chunk(Host, TcpPort, ?DUMMY_PV1_EPOCH, + File1, Off1, Len1), {ok, [{_,_,_}]} = ?FLU_C:checksum_list(Host, TcpPort, File1), {error, bad_arg} = ?FLU_C:append_chunk(Host, TcpPort, ?DUMMY_PV1_EPOCH, @@ -66,8 +67,10 @@ flu_smoke_test() -> {ok, [{_,File1}]} = ?FLU_C:list_files(Host, TcpPort), Len1 = size(Chunk1), {error, no_such_file} = ?FLU_C:read_chunk(Host, TcpPort, + ?DUMMY_PV1_EPOCH, File1, Off1*983, Len1), {error, partial_read} = ?FLU_C:read_chunk(Host, TcpPort, + ?DUMMY_PV1_EPOCH, File1, Off1, Len1*984), Chunk2 = <<"yo yo">>, @@ -77,10 +80,13 @@ flu_smoke_test() -> ok = ?FLU_C:write_chunk(Host, TcpPort, File2, Off2, Chunk2), {error, bad_arg} = ?FLU_C:write_chunk(Host, TcpPort, BadFile, Off2, Chunk2), - {ok, Chunk2} = ?FLU_C:read_chunk(Host, TcpPort, File2, Off2, Len2), + {ok, Chunk2} = ?FLU_C:read_chunk(Host, TcpPort, ?DUMMY_PV1_EPOCH, + File2, Off2, Len2), {error, no_such_file} = ?FLU_C:read_chunk(Host, TcpPort, + ?DUMMY_PV1_EPOCH, "no!!", Off2, Len2), {error, bad_arg} = ?FLU_C:read_chunk(Host, TcpPort, + ?DUMMY_PV1_EPOCH, BadFile, Off2, Len2), %% We know that File1 still exists. Pretend that we've done a