diff --git a/.golangci.yml b/.golangci.yml index d5b2e4e7f5a..77fa6ec46ac 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,7 +21,6 @@ linters-settings: disabled-checks: - regexpMust - appendAssign - - exitAfterDefer - ifElseChain gosec: # To specify a set of rules to explicitly exclude. diff --git a/client/pd_service_discovery_test.go b/client/pd_service_discovery_test.go index 44171873b1a..93d02459a01 100644 --- a/client/pd_service_discovery_test.go +++ b/client/pd_service_discovery_test.go @@ -107,10 +107,10 @@ func newTestServer(isLeader bool) *testServer { func (s *testServer) run() { lis, err := net.Listen("tcp", s.addr) if err != nil { - log.Fatalf("failed to serve: %v", err) + log.Panicf("failed to serve: %v", err) } if err := s.grpcServer.Serve(lis); err != nil { - log.Fatalf("failed to serve: %v", err) + log.Panicf("failed to serve: %v", err) } } diff --git a/client/testutil/tempurl.go b/client/testutil/tempurl.go index ac8f29fa345..7a75b96c05f 100644 --- a/client/testutil/tempurl.go +++ b/client/testutil/tempurl.go @@ -37,19 +37,19 @@ func Alloc() string { } time.Sleep(time.Second) } - log.Fatal("failed to alloc test URL") + log.Panic("failed to alloc test URL") return "" } func tryAllocTestURL() string { l, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { - log.Fatal("listen failed", zap.Error(err)) + log.Panic("listen failed", zap.Error(err)) } addr := fmt.Sprintf("http://%s", l.Addr()) err = l.Close() if err != nil { - log.Fatal("close failed", zap.Error(err)) + log.Panic("close failed", zap.Error(err)) } testAddrMutex.Lock() diff --git a/client/tso_client.go b/client/tso_client.go index 5e221eae478..f9f826074ea 100644 --- a/client/tso_client.go +++ b/client/tso_client.go @@ -232,7 +232,7 @@ func (c *tsoClient) GetTSOAllocatorServingURLByDCLocation(dcLocation string) (st func (c *tsoClient) GetTSOAllocatorClientConnByDCLocation(dcLocation string) (*grpc.ClientConn, string) { url, ok := c.tsoAllocators.Load(dcLocation) if !ok { - log.Fatal("[tso] the allocator leader should exist", zap.String("dc-location", dcLocation)) + log.Panic("[tso] the allocator leader should exist", zap.String("dc-location", dcLocation)) } cc, ok := c.svcDiscovery.GetClientConns().Load(url) if !ok { diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 553b93ed0ef..818abd577d6 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -232,7 +232,7 @@ func start(cmd *cobra.Command, args []string, services ...string) { if err == nil { log.ReplaceGlobals(cfg.Logger, cfg.LogProps) } else { - log.Fatal("initialize logger error", errs.ZapError(err)) + log.Panic("initialize logger error", errs.ZapError(err)) } // Flushing any buffered log entries defer log.Sync() @@ -254,7 +254,7 @@ func start(cmd *cobra.Command, args []string, services ...string) { err = join.PrepareJoinCluster(cfg) if err != nil { - log.Fatal("join meet error", errs.ZapError(err)) + log.Panic("join meet error", errs.ZapError(err)) } // Creates server. @@ -266,7 +266,7 @@ func start(cmd *cobra.Command, args []string, services ...string) { serviceBuilders = append(serviceBuilders, dashboard.GetServiceBuilders()...) svr, err := server.CreateServer(ctx, cfg, services, serviceBuilders...) if err != nil { - log.Fatal("create server failed", errs.ZapError(err)) + log.Panic("create server failed", errs.ZapError(err)) } sc := make(chan os.Signal, 1) @@ -283,7 +283,7 @@ func start(cmd *cobra.Command, args []string, services ...string) { }() if err := svr.Run(); err != nil { - log.Fatal("run server failed", errs.ZapError(err)) + log.Panic("run server failed", errs.ZapError(err)) } <-ctx.Done() diff --git a/pkg/dashboard/distroutil/distro.go b/pkg/dashboard/distroutil/distro.go index 9eb1a2eb31b..650e47bdc06 100644 --- a/pkg/dashboard/distroutil/distro.go +++ b/pkg/dashboard/distroutil/distro.go @@ -33,7 +33,7 @@ const ( func MustGetResPath() string { exePath, err := os.Executable() if err != nil { - log.Fatal("failed to read the execution path", zap.Error(err)) + log.Panic("failed to read the execution path", zap.Error(err)) return "" } return path.Join(path.Dir(exePath), resFolderName) @@ -46,7 +46,7 @@ func MustLoadAndReplaceStrings() { resPath := MustGetResPath() strings, err := distro.ReadResourceStringsFromFile(path.Join(resPath, stringsFileName)) if err != nil { - log.Fatal("failed to load distro strings", zap.Error(err)) + log.Panic("failed to load distro strings", zap.Error(err)) } log.Info("using distribution strings", zap.Any("strings", strings)) distro.ReplaceGlobal(strings) diff --git a/pkg/mcs/resourcemanager/server/server.go b/pkg/mcs/resourcemanager/server/server.go index 708a11344d4..dbdf003dfad 100644 --- a/pkg/mcs/resourcemanager/server/server.go +++ b/pkg/mcs/resourcemanager/server/server.go @@ -394,7 +394,7 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { if err == nil { log.ReplaceGlobals(cfg.Logger, cfg.LogProps) } else { - log.Fatal("initialize logger error", errs.ZapError(err)) + log.Panic("initialize logger error", errs.ZapError(err)) } // Flushing any buffered log entries log.Sync() @@ -421,7 +421,7 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { }() if err := svr.Run(); err != nil { - log.Fatal("run server failed", errs.ZapError(err)) + log.Panic("run server failed", errs.ZapError(err)) } <-ctx.Done() diff --git a/pkg/mcs/scheduling/server/grpc_service.go b/pkg/mcs/scheduling/server/grpc_service.go index 1459ccd3bac..0690f5ff992 100644 --- a/pkg/mcs/scheduling/server/grpc_service.go +++ b/pkg/mcs/scheduling/server/grpc_service.go @@ -69,7 +69,7 @@ type Service struct { func NewService[T ConfigProvider](svr bs.Server) registry.RegistrableService { server, ok := svr.(*Server) if !ok { - log.Fatal("create scheduling server failed") + log.Panic("create scheduling server failed") } return &Service{ Server: server, diff --git a/pkg/mcs/scheduling/server/server.go b/pkg/mcs/scheduling/server/server.go index 8eb9e49d964..e056906639c 100644 --- a/pkg/mcs/scheduling/server/server.go +++ b/pkg/mcs/scheduling/server/server.go @@ -593,7 +593,7 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { if err == nil { log.ReplaceGlobals(cfg.Logger, cfg.LogProps) } else { - log.Fatal("initialize logger error", errs.ZapError(err)) + log.Panic("initialize logger error", errs.ZapError(err)) } // Flushing any buffered log entries log.Sync() @@ -621,7 +621,7 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { }() if err := svr.Run(); err != nil { - log.Fatal("run server failed", errs.ZapError(err)) + log.Panic("run server failed", errs.ZapError(err)) } <-ctx.Done() diff --git a/pkg/mcs/tso/server/grpc_service.go b/pkg/mcs/tso/server/grpc_service.go index 7dd9c6b5605..075c16dc951 100644 --- a/pkg/mcs/tso/server/grpc_service.go +++ b/pkg/mcs/tso/server/grpc_service.go @@ -65,7 +65,7 @@ type Service struct { func NewService[T ConfigProvider](svr bs.Server) registry.RegistrableService { server, ok := svr.(*Server) if !ok { - log.Fatal("create tso server failed") + log.Panic("create tso server failed") } return &Service{ Server: server, diff --git a/pkg/mcs/tso/server/server.go b/pkg/mcs/tso/server/server.go index 60ce2917ed5..bbb55072f9f 100644 --- a/pkg/mcs/tso/server/server.go +++ b/pkg/mcs/tso/server/server.go @@ -465,7 +465,7 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { if err == nil { log.ReplaceGlobals(cfg.Logger, cfg.LogProps) } else { - log.Fatal("initialize logger error", errs.ZapError(err)) + log.Panic("initialize logger error", errs.ZapError(err)) } // Flushing any buffered log entries log.Sync() @@ -493,7 +493,7 @@ func CreateServerWrapper(cmd *cobra.Command, args []string) { }() if err := svr.Run(); err != nil { - log.Fatal("run server failed", errs.ZapError(err)) + log.Panic("run server failed", errs.ZapError(err)) } <-ctx.Done() diff --git a/pkg/mcs/utils/util.go b/pkg/mcs/utils/util.go index 844cf17fde4..df49523289c 100644 --- a/pkg/mcs/utils/util.go +++ b/pkg/mcs/utils/util.go @@ -197,7 +197,7 @@ func startGRPCServer(s server, l net.Listener) { if s.IsClosed() { log.Info("grpc server stopped") } else { - log.Fatal("grpc server stopped unexpectedly", errs.ZapError(err)) + log.Panic("grpc server stopped unexpectedly", errs.ZapError(err)) } } @@ -210,7 +210,7 @@ func startHTTPServer(s server, l net.Listener) { if s.IsClosed() { log.Info("http server stopped") } else { - log.Fatal("http server stopped unexpectedly", errs.ZapError(err)) + log.Panic("http server stopped unexpectedly", errs.ZapError(err)) } } @@ -257,7 +257,7 @@ func StartGRPCAndHTTPServers(s server, serverReadyChan chan<- struct{}, l net.Li if s.IsClosed() { log.Info("mux stopped serving", errs.ZapError(err)) } else { - log.Fatal("mux stopped serving unexpectedly", errs.ZapError(err)) + log.Panic("mux stopped serving unexpectedly", errs.ZapError(err)) } } } diff --git a/pkg/member/member.go b/pkg/member/member.go index bbf46d8f167..13144550ecb 100644 --- a/pkg/member/member.go +++ b/pkg/member/member.go @@ -341,7 +341,7 @@ func (m *EmbeddedEtcdMember) InitMemberInfo(advertiseClientUrls, advertisePeerUr data, err := leader.Marshal() if err != nil { // can't fail, so panic here. - log.Fatal("marshal pd leader meet error", zap.Stringer("pd-leader", leader), errs.ZapError(errs.ErrMarshalLeader, err)) + log.Panic("marshal pd leader meet error", zap.Stringer("pd-leader", leader), errs.ZapError(errs.ErrMarshalLeader, err)) } m.member = leader m.memberValue = string(data) diff --git a/pkg/member/participant.go b/pkg/member/participant.go index 8a0ffadd31e..f9385f23002 100644 --- a/pkg/member/participant.go +++ b/pkg/member/participant.go @@ -82,7 +82,7 @@ func (m *Participant) InitInfo(p participant, rootPath string, leaderName string data, err := p.Marshal() if err != nil { // can't fail, so panic here. - log.Fatal("marshal leader meet error", zap.String("member-name", p.String()), errs.ZapError(errs.ErrMarshalLeader, err)) + log.Panic("marshal leader meet error", zap.String("member-name", p.String()), errs.ZapError(errs.ErrMarshalLeader, err)) } m.member = p m.memberValue = string(data) diff --git a/pkg/memory/meminfo.go b/pkg/memory/meminfo.go index 64505e2e5f3..b9806b36449 100644 --- a/pkg/memory/meminfo.go +++ b/pkg/memory/meminfo.go @@ -158,7 +158,7 @@ func MemUsedCGroup() (uint64, error) { func mustNil(err error) { if err != nil { - log.Fatal("unexpected error", zap.Error(err), zap.Stack("stack")) + log.Panic("unexpected error", zap.Error(err), zap.Stack("stack")) } } diff --git a/pkg/schedule/coordinator.go b/pkg/schedule/coordinator.go index 1a8a8eb377b..aa949b284ab 100644 --- a/pkg/schedule/coordinator.go +++ b/pkg/schedule/coordinator.go @@ -430,7 +430,7 @@ func (c *Coordinator) InitSchedulers(needRun bool) { log.Error("cannot load schedulers' config", zap.Int("retry-times", i), errs.ZapError(err)) } if err != nil { - log.Fatal("cannot load schedulers' config", errs.ZapError(err)) + log.Panic("cannot load schedulers' config", errs.ZapError(err)) } scheduleCfg := c.cluster.GetSchedulerConfig().GetScheduleConfig().Clone() // The new way to create scheduler with the independent configuration. diff --git a/pkg/schedule/schedulers/base_scheduler.go b/pkg/schedule/schedulers/base_scheduler.go index f3772757ad3..2b5e0718424 100644 --- a/pkg/schedule/schedulers/base_scheduler.go +++ b/pkg/schedule/schedulers/base_scheduler.go @@ -53,7 +53,7 @@ func intervalGrow(x time.Duration, maxInterval time.Duration, typ intervalGrowth case zeroGrowth: return x default: - log.Fatal("type error", errs.ZapError(errs.ErrInternalGrowth)) + log.Panic("type error", errs.ZapError(errs.ErrInternalGrowth)) } return 0 } diff --git a/pkg/schedule/schedulers/scheduler.go b/pkg/schedule/schedulers/scheduler.go index abace59a266..c2c604f589e 100644 --- a/pkg/schedule/schedulers/scheduler.go +++ b/pkg/schedule/schedulers/scheduler.go @@ -120,7 +120,7 @@ var ( // func of a package. func RegisterScheduler(typ string, createFn CreateSchedulerFunc) { if _, ok := schedulerMap[typ]; ok { - log.Fatal("duplicated scheduler", zap.String("type", typ), errs.ZapError(errs.ErrSchedulerDuplicated)) + log.Panic("duplicated scheduler", zap.String("type", typ), errs.ZapError(errs.ErrSchedulerDuplicated)) } schedulerMap[typ] = createFn } @@ -129,7 +129,7 @@ func RegisterScheduler(typ string, createFn CreateSchedulerFunc) { // func of package. func RegisterSliceDecoderBuilder(typ string, builder ConfigSliceDecoderBuilder) { if _, ok := schedulerArgsToDecoder[typ]; ok { - log.Fatal("duplicated scheduler", zap.String("type", typ), errs.ZapError(errs.ErrSchedulerDuplicated)) + log.Panic("duplicated scheduler", zap.String("type", typ), errs.ZapError(errs.ErrSchedulerDuplicated)) } schedulerArgsToDecoder[typ] = builder config.RegisterScheduler(typ) diff --git a/pkg/storage/hot_region_storage_test.go b/pkg/storage/hot_region_storage_test.go index 1486fb8271d..79e8466e3d1 100644 --- a/pkg/storage/hot_region_storage_test.go +++ b/pkg/storage/hot_region_storage_test.go @@ -309,7 +309,7 @@ func newTestHotRegionStorage(pullInterval time.Duration, func PrintDirSize(path string) { size, err := DirSizeB(path) if err != nil { - log.Fatal(err) + log.Panic(err) } fmt.Printf("file size %d\n", size) } diff --git a/pkg/syncer/history_buffer.go b/pkg/syncer/history_buffer.go index 08fe85cc8c5..492d8798f2b 100644 --- a/pkg/syncer/history_buffer.go +++ b/pkg/syncer/history_buffer.go @@ -148,7 +148,7 @@ func (h *historyBuffer) reload() { if v != "" { h.index, err = strconv.ParseUint(v, 10, 64) if err != nil { - log.Fatal("load history index failed", errs.ZapError(errs.ErrStrconvParseUint, err)) + log.Panic("load history index failed", errs.ZapError(errs.ErrStrconvParseUint, err)) } } log.Info("start from history index", zap.Uint64("start-index", h.firstIndex())) diff --git a/pkg/tso/keyspace_group_manager.go b/pkg/tso/keyspace_group_manager.go index 83a1369d2f2..c82ed360fa1 100644 --- a/pkg/tso/keyspace_group_manager.go +++ b/pkg/tso/keyspace_group_manager.go @@ -404,7 +404,7 @@ func NewKeyspaceGroupManager( cfg ServiceConfig, ) *KeyspaceGroupManager { if mcsutils.MaxKeyspaceGroupCountInUse > mcsutils.MaxKeyspaceGroupCount { - log.Fatal("MaxKeyspaceGroupCountInUse is larger than MaxKeyspaceGroupCount", + log.Panic("MaxKeyspaceGroupCountInUse is larger than MaxKeyspaceGroupCount", zap.Uint32("max-keyspace-group-count-in-use", mcsutils.MaxKeyspaceGroupCountInUse), zap.Uint32("max-keyspace-group-count", mcsutils.MaxKeyspaceGroupCount)) } diff --git a/pkg/utils/logutil/log.go b/pkg/utils/logutil/log.go index c7a9ac2f3b7..126aa472cb9 100644 --- a/pkg/utils/logutil/log.go +++ b/pkg/utils/logutil/log.go @@ -90,7 +90,7 @@ func SetupLogger( // Commonly used with a `defer`. func LogPanic() { if e := recover(); e != nil { - log.Fatal("panic", zap.Reflect("recover", e)) + log.Panic("panic", zap.Reflect("recover", e)) } } diff --git a/pkg/utils/tempurl/tempurl.go b/pkg/utils/tempurl/tempurl.go index cd5cd498f95..750bdc7b671 100644 --- a/pkg/utils/tempurl/tempurl.go +++ b/pkg/utils/tempurl/tempurl.go @@ -43,7 +43,7 @@ func Alloc() string { } time.Sleep(time.Second) } - log.Fatal("failed to alloc test URL") + log.Panic("failed to alloc test URL") return "" } @@ -53,12 +53,12 @@ func tryAllocTestURL() string { } l, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { - log.Fatal("listen failed", errs.ZapError(err)) + log.Panic("listen failed", errs.ZapError(err)) } addr := fmt.Sprintf("http://%s", l.Addr()) err = l.Close() if err != nil { - log.Fatal("close failed", errs.ZapError(err)) + log.Panic("close failed", errs.ZapError(err)) } testAddrMutex.Lock() diff --git a/pkg/versioninfo/feature.go b/pkg/versioninfo/feature.go index 21ad56e8585..aee7cd1d9da 100644 --- a/pkg/versioninfo/feature.go +++ b/pkg/versioninfo/feature.go @@ -66,7 +66,7 @@ var featuresDict = map[Feature]string{ func MinSupportedVersion(v Feature) *semver.Version { target, ok := featuresDict[v] if !ok { - log.Fatal("the corresponding version of the feature doesn't exist", zap.Int("feature-number", int(v)), errs.ZapError(errs.ErrFeatureNotExisted)) + log.Panic("the corresponding version of the feature doesn't exist", zap.Int("feature-number", int(v)), errs.ZapError(errs.ErrFeatureNotExisted)) } version := MustParseVersion(target) return version diff --git a/pkg/versioninfo/versioninfo.go b/pkg/versioninfo/versioninfo.go index d6f4738d786..4b9951a9f46 100644 --- a/pkg/versioninfo/versioninfo.go +++ b/pkg/versioninfo/versioninfo.go @@ -67,7 +67,7 @@ func ParseVersion(v string) (*semver.Version, error) { func MustParseVersion(v string) *semver.Version { ver, err := ParseVersion(v) if err != nil { - log.Fatal("version string is illegal", errs.ZapError(err)) + log.Panic("version string is illegal", errs.ZapError(err)) } return ver } diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 93be9d1c076..4a8e7ca2dc4 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -421,7 +421,7 @@ func (c *RaftCluster) startGCTuner() { defer tick.Stop() totalMem, err := memory.MemTotal() if err != nil { - log.Fatal("fail to get total memory:%s", zap.Error(err)) + log.Panic("fail to get total memory:%s", zap.Error(err)) } log.Info("memory info", zap.Uint64("total-mem", totalMem)) cfg := c.opt.GetPDServerConfig() diff --git a/server/join/join.go b/server/join/join.go index 1319dc08d07..0be568ccdf7 100644 --- a/server/join/join.go +++ b/server/join/join.go @@ -95,7 +95,7 @@ func PrepareJoinCluster(cfg *config.Config) error { if _, err := os.Stat(filePath); !os.IsNotExist(err) { s, err := os.ReadFile(filePath) if err != nil { - log.Fatal("read the join config meet error", errs.ZapError(errs.ErrIORead, err)) + log.Panic("read the join config meet error", errs.ZapError(errs.ErrIORead, err)) } cfg.InitialCluster = strings.TrimSpace(string(s)) cfg.InitialClusterState = embed.ClusterStateFlagExisting diff --git a/tools/pd-analysis/analysis/parse_log.go b/tools/pd-analysis/analysis/parse_log.go index f096e3fe380..9791fceb034 100644 --- a/tools/pd-analysis/analysis/parse_log.go +++ b/tools/pd-analysis/analysis/parse_log.go @@ -130,10 +130,10 @@ func currentTime(layout string) func(content string) (time.Time, error) { if pattern, ok := supportLayouts[layout]; ok { r, err = regexp.Compile(pattern) if err != nil { - log.Fatal(err) + log.Panic(err) } } else { - log.Fatal("unsupported time layout") + log.Panic("unsupported time layout") } return func(content string) (time.Time, error) { result := r.FindStringSubmatch(content) diff --git a/tools/pd-analysis/analysis/transfer_counter.go b/tools/pd-analysis/analysis/transfer_counter.go index 8f472ae1e03..014d4cc8050 100644 --- a/tools/pd-analysis/analysis/transfer_counter.go +++ b/tools/pd-analysis/analysis/transfer_counter.go @@ -97,7 +97,7 @@ func (c *TransferCounter) AddSource(regionID, sourceStoreID uint64) { } delete(c.regionMap, regionID) } else { - log.Fatal("error when add sourceStore in transfer region map", zap.Uint64("source-store", sourceStoreID), zap.Uint64("region", regionID)) + log.Panic("error when add sourceStore in transfer region map", zap.Uint64("source-store", sourceStoreID), zap.Uint64("region", regionID)) } } @@ -239,7 +239,7 @@ func (c *TransferCounter) PrintResult() { // Output csv file fd, err := os.OpenFile("result.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600) if err != nil { - log.Fatal(err) + log.Panic(err) } defer func() { if err := fd.Close(); err != nil { @@ -255,7 +255,7 @@ func (c *TransferCounter) PrintResult() { buf := []byte(fdContent) _, err = fd.Write(buf) if err != nil { - log.Fatal(err) + log.Panic(err) } } diff --git a/tools/pd-api-bench/main.go b/tools/pd-api-bench/main.go index 747fbaa10c1..f584139ae6f 100644 --- a/tools/pd-api-bench/main.go +++ b/tools/pd-api-bench/main.go @@ -90,13 +90,13 @@ func main() { case flag.ErrHelp: exit(0) default: - log.Fatal("parse cmd flags error", zap.Error(err)) + log.Panic("parse cmd flags error", zap.Error(err)) } err = logutil.SetupLogger(cfg.Log, &cfg.Logger, &cfg.LogProps, logutil.RedactInfoLogOFF) if err == nil { log.ReplaceGlobals(cfg.Logger, cfg.LogProps) } else { - log.Fatal("initialize logger error", zap.Error(err)) + log.Panic("initialize logger error", zap.Error(err)) } sc := make(chan os.Signal, 1) signal.Notify(sc, @@ -131,7 +131,7 @@ func main() { } err = cases.InitCluster(ctx, pdClis[0], httpClis[0]) if err != nil { - log.Fatal("InitCluster error", zap.Error(err)) + log.Panic("InitCluster error", zap.Error(err)) } coordinator := cases.NewCoordinator(ctx, httpClis, pdClis, etcdClis) @@ -359,7 +359,7 @@ func newEtcdClient(cfg *config.Config) *clientv3.Client { KeyPath: cfg.KeyPath, }.ToTLSConfig() if err != nil { - log.Fatal("fail to create etcd client", zap.Error(err)) + log.Panic("fail to create etcd client", zap.Error(err)) return nil } clientConfig := clientv3.Config{ @@ -370,7 +370,7 @@ func newEtcdClient(cfg *config.Config) *clientv3.Client { } client, err := clientv3.New(clientConfig) if err != nil { - log.Fatal("fail to create pd client", zap.Error(err)) + log.Panic("fail to create pd client", zap.Error(err)) } return client } @@ -390,7 +390,7 @@ func newPDClient(ctx context.Context, cfg *config.Config) pd.Client { }), )) if err != nil { - log.Fatal("fail to create pd client", zap.Error(err)) + log.Panic("fail to create pd client", zap.Error(err)) } return pdCli } @@ -418,7 +418,7 @@ func loadTLSConfig(cfg *config.Config) *tls.Config { SSLKEYBytes: keyData, }.ToTLSConfig() if err != nil { - log.Fatal("failed to load tlc config", zap.Error(err)) + log.Panic("failed to load tlc config", zap.Error(err)) } return tlsConf diff --git a/tools/pd-ctl/pdctl/ctl.go b/tools/pd-ctl/pdctl/ctl.go index fbacd65dc53..5852b8f57ca 100644 --- a/tools/pd-ctl/pdctl/ctl.go +++ b/tools/pd-ctl/pdctl/ctl.go @@ -149,7 +149,8 @@ func loop(persistentFlags *pflag.FlagSet, readlineCompleter readline.AutoComplet continue } if line == "exit" { - os.Exit(0) + l.Close() + os.Exit(0) //nolint:gocritic } args, err := shellwords.Parse(line) if err != nil { diff --git a/tools/pd-heartbeat-bench/main.go b/tools/pd-heartbeat-bench/main.go index 77ae6354bff..6516bf6383f 100644 --- a/tools/pd-heartbeat-bench/main.go +++ b/tools/pd-heartbeat-bench/main.go @@ -114,7 +114,7 @@ func bootstrap(ctx context.Context, cli pdpb.PDClient) { isBootstrapped, err := cli.IsBootstrapped(cctx, &pdpb.IsBootstrappedRequest{Header: header()}) cancel() if err != nil { - log.Fatal("check if cluster has already bootstrapped failed", zap.Error(err)) + log.Panic("check if cluster has already bootstrapped failed", zap.Error(err)) } if isBootstrapped.GetBootstrapped() { log.Info("already bootstrapped") @@ -140,10 +140,10 @@ func bootstrap(ctx context.Context, cli pdpb.PDClient) { resp, err := cli.Bootstrap(cctx, req) cancel() if err != nil { - log.Fatal("failed to bootstrap the cluster", zap.Error(err)) + log.Panic("failed to bootstrap the cluster", zap.Error(err)) } if resp.GetHeader().GetError() != nil { - log.Fatal("failed to bootstrap the cluster", zap.String("err", resp.GetHeader().GetError().String())) + log.Panic("failed to bootstrap the cluster", zap.String("err", resp.GetHeader().GetError().String())) } log.Info("bootstrapped") } @@ -159,10 +159,10 @@ func putStores(ctx context.Context, cfg *config.Config, cli pdpb.PDClient, store resp, err := cli.PutStore(cctx, &pdpb.PutStoreRequest{Header: header(), Store: store}) cancel() if err != nil { - log.Fatal("failed to put store", zap.Uint64("store-id", i), zap.Error(err)) + log.Panic("failed to put store", zap.Uint64("store-id", i), zap.Error(err)) } if resp.GetHeader().GetError() != nil { - log.Fatal("failed to put store", zap.Uint64("store-id", i), zap.String("err", resp.GetHeader().GetError().String())) + log.Panic("failed to put store", zap.Uint64("store-id", i), zap.String("err", resp.GetHeader().GetError().String())) } go func(ctx context.Context, storeID uint64) { var heartbeatTicker = time.NewTicker(10 * time.Second) @@ -325,11 +325,11 @@ func (rs *Regions) update(cfg *config.Config, options *config.Options) { func createHeartbeatStream(ctx context.Context, cfg *config.Config) (pdpb.PDClient, pdpb.PD_RegionHeartbeatClient) { cli, err := newClient(ctx, cfg) if err != nil { - log.Fatal("create client error", zap.Error(err)) + log.Panic("create client error", zap.Error(err)) } stream, err := cli.RegionHeartbeat(ctx) if err != nil { - log.Fatal("create stream error", zap.Error(err)) + log.Panic("create stream error", zap.Error(err)) } go func() { @@ -471,7 +471,7 @@ func main() { case pflag.ErrHelp: exit(0) default: - log.Fatal("parse cmd flags error", zap.Error(err)) + log.Panic("parse cmd flags error", zap.Error(err)) } // New zap logger @@ -479,7 +479,7 @@ func main() { if err == nil { log.ReplaceGlobals(cfg.Logger, cfg.LogProps) } else { - log.Fatal("initialize logger error", zap.Error(err)) + log.Panic("initialize logger error", zap.Error(err)) } maxVersion = cfg.InitEpochVer @@ -501,7 +501,7 @@ func main() { }() cli, err := newClient(ctx, cfg) if err != nil { - log.Fatal("create client error", zap.Error(err)) + log.Panic("create client error", zap.Error(err)) } initClusterID(ctx, cli) @@ -715,7 +715,7 @@ func loadTLSConfig(cfg *config.Config) *tls.Config { SSLKEYBytes: keyData, }.ToTLSConfig() if err != nil { - log.Fatal("failed to load tlc config", zap.Error(err)) + log.Panic("failed to load tlc config", zap.Error(err)) } return tlsConf diff --git a/tools/pd-simulator/main.go b/tools/pd-simulator/main.go index 63ba7f9134d..f13e5ee96b9 100644 --- a/tools/pd-simulator/main.go +++ b/tools/pd-simulator/main.go @@ -115,7 +115,7 @@ func NewSingleServer(ctx context.Context, simConfig *sc.SimConfig) (*server.Serv if err == nil { log.ReplaceGlobals(simConfig.ServerConfig.Logger, simConfig.ServerConfig.LogProps) } else { - log.Fatal("setup logger error", zap.Error(err)) + log.Panic("setup logger error", zap.Error(err)) } s, err := server.CreateServer(ctx, simConfig.ServerConfig, nil, api.NewHandler) @@ -190,6 +190,7 @@ EXIT: simulator.SD.Close() } if simResult != "OK" { - os.Exit(1) + tick.Stop() + os.Exit(1) //nolint:gocritic } } diff --git a/tools/pd-tso-bench/main.go b/tools/pd-tso-bench/main.go index 3726373779e..4a181a07576 100644 --- a/tools/pd-tso-bench/main.go +++ b/tools/pd-tso-bench/main.go @@ -106,7 +106,7 @@ func bench(mainCtx context.Context) { for idx := range pdClients { pdCli, err := createPDClient(mainCtx) if err != nil { - log.Fatal(fmt.Sprintf("create pd client #%d failed: %v", idx, err)) + log.Panic(fmt.Sprintf("create pd client #%d failed: %v", idx, err)) } pdClients[idx] = pdCli } @@ -116,7 +116,7 @@ func bench(mainCtx context.Context) { for idx, pdCli := range pdClients { _, _, err := pdCli.GetLocalTS(ctx, *dcLocation) if err != nil { - log.Fatal("get first time tso failed", zap.Int("client-number", idx), zap.Error(err)) + log.Panic("get first time tso failed", zap.Int("client-number", idx), zap.Error(err)) } } @@ -406,7 +406,7 @@ func reqWorker(ctx context.Context, pdClients []pd.Client, clientIdx int, durCh time.Sleep(sleepIntervalOnFailure) } if err != nil { - log.Fatal(fmt.Sprintf("%v", err)) + log.Panic(fmt.Sprintf("%v", err)) } dur := time.Since(start) - time.Duration(i)*sleepIntervalOnFailure - totalSleepBeforeGetTS diff --git a/tools/pd-ut/alloc/server.go b/tools/pd-ut/alloc/server.go index aced73467fb..38226a3951f 100644 --- a/tools/pd-ut/alloc/server.go +++ b/tools/pd-ut/alloc/server.go @@ -48,7 +48,7 @@ func RunHTTPServer() *http.Server { srv := &http.Server{Addr: *statusAddress, Handler: engine.Handler(), ReadHeaderTimeout: 3 * time.Second} go func() { if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { - log.Fatal("server listen error", zap.Error(err)) + log.Panic("server listen error", zap.Error(err)) } }() diff --git a/tools/pd-ut/alloc/tempurl.go b/tools/pd-ut/alloc/tempurl.go index 6be69dfe056..01c56056e1f 100644 --- a/tools/pd-ut/alloc/tempurl.go +++ b/tools/pd-ut/alloc/tempurl.go @@ -37,7 +37,7 @@ func Alloc() string { } time.Sleep(200 * time.Millisecond) } - log.Fatal("failed to alloc test URL") + log.Panic("failed to alloc test URL") return "" } @@ -49,7 +49,7 @@ func tryAllocTestURL() string { addr := fmt.Sprintf("http://%s", l.Addr()) err = l.Close() if err != nil { - log.Fatal("close failed", errs.ZapError(err)) + log.Panic("close failed", errs.ZapError(err)) } testAddrMutex.Lock() diff --git a/tools/pd-ut/coverProfile.go b/tools/pd-ut/coverProfile.go index 0ed1c3f3c61..4586c35ae23 100644 --- a/tools/pd-ut/coverProfile.go +++ b/tools/pd-ut/coverProfile.go @@ -64,7 +64,8 @@ func collectCoverProfileFile() { } if err := w1.Flush(); err != nil { fmt.Println("flush data to cover profile file error:", err) - os.Exit(-1) + w.Close() + os.Exit(-1) //nolint: gocritic } } } @@ -81,7 +82,8 @@ func collectOneCoverProfileFile(result map[string]*cover.Profile, file os.DirEnt profs, err := cover.ParseProfilesFromReader(f) if err != nil { fmt.Println("parse cover profile file error:", err) - os.Exit(-1) + f.Close() + os.Exit(-1) //nolint: gocritic } mergeProfile(result, profs) } diff --git a/tools/pd-ut/ut.go b/tools/pd-ut/ut.go index de62151fcb3..fc89703700a 100644 --- a/tools/pd-ut/ut.go +++ b/tools/pd-ut/ut.go @@ -150,7 +150,7 @@ func main() { srv := alloc.RunHTTPServer() defer func() { if err := srv.Shutdown(context.Background()); err != nil { - log.Fatal("server shutdown error", zap.Error(err)) + log.Panic("server shutdown error", zap.Error(err)) } }() @@ -187,7 +187,10 @@ func main() { } } if !isSucceed { - os.Exit(1) + if len(coverFileTempDir) > 0 { + os.RemoveAll(coverFileTempDir) + } + os.Exit(1) //nolint:gocritic } }