Skip to content

Commit 4a4667b

Browse files
evanjyycptt
andauthored
Update slices.SortFunc for Go 1.21 (#4706)
<!-- Describe what has changed in this PR --> **What changed?** The golang.org/x/exp module was updated to use the same function signature as Go 1.21's upcoming slices.SortFunc function. This changed the return value from a bool (less than) to an int (compare to). Update Temporal to the latest version and fix the uses. <!-- Tell your future self why have you made these changes --> **Why?** For more details about the upstream change, see the following issue and commit: - golang/go#61374 - https://cs.opensource.google/go/x/exp/+/302865e7556b4ae5de27248ce625d443ef4ad3ed <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** I ran the tests locally on my machine. <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** Worst case I may have switched the sort order somewhere accidentally. <!-- Is this PR a hotfix candidate or require that a notification be sent to the broader community? (Yes/No) --> **Is hotfix candidate?** No --------- Co-authored-by: Yichao Yang <[email protected]>
1 parent 46bbbf7 commit 4a4667b

File tree

7 files changed

+22
-21
lines changed

7 files changed

+22
-21
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ require (
5151
go.uber.org/fx v1.20.0
5252
go.uber.org/multierr v1.11.0
5353
go.uber.org/zap v1.24.0
54-
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
54+
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691
5555
golang.org/x/oauth2 v0.9.0
5656
golang.org/x/sync v0.3.0
5757
golang.org/x/time v0.3.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0
13701370
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
13711371
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
13721372
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
1373-
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
1374-
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
1373+
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 h1:/yRP+0AN7mf5DkD3BAI6TOFnd51gEoDEb8o35jIFtgw=
1374+
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
13751375
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
13761376
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
13771377
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

service/history/queues/action_pending_task_count.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ func (a *actionQueuePendingTask) gatherStatistics(
126126
})
127127
}
128128
for _, sliceList := range a.slicesPerNamespace {
129-
slices.SortFunc(sliceList, func(this, that Slice) bool {
129+
slices.SortFunc(sliceList, func(this, that Slice) int {
130130
thisMin := this.Scope().Range.InclusiveMin
131131
thatMin := that.Scope().Range.InclusiveMin
132-
return thisMin.CompareTo(thatMin) > 0
132+
// sort in largest to smallest order
133+
return thatMin.CompareTo(thisMin)
133134
})
134135
}
135136
}

service/history/queues/action_slice_count.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ func (a *actionSliceCount) pickCompactCandidates(
203203
candidates []compactCandidate,
204204
numSliceToCompact int,
205205
) map[Slice]struct{} {
206-
slices.SortFunc(candidates, func(this, that compactCandidate) bool {
207-
return this.distance.CompareTo(that.distance) < 0
206+
slices.SortFunc(candidates, func(this, that compactCandidate) int {
207+
return this.distance.CompareTo(that.distance)
208208
})
209209

210210
sliceToCompact := make(map[Slice]struct{}, numSliceToCompact)

service/history/queues/queue_scheduled_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ func (s *scheduledQueueSuite) TestPaginationFnProvider() {
143143
tasks.NewKey(r.InclusiveMin.FireTime.Add(time.Microsecond*10), rand.Int63()),
144144
tasks.NewKey(r.InclusiveMin.FireTime.Add(time.Second), rand.Int63()),
145145
}
146-
slices.SortFunc(testTaskKeys, func(k1, k2 tasks.Key) bool {
147-
return k1.CompareTo(k2) < 0
146+
slices.SortFunc(testTaskKeys, func(k1, k2 tasks.Key) int {
147+
return k1.CompareTo(k2)
148148
})
149149
shouldHaveNextPage := true
150150
if testTaskKeys[len(testTaskKeys)-1].CompareTo(r.ExclusiveMax) >= 0 {

service/history/queues/slice_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ func (s *sliceSuite) TestShrinkScope_ShrinkRange() {
337337
slice.iterators = s.randomIteratorsInRange(r, rand.Intn(2), nil)
338338

339339
executables := s.randomExecutablesInRange(r, 5)
340-
slices.SortFunc(executables, func(a, b Executable) bool {
341-
return a.GetKey().CompareTo(b.GetKey()) < 0
340+
slices.SortFunc(executables, func(a, b Executable) int {
341+
return a.GetKey().CompareTo(b.GetKey())
342342
})
343343

344344
firstPendingIdx := len(executables)
@@ -386,8 +386,8 @@ func (s *sliceSuite) TestShrinkScope_ShrinkPredicate() {
386386
slice.iterators = []Iterator{} // manually set iterators to be empty to trigger predicate update
387387

388388
executables := s.randomExecutablesInRange(r, 100)
389-
slices.SortFunc(executables, func(a, b Executable) bool {
390-
return a.GetKey().CompareTo(b.GetKey()) < 0
389+
slices.SortFunc(executables, func(a, b Executable) int {
390+
return a.GetKey().CompareTo(b.GetKey())
391391
})
392392

393393
pendingNamespaceID := []string{uuid.New(), uuid.New()}
@@ -442,8 +442,8 @@ func (s *sliceSuite) TestSelectTasks_NoError() {
442442
mockTasks = append(mockTasks, mockTask)
443443
}
444444

445-
slices.SortFunc(mockTasks, func(a, b tasks.Task) bool {
446-
return a.GetKey().CompareTo(b.GetKey()) < 0
445+
slices.SortFunc(mockTasks, func(a, b tasks.Task) int {
446+
return a.GetKey().CompareTo(b.GetKey())
447447
})
448448

449449
return mockTasks, nil, nil
@@ -491,8 +491,8 @@ func (s *sliceSuite) TestSelectTasks_Error_NoLoadedTasks() {
491491
mockTasks = append(mockTasks, mockTask)
492492
}
493493

494-
slices.SortFunc(mockTasks, func(a, b tasks.Task) bool {
495-
return a.GetKey().CompareTo(b.GetKey()) < 0
494+
slices.SortFunc(mockTasks, func(a, b tasks.Task) int {
495+
return a.GetKey().CompareTo(b.GetKey())
496496
})
497497

498498
return mockTasks, nil, nil
@@ -534,8 +534,8 @@ func (s *sliceSuite) TestSelectTasks_Error_WithLoadedTasks() {
534534
mockTasks = append(mockTasks, mockTask)
535535
}
536536

537-
slices.SortFunc(mockTasks, func(a, b tasks.Task) bool {
538-
return a.GetKey().CompareTo(b.GetKey()) < 0
537+
slices.SortFunc(mockTasks, func(a, b tasks.Task) int {
538+
return a.GetKey().CompareTo(b.GetKey())
539539
})
540540

541541
return mockTasks, []byte{1, 2, 3}, nil

service/history/queues/test_util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func NewRandomOrderedRangesInRange(
9898
ranges = append(ranges[1:], left, right)
9999
}
100100

101-
slices.SortFunc(ranges, func(a, b Range) bool {
102-
return a.InclusiveMin.CompareTo(b.InclusiveMin) < 0
101+
slices.SortFunc(ranges, func(a, b Range) int {
102+
return a.InclusiveMin.CompareTo(b.InclusiveMin)
103103
})
104104

105105
return ranges

0 commit comments

Comments
 (0)