Commit 8de9f0fe authored by Maxim Ivanov's avatar Maxim Ivanov
Browse files

chore(matchmaker): allow mutual index conflict check

parent 9e6ba190
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ func (m *LocalMatchmaker) Process() {
				continue
			}

			if m.doesConflictWithIndex(threshold, indexReader, hitIndex, index) {
			if m.doesConflictWithIndex(threshold, indexReader, hitIndex, index, false) {
				continue
			}

@@ -536,7 +536,8 @@ func (m *LocalMatchmaker) Process() {
// check if fromIndex conflict with toIndex
// index A conflicts with index B if they have overlapping sessions
// or A.Query won't select B due to properties mismatch
func (m *LocalMatchmaker) doesConflictWithIndex(threshold bool, indexReader *bluge.Reader, fromIndex *MatchmakerIndex, toIndex *MatchmakerIndex) bool {
// If reverse is true, perform reverse check for a full mutual conflict check
func (m *LocalMatchmaker) doesConflictWithIndex(threshold bool, indexReader *bluge.Reader, fromIndex *MatchmakerIndex, toIndex *MatchmakerIndex, reverseCheck bool) bool {
	if !threshold && m.config.GetMatchmaker().RevPrecision {
		outerMutualMatch, err := validateMatch(m, indexReader, fromIndex.ParsedQuery, fromIndex.Ticket, toIndex.Ticket)
		if err != nil {
@@ -546,6 +547,18 @@ func (m *LocalMatchmaker) doesConflictWithIndex(threshold bool, indexReader *blu
			// This search hit is not a mutual match with the outer ticket.
			return true
		}

		if reverseCheck {
			outerMutualMatch, err := validateMatch(m, indexReader, toIndex.ParsedQuery, toIndex.Ticket, fromIndex.Ticket)
			if err != nil {
				m.logger.Error("error validating mutual match", zap.Error(err))
				return true
			} else if !outerMutualMatch {
				// This search hit is not a mutual match with the outer ticket.
				return true
			}

		}
	}

	// Check if there are overlapping session IDs, and if so these tickets are ineligible to match together.