couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxepal <...@git.apache.org>
Subject [GitHub] couchdb-fabric pull request: 2526 pending updates info
Date Tue, 30 Dec 2014 20:34:48 GMT
Github user kxepal commented on a diff in the pull request:

    https://github.com/apache/couchdb-fabric/pull/9#discussion_r22363589
  
    --- Diff: src/fabric_group_info.erl ---
    @@ -38,41 +39,74 @@ go(DbName, #doc{id=DDocId}) ->
             rexi_monitor:stop(RexiMon)
         end.
     
    -handle_message({rexi_DOWN, _, {_,NodeRef},_}, _Shard, {Counters, Acc}) ->
    +handle_message({rexi_DOWN, _, {_,NodeRef},_}, _Shard,
    +        {Counters, Acc, Ushards}) ->
         case fabric_util:remove_down_workers(Counters, NodeRef) of
         {ok, NewCounters} ->
    -        {ok, {NewCounters, Acc}};
    +        {ok, {NewCounters, Acc, Ushards}};
         error ->
             {error, {nodedown, <<"progress not possible">>}}
         end;
     
    -handle_message({rexi_EXIT, Reason}, Shard, {Counters, Acc}) ->
    +handle_message({rexi_EXIT, Reason}, Shard, {Counters, Acc, Ushards}) ->
         NewCounters = lists:keydelete(Shard, #shard.ref, Counters),
         case fabric_view:is_progress_possible(NewCounters) of
         true ->
    -        {ok, {NewCounters, Acc}};
    +        {ok, {NewCounters, Acc, Ushards}};
         false ->
             {error, Reason}
         end;
     
    -handle_message({ok, Info}, Shard, {Counters, Acc}) ->
    -    case fabric_dict:lookup_element(Shard, Counters) of
    -    undefined ->
    -        % already heard from someone else in this range
    -        {ok, {Counters, Acc}};
    -    nil ->
    -        C1 = fabric_dict:store(Shard, ok, Counters),
    -        C2 = fabric_view:remove_overlapping_shards(Shard, C1),
    -        case fabric_dict:any(nil, C2) of
    -        true ->
    -            {ok, {C2, [Info|Acc]}};
    -        false ->
    -            {stop, merge_results(lists:flatten([Info|Acc]))}
    -        end
    +handle_message({ok, Info}, Shard, {Counters0, Acc, Ushards}) ->
    +    NewAcc = append_result(Info, Shard, Acc, Ushards),
    +    Counters = fabric_dict:store(Shard, ok, Counters0),
    +    case is_complete(Counters) of
    +    false ->
    +        {ok, {Counters, NewAcc, Ushards}};
    +    true ->
    +        Pending = aggregate_pending(NewAcc),
    +        Infos = get_infos(NewAcc),
    +        Results = [{updates_pending, {Pending}}|merge_results(Infos)],
    +        {stop, Results}
         end;
     handle_message(_, _, Acc) ->
         {ok, Acc}.
     
    +acc_init(Workers, Ushards) ->
    +    Set = sets:from_list([{Id, N} || #shard{name = Id, node = N} <- Ushards]),
    +    {fabric_dict:init(Workers, nil), dict:new(), Set}.
    +
    +is_complete(Counters) ->
    +    not fabric_dict:any(nil, Counters).
    +
    +append_result(Info, #shard{name = Name, node = Node}, Acc, Ushards) ->
    +    IsPreferred = sets:is_element({Name, Node}, Ushards),
    +    dict:append(Name, {Node, IsPreferred, Info}, Acc).
    +
    +get_infos(Acc) ->
    +    Values = [V || {_, V} <- dict:to_list(Acc)],
    +    lists:flatten([Info || {_Node, _Pref, Info} <- lists:flatten(Values)]).
    +
    +aggregate_pending(Dict) ->
    +    {Preferred, Total, Minimum} =
    +        dict:fold(fun(_Name, Results, {P, T, M}) ->
    +            {Preferred, Total, Minimum} = calculate_pending(Results),
    +            {P + Preferred, T + Total, M + Minimum}
    +        end, {0, 0, 0}, Dict),
    +    [{minimum, Minimum},
    +    {preferred, Preferred},
    --- End diff --
    
    Indention. Container elements should be aligned by elements.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message