diff options
author | Magnus Ahltorp <map@kth.se> | 2017-07-28 13:38:43 +0200 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2017-07-28 13:38:43 +0200 |
commit | 11e0bdd000dad72ed4c46d419e253ee0caefbc2b (patch) | |
tree | 3c886c080433ce70bd23d682c730d232f2e87a3b /merge/src/merge_fetch_ctrl.erl | |
parent | 489df8ecaf16ca7429eb15b31ffbe6f686f5b0d1 (diff) |
Still WIPmergefetch
Diffstat (limited to 'merge/src/merge_fetch_ctrl.erl')
-rw-r--r-- | merge/src/merge_fetch_ctrl.erl | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/merge/src/merge_fetch_ctrl.erl b/merge/src/merge_fetch_ctrl.erl index 6c055df..49fe043 100644 --- a/merge/src/merge_fetch_ctrl.erl +++ b/merge/src/merge_fetch_ctrl.erl @@ -69,7 +69,7 @@ handle_call({newentries, List, Node}, _From, #state{tofetch = ToFetch} = State) {true, {Hash, undefined}} end end, List), - {noreply, State#state{tofetch = [ToFetch | NewEntries]}}; + {reply, ok, State#state{tofetch = ToFetch ++ NewEntries}}; handle_call({entriestofetch, Node, NMax}, _From, #state{tofetch = ToFetch} = State) -> @@ -79,12 +79,12 @@ handle_call({entriestofetch, Node, NMax}, _From, handle_call({fetchstatus, Entry, success}, _From, #state{tofetch = ToFetch} = State) -> NewToFetch = fetch_success(ToFetch, Entry), - {noreply, State#state{tofetch = NewToFetch}}; + {reply, ok, State#state{tofetch = NewToFetch}}; handle_call({fetchstatus, Entry, failure}, _From, #state{tofetch = ToFetch} = State) -> NewToFetch = fetch_failure(ToFetch, Entry), - {noreply, State#state{tofetch = NewToFetch}}. + {reply, ok, State#state{tofetch = NewToFetch}}. handle_cast(_Request, State) -> {noreply, State}. @@ -97,8 +97,18 @@ terminate(_Reason, _State) -> ok. %%%%%%%%%%%%%%%%%%%% + +write_currentsize(CurrentSize, LastHash) -> + {ok, CurrentSizeFile} = application:get_env(plop, fetched_path), + CurrentSizeData = {struct, [{index, CurrentSize - 1}, {hash, list_to_binary(hex:bin_to_hexstr(LastHash))}]}, + ok = atomic:replacefile(CurrentSizeFile, mochijson2:encode(CurrentSizeData)). + -spec fetch_success(list(), binary()) -> list(). fetch_success(ToFetch, Entry) -> + CurrentPos = db:indexsize(), + db:add_index_nosync_noreverse(Entry, CurrentPos), + db:index_sync(), + write_currentsize(CurrentPos + 1, Entry), true = ets:insert(?MISSINGENTRIES_TABLE, {Entry, []}), keydelete(Entry, 1, ToFetch). @@ -116,7 +126,7 @@ fetch_failure(ToFetch, Entry) -> etf(ToFetch, Node, NMax) -> etf(ToFetch, Node, NMax, [], []). etf(ToFetchRest, _Node, 0, AccToFetch, AccEntries) -> - {[reverse(AccToFetch) | ToFetchRest], reverse(AccEntries)}; + {reverse(AccToFetch) ++ ToFetchRest, reverse(AccEntries)}; etf([], Node, _NMax, AccToFetch, AccEntries) -> etf([], Node, 0, AccToFetch, AccEntries); etf([H|T], Node, NMax, AccToFetch, AccEntries) -> @@ -142,8 +152,10 @@ etf([H|T], Node, NMax, AccToFetch, AccEntries) -> not_fetched(List) -> filter(fun(H) -> case ets:match(?MISSINGENTRIES_TABLE, {H, '$1'}) of - [[[]]] -> false; % Match: Empty list. - _ -> true + [] -> + true; % Match: Empty list. + E -> + false end end, List). |