Skip to content

Commit d75733f

Browse files
ti-chi-botHuSharp
andauthored
*: add defer to logs the panic reason and stack (tikv#6123) (tikv#6153)
ref tikv#6099, ref tikv#6123 add defer logs the panic reason and stack Signed-off-by: husharp <jinhao.hu@pingcap.com> Co-authored-by: husharp <jinhao.hu@pingcap.com>
1 parent 39a4de6 commit d75733f

File tree

6 files changed

+15
-0
lines changed

6 files changed

+15
-0
lines changed

pkg/cache/ttl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"time"
2020

2121
"github.com/pingcap/log"
22+
"github.com/tikv/pd/pkg/logutil"
2223
"github.com/tikv/pd/pkg/syncutil"
2324
"go.uber.org/zap"
2425
)
@@ -142,6 +143,7 @@ func (c *ttlCache) Clear() {
142143
}
143144

144145
func (c *ttlCache) doGC() {
146+
defer logutil.LogPanic()
145147
ticker := time.NewTicker(c.gcInterval)
146148
defer ticker.Stop()
147149

pkg/systimemon/systimemon.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import (
2020

2121
"github.com/pingcap/log"
2222
"github.com/tikv/pd/pkg/errs"
23+
"github.com/tikv/pd/pkg/logutil"
2324
"go.uber.org/zap"
2425
)
2526

2627
// StartMonitor calls systimeErrHandler if system time jump backward.
2728
func StartMonitor(ctx context.Context, now func() time.Time, systimeErrHandler func()) {
29+
defer logutil.LogPanic()
2830
log.Info("start system time monitor")
2931
tick := time.NewTicker(100 * time.Millisecond)
3032
defer tick.Stop()

server/election/lease.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/pingcap/log"
2323
"github.com/tikv/pd/pkg/errs"
2424
"github.com/tikv/pd/pkg/etcdutil"
25+
"github.com/tikv/pd/pkg/logutil"
2526
"github.com/tikv/pd/pkg/typeutil"
2627
"go.etcd.io/etcd/clientv3"
2728
"go.uber.org/zap"
@@ -129,6 +130,7 @@ func (l *lease) keepAliveWorker(ctx context.Context, interval time.Duration) <-c
129130
ch := make(chan time.Time)
130131

131132
go func() {
133+
defer logutil.LogPanic()
132134
ticker := time.NewTicker(interval)
133135
defer ticker.Stop()
134136

@@ -137,6 +139,7 @@ func (l *lease) keepAliveWorker(ctx context.Context, interval time.Duration) <-c
137139

138140
for {
139141
go func() {
142+
defer logutil.LogPanic()
140143
start := time.Now()
141144
ctx1, cancel := context.WithTimeout(ctx, l.leaseTimeout)
142145
defer cancel()

server/region_syncer/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/pingcap/log"
2525
"github.com/tikv/pd/pkg/errs"
2626
"github.com/tikv/pd/pkg/grpcutil"
27+
"github.com/tikv/pd/pkg/logutil"
2728
"github.com/tikv/pd/server/core"
2829
"go.uber.org/zap"
2930
"google.golang.org/grpc"
@@ -116,6 +117,7 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) {
116117
ctx := s.mu.clientCtx
117118

118119
go func() {
120+
defer logutil.LogPanic()
119121
defer s.wg.Done()
120122
// used to load region from kv storage to cache storage.
121123
bc := s.server.GetBasicCluster()

server/tso/allocator_manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/tikv/pd/pkg/errs"
3131
"github.com/tikv/pd/pkg/etcdutil"
3232
"github.com/tikv/pd/pkg/grpcutil"
33+
"github.com/tikv/pd/pkg/logutil"
3334
"github.com/tikv/pd/pkg/slice"
3435
"github.com/tikv/pd/pkg/syncutil"
3536
"github.com/tikv/pd/server/config"
@@ -341,6 +342,7 @@ func (am *AllocatorManager) getLocalTSOAllocatorPath() string {
341342

342343
// similar logic with leaderLoop in server/server.go
343344
func (am *AllocatorManager) allocatorLeaderLoop(ctx context.Context, allocator *LocalTSOAllocator) {
345+
defer logutil.LogPanic()
344346
defer log.Info("server is closed, return local tso allocator leader loop",
345347
zap.String("dc-location", allocator.GetDCLocation()),
346348
zap.String("local-tso-allocator-name", am.member.Member().Name))
@@ -592,6 +594,7 @@ func (am *AllocatorManager) allocatorUpdater() {
592594

593595
// updateAllocator is used to update the allocator in the group.
594596
func (am *AllocatorManager) updateAllocator(ag *allocatorGroup) {
597+
defer logutil.LogPanic()
595598
defer am.wg.Done()
596599
select {
597600
case <-ag.ctx.Done():
@@ -642,6 +645,7 @@ func (am *AllocatorManager) allocatorPatroller(serverCtx context.Context) {
642645
// ClusterDCLocationChecker collects all dc-locations of a cluster, computes some related info
643646
// and stores them into the DCLocationInfo, then finally writes them into am.mu.clusterDCLocations.
644647
func (am *AllocatorManager) ClusterDCLocationChecker() {
648+
defer logutil.LogPanic()
645649
// Wait for the PD leader to be elected out.
646650
if am.member.GetLeader() == nil {
647651
return

server/tso/global_allocator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/pingcap/kvproto/pkg/pdpb"
2626
"github.com/pingcap/log"
2727
"github.com/tikv/pd/pkg/errs"
28+
"github.com/tikv/pd/pkg/logutil"
2829
"github.com/tikv/pd/pkg/slice"
2930
"github.com/tikv/pd/pkg/tsoutil"
3031
"github.com/tikv/pd/pkg/typeutil"
@@ -334,6 +335,7 @@ func (gta *GlobalTSOAllocator) SyncMaxTS(
334335
// Send SyncMaxTSRequest to all allocator leaders concurrently.
335336
wg.Add(1)
336337
go func(ctx context.Context, conn *grpc.ClientConn, respCh chan<- *syncResp) {
338+
defer logutil.LogPanic()
337339
defer wg.Done()
338340
syncMaxTSResp := &syncResp{}
339341
syncCtx, cancel := context.WithTimeout(ctx, rpcTimeout)

0 commit comments

Comments
 (0)