-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #612 from twmb/sticky
sticky: further improvements
- Loading branch information
Showing
4 changed files
with
100 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build go1.21 | ||
// +build go1.21 | ||
|
||
package sticky | ||
|
||
import "slices" | ||
|
||
func sortPartNums(ps memberPartitions) { | ||
slices.Sort(ps) | ||
} | ||
|
||
func (b *balancer) sortMemberByLiteralPartNum(memberNum int) { | ||
partNums := b.plan[memberNum] | ||
slices.SortFunc(partNums, func(lpNum, rpNum int32) int { | ||
ltNum, rtNum := b.partOwners[lpNum], b.partOwners[rpNum] | ||
li, ri := b.topicInfos[ltNum], b.topicInfos[rtNum] | ||
lt, rt := li.topic, ri.topic | ||
lp, rp := lpNum-li.partNum, rpNum-ri.partNum | ||
if lp < rp { | ||
return -1 | ||
} else if lp > rp { | ||
return 1 | ||
} else if lt < rt { | ||
return -1 | ||
} | ||
return 1 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build !go1.21 | ||
// +build !go1.21 | ||
|
||
package sticky | ||
|
||
import "sort" | ||
|
||
func sortPartNums(partNums memberPartitions) { | ||
sort.Slice(partNums, func(i, j int) bool { return partNums[i] < partNums[j] }) | ||
} | ||
|
||
func (b *balancer) sortMemberByLiteralPartNum(memberNum int) { | ||
partNums := b.plan[memberNum] | ||
sort.Slice(partNums, func(i, j int) bool { | ||
lpNum, rpNum := partNums[i], partNums[j] | ||
ltNum, rtNum := b.partOwners[lpNum], b.partOwners[rpNum] | ||
li, ri := b.topicInfos[ltNum], b.topicInfos[rtNum] | ||
lt, rt := li.topic, ri.topic | ||
lp, rp := lpNum-li.partNum, rpNum-ri.partNum | ||
return lp < rp || (lp == rp && lt < rt) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters