Skip to content

Commit

Permalink
Resolve matchmaker regression
Browse files Browse the repository at this point in the history
Resolve an issue that would cause the matchmaker to not match two
suitable opponents.

Resolves #827
  • Loading branch information
sesposito committed May 18, 2022
1 parent 9e01784 commit 7e46dec
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions server/matchmaker.go
Expand Up @@ -238,7 +238,7 @@ func (m *LocalMatchmaker) process(batch *index.Batch) {

for ticket, index := range m.activeIndexes {
index.Intervals++
lastInterval := index.Intervals > m.config.GetMatchmaker().MaxIntervals || index.MinCount == index.MaxCount
lastInterval := index.Intervals >= m.config.GetMatchmaker().MaxIntervals || index.MinCount == index.MaxCount
if lastInterval {
// Drop from active indexes if it has reached its max intervals, or if its min/max counts are equal. In the
// latter case keeping it active would have the same result as leaving it in the pool, so this saves work.
Expand Down Expand Up @@ -304,13 +304,17 @@ func (m *LocalMatchmaker) process(batch *index.Batch) {

// Form possible combinations, in case multiple matches might be suitable.
entryCombos := make([][]*MatchmakerEntry, 0, 5)
lastHitCounter := len(blugeMatches.Hits) - 1
for hitCounter, hit := range blugeMatches.Hits {

for idx, hit := range blugeMatches.Hits {
if hit.ID == ticket {
// Skip the current ticket.
continue
// Remove the current ticket.
blugeMatches.Hits = append(blugeMatches.Hits[:idx], blugeMatches.Hits[idx+1:]...)
break
}
}

lastHitCounter := len(blugeMatches.Hits) - 1
for hitCounter, hit := range blugeMatches.Hits {
hitIndex, ok := m.indexes[hit.ID]
if !ok {
// Ticket did not exist, should not happen.
Expand Down Expand Up @@ -488,12 +492,8 @@ func (m *LocalMatchmaker) process(batch *index.Batch) {

// Remove all entries/indexes that have just matched. It must be done here so any following process iterations
// cannot pick up the same tickets to match against.
ticketsToDelete := make(map[string]struct{}, len(currentMatchedEntries))
for _, entry := range currentMatchedEntries {
if _, ok := ticketsToDelete[entry.Ticket]; !ok {
batch.Delete(bluge.Identifier(entry.Ticket))
ticketsToDelete[entry.Ticket] = struct{}{}
}
batch.Delete(bluge.Identifier(entry.Ticket))
delete(m.entries, entry.Ticket)
delete(m.indexes, entry.Ticket)
delete(m.activeIndexes, entry.Ticket)
Expand Down

0 comments on commit 7e46dec

Please sign in to comment.