-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tools: support get all groups (tikv#6714) ref tikv#5895, ref tikv#6706 Signed-off-by: Ryan Leung <rleungx@gmail.com> * Fix data race between read APIs and finshiSplit/finishMerge in keyspace group manager (tikv#6723) close tikv#6721 checkTSOMerge and checkTSOSplit will read from kgm.getKeyspaceGroupMeta finishMergeKeyspaceGroup and finishSplitKeyspaceGroup will update kgm so just return a copy to avoid data race Signed-off-by: Bin Shi <binshi.bing@gmail.com> * tso: fix memory leak introduced by timer.After (tikv#6730) close tikv#6719, ref tikv#6720 Signed-off-by: lhy1024 <admin@liudos.us> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> * mcs, tso: fix split and split-range command bugs. (tikv#6732) close tikv#6687, close tikv#6731 Fix split and split-range command bugs. Signed-off-by: Bin Shi <binshi.bing@gmail.com> --------- Signed-off-by: Ryan Leung <rleungx@gmail.com> Signed-off-by: Bin Shi <binshi.bing@gmail.com> Co-authored-by: Ryan Leung <rleungx@gmail.com> Co-authored-by: Bin Shi <39923490+binshi-bing@users.noreply.github.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3b9ca3f
commit 2d22ba6
Showing
10 changed files
with
269 additions
and
57 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133 | ||
|
||
package timerpool | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
) | ||
|
||
// GlobalTimerPool is a global pool for reusing *time.Timer. | ||
var GlobalTimerPool TimerPool | ||
|
||
// TimerPool is a wrapper of sync.Pool which caches *time.Timer for reuse. | ||
type TimerPool struct { | ||
pool sync.Pool | ||
} | ||
|
||
// Get returns a timer with a given duration. | ||
func (tp *TimerPool) Get(d time.Duration) *time.Timer { | ||
if v := tp.pool.Get(); v != nil { | ||
timer := v.(*time.Timer) | ||
timer.Reset(d) | ||
return timer | ||
} | ||
return time.NewTimer(d) | ||
} | ||
|
||
// Put tries to call timer.Stop() before putting it back into pool, | ||
// if the timer.Stop() returns false (it has either already expired or been stopped), | ||
// have a shot at draining the channel with residual time if there is one. | ||
func (tp *TimerPool) Put(timer *time.Timer) { | ||
if !timer.Stop() { | ||
select { | ||
case <-timer.C: | ||
default: | ||
} | ||
} | ||
tp.pool.Put(timer) | ||
} |
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,70 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133 | ||
|
||
package timerpool | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestTimerPool(t *testing.T) { | ||
var tp TimerPool | ||
|
||
for i := 0; i < 100; i++ { | ||
timer := tp.Get(20 * time.Millisecond) | ||
|
||
select { | ||
case <-timer.C: | ||
t.Errorf("timer expired too early") | ||
continue | ||
default: | ||
} | ||
|
||
select { | ||
case <-time.After(100 * time.Millisecond): | ||
t.Errorf("timer didn't expire on time") | ||
case <-timer.C: | ||
} | ||
|
||
tp.Put(timer) | ||
} | ||
} | ||
|
||
const timeout = 10 * time.Millisecond | ||
|
||
func BenchmarkTimerUtilization(b *testing.B) { | ||
b.Run("TimerWithPool", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
t := GlobalTimerPool.Get(timeout) | ||
GlobalTimerPool.Put(t) | ||
} | ||
}) | ||
b.Run("TimerWithoutPool", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
t := time.NewTimer(timeout) | ||
t.Stop() | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkTimerPoolParallel(b *testing.B) { | ||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
t := GlobalTimerPool.Get(timeout) | ||
GlobalTimerPool.Put(t) | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkTimerNativeParallel(b *testing.B) { | ||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
t := time.NewTimer(timeout) | ||
t.Stop() | ||
} | ||
}) | ||
} |
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
Oops, something went wrong.