Unverified Commit 1f0a170b authored by Andrei Mihu's avatar Andrei Mihu Committed by GitHub
Browse files

Ensure the matchmaker always correctly prefers matches closer to the maximum count. (#809)

parent 80879a3e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Fix incorrect link device behaviour in JavaScript runtime.
- Fix JS runtime multi-update execution consistency when part of the operation fails.
- Fix handling of wallet ledger lookups with no limit during account exports.
- Ensure maximum count is accounted for in matchmaker mutual match checks.
- Ensure the matchmaker always correctly prefers matches closer to the maximum count.

## [3.10.0] - 2021-12-16
### Added
+2 −2
Original line number Diff line number Diff line
@@ -19,14 +19,14 @@ import (
	"context"
	"encoding/gob"
	"fmt"
	"go.uber.org/atomic"
	"go.uber.org/zap"
	"strings"
	"testing"

	"github.com/blugelabs/bluge"
	"github.com/gofrs/uuid"
	"github.com/heroiclabs/nakama-common/runtime"
	"go.uber.org/atomic"
	"go.uber.org/zap"
	"google.golang.org/protobuf/types/known/wrapperspb"
)

+20 −3
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ func (m *LocalMatchmaker) process(batch *index.Batch) {

		// Form possible combinations, in case multiple matches might be suitable.
		entryCombos := make([][]*MatchmakerEntry, 0, 5)
		for _, hit := range blugeMatches.Hits {
		for hitCounter, hit := range blugeMatches.Hits {
			if hit.ID == ticket {
				// Skip the current ticket.
				continue
@@ -278,7 +278,7 @@ func (m *LocalMatchmaker) process(batch *index.Batch) {
				m.logger.Error("error validating mutual match", zap.Error(err))
				continue
			} else if !outerMutualMatch {
				// this search hit is not a mutual match with the outer ticket
				// This search hit is not a mutual match with the outer ticket.
				continue
			}

@@ -365,7 +365,12 @@ func (m *LocalMatchmaker) process(batch *index.Batch) {
				foundComboIdx = len(entryCombos) - 1
			}

			if l := len(foundCombo) + index.Count; l == index.MaxCount || (lastInterval && l >= index.MinCount && l <= index.MaxCount) {
			// The combo is considered match-worthy if either the max count has been satisfied, or ALL of these conditions are met:
			// * It is the last interval for this active index.
			// * The combo at least satisfies the min count.
			// * The combo does not exceed the max count.
			// * There are no further hits that may further fill the found combo, so we get as close as possible to the max count.
			if l := len(foundCombo) + index.Count; l == index.MaxCount || (lastInterval && l >= index.MinCount && l <= index.MaxCount && hitCounter >= len(blugeMatches.Hits)-1) {
				// Check that the minimum count that satisfies the current index is also good enough for all matched entries.
				var minCountFailed bool
				for _, e := range foundCombo {
@@ -378,6 +383,18 @@ func (m *LocalMatchmaker) process(batch *index.Batch) {
					continue
				}

				// Check that the maximum count that satisfies the current index is also good enough for all matched entries.
				var maxCountFailed bool
				for _, e := range foundCombo {
					if foundIndex, ok := m.indexes[e.Ticket]; ok && foundIndex.MaxCount < l {
						maxCountFailed = true
						break
					}
				}
				if maxCountFailed {
					continue
				}

				// Found a suitable match.
				entries, ok := m.entries[ticket]
				if !ok {
+3 −2
Original line number Diff line number Diff line
@@ -15,11 +15,12 @@
package server

import (
	"strings"
	"testing"

	"github.com/dop251/goja"
	"go.uber.org/zap"
	"go.uber.org/zap/zaptest/observer"
	"strings"
	"testing"
)

func TestJsObjectFreeze(t *testing.T) {