resolveConflicts resolves a list of conflicted state entries. It takes two lists. The first is a list of all state entries that are not conflicted. The second is a list of all state entries that are conflicted A state entry is conflicted when there is more than one numeric event ID for the same stat
( ctx context.Context, notConflicted, conflicted []types.StateEntry, )
| 854 | // The returned list is sorted by state key tuple. |
| 855 | // Returns an error if there was a problem talking to the database. |
| 856 | func (v *StateResolution) resolveConflictsV2( |
| 857 | ctx context.Context, |
| 858 | notConflicted, conflicted []types.StateEntry, |
| 859 | ) ([]types.StateEntry, error) { |
| 860 | span, ctx := opentracing.StartSpanFromContext(ctx, "StateResolution.resolveConflictsV2") |
| 861 | defer span.Finish() |
| 862 | |
| 863 | estimate := len(conflicted) + len(notConflicted) |
| 864 | eventIDMap := make(map[string]types.StateEntry, estimate) |
| 865 | |
| 866 | // Load the conflicted events |
| 867 | conflictedEvents, conflictedEventMap, err := v.loadStateEvents(ctx, conflicted) |
| 868 | if err != nil { |
| 869 | return nil, err |
| 870 | } |
| 871 | for k, v := range conflictedEventMap { |
| 872 | eventIDMap[k] = v |
| 873 | } |
| 874 | |
| 875 | // Load the non-conflicted events |
| 876 | nonConflictedEvents, nonConflictedEventMap, err := v.loadStateEvents(ctx, notConflicted) |
| 877 | if err != nil { |
| 878 | return nil, err |
| 879 | } |
| 880 | for k, v := range nonConflictedEventMap { |
| 881 | eventIDMap[k] = v |
| 882 | } |
| 883 | |
| 884 | // For each conflicted event, we will add a new set of auth events. Auth |
| 885 | // events may be duplicated across these sets but that's OK. |
| 886 | authSets := make(map[string][]*gomatrixserverlib.Event, len(conflicted)) |
| 887 | authEvents := make([]*gomatrixserverlib.Event, 0, estimate*3) |
| 888 | gotAuthEvents := make(map[string]struct{}, estimate*3) |
| 889 | authDifference := make([]*gomatrixserverlib.Event, 0, estimate) |
| 890 | knownAuthEvents := make(map[string]types.Event, estimate*3) |
| 891 | |
| 892 | // For each conflicted event, let's try and get the needed auth events. |
| 893 | if err = func() error { |
| 894 | span, sctx := opentracing.StartSpanFromContext(ctx, "StateResolution.loadAuthEvents") |
| 895 | defer span.Finish() |
| 896 | |
| 897 | loader := authEventLoader{ |
| 898 | v: v, |
| 899 | lookupFromDB: make([]string, 0, len(conflictedEvents)*3), |
| 900 | lookupFromMem: make([]string, 0, len(conflictedEvents)*3), |
| 901 | lookedUpEvents: make([]types.Event, 0, len(conflictedEvents)*3), |
| 902 | eventMap: map[string]types.Event{}, |
| 903 | } |
| 904 | for _, conflictedEvent := range conflictedEvents { |
| 905 | // Work out which auth events we need to load. |
| 906 | key := conflictedEvent.EventID() |
| 907 | |
| 908 | // Store the newly found auth events in the auth set for this event. |
| 909 | var authEventMap map[string]types.StateEntry |
| 910 | authSets[key], authEventMap, err = loader.loadAuthEvents(sctx, conflictedEvent, knownAuthEvents) |
| 911 | if err != nil { |
| 912 | return err |
| 913 | } |
no test coverage detected