Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sync.pool to contain our token map in conflictingTokensExist #84

Merged
merged 5 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* [ENHANCEMENT] Replace go-kit/kit/log with go-kit/log. #52
* [ENHANCEMENT] Add spanlogger package. #42
* [ENHANCEMENT] Add runutil.CloseWithLogOnErr function. #58
* [ENHANCEMENT] Optimise memberlist receive path when used as a backing store for rings with a large number of members. #76 #77
* [ENHANCEMENT] Optimise memberlist receive path when used as a backing store for rings with a large number of members. #76 #77 #84
* [ENHANCEMENT] Memberlist: prepare the data to send on the write before starting counting the elapsed time for `-memberlist.packet-write-timeout`, in order to reduce chances we hit the timeout when sending a packet to other node. #89
* [BUGFIX] spanlogger: Support multiple tenant IDs. #59
* [BUGFIX] Memberlist: fixed corrupted packets when sending compound messages with more than 255 messages or messages bigger than 64KB. #85
20 changes: 12 additions & 8 deletions ring/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"container/heap"
"fmt"
"sort"
"sync"
"time"

"github.com/gogo/protobuf/proto"
Expand Down Expand Up @@ -302,19 +303,22 @@ func normalizeIngestersMap(inputRing *Desc) {
}
}

func conflictingTokensExist(normalizedIngesters map[string]InstanceDesc) bool {
count := 0
for _, ing := range normalizedIngesters {
count += len(ing.Tokens)
}
var tokenMapPool = sync.Pool{New: func() interface{} { return make(map[uint32]struct{}) }}

tokensMap := make(map[uint32]bool, count)
func conflictingTokensExist(normalizedIngesters map[string]InstanceDesc) bool {
tokensMap := tokenMapPool.Get().(map[uint32]struct{})
defer func() {
for k := range tokensMap {
delete(tokensMap, k)
}
tokenMapPool.Put(tokensMap)
stevesg marked this conversation as resolved.
Show resolved Hide resolved
}()
for _, ing := range normalizedIngesters {
for _, t := range ing.Tokens {
if tokensMap[t] {
if _, contains := tokensMap[t]; contains {
return true
}
tokensMap[t] = true
tokensMap[t] = struct{}{}
}
}
return false
Expand Down