diff options
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). |