Trim command and GC prototype implementation #32

Merged
kuenishi merged 4 commits from ku/trim-and-gc into master 2015-10-29 06:07:10 +00:00
2 changed files with 7 additions and 3 deletions
Showing only changes of commit 028135d927 - Show all commits

View file

@ -600,8 +600,6 @@ do_trim_chunk2(File, Offset, Size, Depth, STime, TO,
Proxy = orddict:fetch(HeadFLU, PD), Proxy = orddict:fetch(HeadFLU, PD),
case ?FLU_PC:trim_chunk(Proxy, EpochID, File, Offset, Size, ?TIMEOUT) of case ?FLU_PC:trim_chunk(Proxy, EpochID, File, Offset, Size, ?TIMEOUT) of
ok -> ok ->
%% From this point onward, we use the same code & logic path as
%% append does.
do_trim_midtail(RestFLUs, undefined, File, Offset, Size, do_trim_midtail(RestFLUs, undefined, File, Offset, Size,
[HeadFLU], 0, STime, TO, S); [HeadFLU], 0, STime, TO, S);
{error, trimmed} -> {error, trimmed} ->

View file

@ -1,6 +1,6 @@
-module(machi_plist). -module(machi_plist).
%%% @doc persistent list of binaries that support mutual exclusion %%% @doc persistent list of binaries
-export([open/2, close/1, find/2, add/2]). -export([open/2, close/1, find/2, add/2]).
@ -19,6 +19,9 @@
-spec open(file:filename_all(), proplists:proplist()) -> -spec open(file:filename_all(), proplists:proplist()) ->
{ok, plist()} | {error, file:posix()}. {ok, plist()} | {error, file:posix()}.
open(Filename, _Opt) -> open(Filename, _Opt) ->
%% TODO: This decode could fail if the file didn't finish writing
%% whole contents, which should be fixed by some persistent
%% solution.
List = case file:read_file(Filename) of List = case file:read_file(Filename) of
{ok, <<>>} -> []; {ok, <<>>} -> [];
{ok, Bin} -> binary_to_term(Bin); {ok, Bin} -> binary_to_term(Bin);
@ -48,6 +51,9 @@ add(Plist = #machi_plist{list=List0, fd=Fd}, Name) ->
{ok, Plist}; {ok, Plist};
false -> false ->
List = lists:append(List0, [Name]), List = lists:append(List0, [Name]),
%% TODO: partial write could break the file with other
%% persistent info (even lose data of trimmed states);
%% needs a solution.
case file:pwrite(Fd, 0, term_to_binary(List)) of case file:pwrite(Fd, 0, term_to_binary(List)) of
ok -> ok ->
{ok, Plist#machi_plist{list=List}}; {ok, Plist#machi_plist{list=List}};