diff --git a/pd-client/client.go b/pd-client/client.go index 31d039558f60..52da2de204b7 100644 --- a/pd-client/client.go +++ b/pd-client/client.go @@ -175,7 +175,7 @@ func (c *client) initClusterID() error { time.Sleep(time.Second) } - return errors.WithStack(errFailInitClusterID) + return errors.AddStack(errFailInitClusterID) } func (c *client) updateLeader() error { @@ -186,7 +186,7 @@ func (c *client) updateLeader() error { if err != nil || members.GetLeader() == nil || len(members.GetLeader().GetClientUrls()) == 0 { select { case <-c.ctx.Done(): - return errors.WithStack(err) + return errors.AddStack(err) default: continue } @@ -204,7 +204,7 @@ func (c *client) getMembers(ctx context.Context, url string) (*pdpb.GetMembersRe } members, err := pdpb.NewPDClient(cc).GetMembers(ctx, &pdpb.GetMembersRequest{}) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } return members, nil } @@ -274,11 +274,11 @@ func (c *client) getOrCreateGRPCConn(addr string) (*grpc.ClientConn, error) { } u, err := url.Parse(addr) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } cc, err := grpc.Dial(u.Host, opt) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } c.connMu.Lock() defer c.connMu.Unlock() @@ -367,7 +367,7 @@ func (c *client) tsLoop() { log.Errorf("[pd] create tso stream error: %v", err) c.ScheduleCheckLeader() cancel() - c.revokeTSORequest(errors.WithStack(err)) + c.revokeTSORequest(errors.AddStack(err)) select { case <-time.After(time.Second): case <-loopCtx.Done(): @@ -440,19 +440,19 @@ func (c *client) processTSORequests(stream pdpb.PD_TsoClient, requests []*tsoReq } if err := stream.Send(req); err != nil { - err = errors.WithStack(err) + err = errors.AddStack(err) c.finishTSORequest(requests, 0, 0, err) return err } resp, err := stream.Recv() if err != nil { - err = errors.WithStack(err) + err = errors.AddStack(err) c.finishTSORequest(requests, 0, 0, err) return err } requestDuration.WithLabelValues("tso").Observe(time.Since(start).Seconds()) if resp.GetCount() != uint32(len(requests)) { - err = errors.WithStack(errTSOLength) + err = errors.AddStack(errTSOLength) c.finishTSORequest(requests, 0, 0, err) return err } @@ -486,7 +486,7 @@ func (c *client) Close() { c.cancel() c.wg.Wait() - c.revokeTSORequest(errors.WithStack(errClosing)) + c.revokeTSORequest(errors.AddStack(errClosing)) c.connMu.Lock() defer c.connMu.Unlock() @@ -562,7 +562,7 @@ func (req *tsoRequest) Wait() (physical int64, logical int64, err error) { cmdDuration.WithLabelValues("tso_async_wait").Observe(time.Since(req.start).Seconds()) select { case err = <-req.done: - err = errors.WithStack(err) + err = errors.AddStack(err) defer tsoReqPool.Put(req) if err != nil { cmdFailedDuration.WithLabelValues("tso").Observe(time.Since(req.start).Seconds()) @@ -572,7 +572,7 @@ func (req *tsoRequest) Wait() (physical int64, logical int64, err error) { cmdDuration.WithLabelValues("tso").Observe(time.Since(req.start).Seconds()) return case <-req.ctx.Done(): - return 0, 0, errors.WithStack(req.ctx.Err()) + return 0, 0, errors.AddStack(req.ctx.Err()) } } @@ -599,7 +599,7 @@ func (c *client) GetRegion(ctx context.Context, key []byte) (*metapb.Region, *me if err != nil { cmdFailedDuration.WithLabelValues("get_region").Observe(time.Since(start).Seconds()) c.ScheduleCheckLeader() - return nil, nil, errors.WithStack(err) + return nil, nil, errors.AddStack(err) } return resp.GetRegion(), resp.GetLeader(), nil } @@ -622,7 +622,7 @@ func (c *client) GetPrevRegion(ctx context.Context, key []byte) (*metapb.Region, if err != nil { cmdFailedDuration.WithLabelValues("get_prev_region").Observe(time.Since(start).Seconds()) c.ScheduleCheckLeader() - return nil, nil, errors.WithStack(err) + return nil, nil, errors.AddStack(err) } return resp.GetRegion(), resp.GetLeader(), nil } @@ -645,7 +645,7 @@ func (c *client) GetRegionByID(ctx context.Context, regionID uint64) (*metapb.Re if err != nil { cmdFailedDuration.WithLabelValues("get_region_byid").Observe(time.Since(start).Seconds()) c.ScheduleCheckLeader() - return nil, nil, errors.WithStack(err) + return nil, nil, errors.AddStack(err) } return resp.GetRegion(), resp.GetLeader(), nil } @@ -668,7 +668,7 @@ func (c *client) GetStore(ctx context.Context, storeID uint64) (*metapb.Store, e if err != nil { cmdFailedDuration.WithLabelValues("get_store").Observe(time.Since(start).Seconds()) c.ScheduleCheckLeader() - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } store := resp.GetStore() if store == nil { @@ -697,7 +697,7 @@ func (c *client) GetAllStores(ctx context.Context) ([]*metapb.Store, error) { if err != nil { cmdFailedDuration.WithLabelValues("get_all_stores").Observe(time.Since(start).Seconds()) c.ScheduleCheckLeader() - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } stores := resp.GetStores() return stores, nil @@ -721,7 +721,7 @@ func (c *client) UpdateGCSafePoint(ctx context.Context, safePoint uint64) (uint6 if err != nil { cmdFailedDuration.WithLabelValues("update_gc_safe_point").Observe(time.Since(start).Seconds()) c.ScheduleCheckLeader() - return 0, errors.WithStack(err) + return 0, errors.AddStack(err) } return resp.GetNewSafePoint(), nil } diff --git a/pdctl/command/global.go b/pdctl/command/global.go index 19f16991f3dd..ac6ce86f2f4b 100644 --- a/pdctl/command/global.go +++ b/pdctl/command/global.go @@ -43,7 +43,7 @@ func InitHTTPSClient(CAPath, CertPath, KeyPath string) error { } tlsConfig, err := tlsInfo.ClientConfig() if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } dialClient = &http.Client{Transport: &http.Transport{ diff --git a/pdctl/command/operator.go b/pdctl/command/operator.go index 8d728e82d031..4e5bf7158c64 100644 --- a/pdctl/command/operator.go +++ b/pdctl/command/operator.go @@ -355,7 +355,7 @@ func parseUint64s(args []string) ([]uint64, error) { for _, arg := range args { v, err := strconv.ParseUint(arg, 10, 64) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } results = append(results, v) } diff --git a/pkg/apiutil/apiutil.go b/pkg/apiutil/apiutil.go index ed232c31a8a4..ceadc8c9fcc3 100644 --- a/pkg/apiutil/apiutil.go +++ b/pkg/apiutil/apiutil.go @@ -27,7 +27,7 @@ import ( // This is designed to be used in a defer statement. func DeferClose(c io.Closer, err *error) { if cerr := c.Close(); cerr != nil && *err == nil { - *err = errors.WithStack(cerr) + *err = errors.AddStack(cerr) } } @@ -55,7 +55,7 @@ func ReadJSON(r io.ReadCloser, data interface{}) error { defer DeferClose(r, &err) b, err := ioutil.ReadAll(r) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } err = json.Unmarshal(b, data) diff --git a/pkg/etcdutil/etcdutil.go b/pkg/etcdutil/etcdutil.go index 2e9bdf1a1ddd..13970768a74e 100644 --- a/pkg/etcdutil/etcdutil.go +++ b/pkg/etcdutil/etcdutil.go @@ -76,7 +76,7 @@ func AddEtcdMember(client *clientv3.Client, urls []string) (*clientv3.MemberAddR ctx, cancel := context.WithTimeout(client.Ctx(), DefaultRequestTimeout) addResp, err := client.MemberAdd(ctx, urls) cancel() - return addResp, errors.WithStack(err) + return addResp, errors.AddStack(err) } // ListEtcdMembers returns a list of internal etcd members. @@ -84,7 +84,7 @@ func ListEtcdMembers(client *clientv3.Client) (*clientv3.MemberListResponse, err ctx, cancel := context.WithTimeout(client.Ctx(), DefaultRequestTimeout) listResp, err := client.MemberList(ctx) cancel() - return listResp, errors.WithStack(err) + return listResp, errors.AddStack(err) } // RemoveEtcdMember removes a member by the given id. @@ -92,5 +92,5 @@ func RemoveEtcdMember(client *clientv3.Client, id uint64) (*clientv3.MemberRemov ctx, cancel := context.WithTimeout(client.Ctx(), DefaultRequestTimeout) rmResp, err := client.MemberRemove(ctx, id) cancel() - return rmResp, errors.WithStack(err) + return rmResp, errors.AddStack(err) } diff --git a/pkg/faketikv/client.go b/pkg/faketikv/client.go index abf6969c7015..b10f4b1401cd 100644 --- a/pkg/faketikv/client.go +++ b/pkg/faketikv/client.go @@ -107,13 +107,13 @@ func (c *client) initClusterID() error { return nil } - return errors.WithStack(errFailInitClusterID) + return errors.AddStack(errFailInitClusterID) } func (c *client) getMembers(ctx context.Context) (*pdpb.GetMembersResponse, error) { members, err := c.pdClient().GetMembers(ctx, &pdpb.GetMembersRequest{}) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } return members, nil } @@ -121,7 +121,7 @@ func (c *client) getMembers(ctx context.Context) (*pdpb.GetMembersResponse, erro func (c *client) createConn() (*grpc.ClientConn, error) { cc, err := grpc.Dial(strings.TrimPrefix(c.url, "http://"), grpc.WithInsecure()) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } return cc, nil } diff --git a/pkg/faketikv/drive.go b/pkg/faketikv/drive.go index 7d42e29c7bed..9cb62d6c28a5 100644 --- a/pkg/faketikv/drive.go +++ b/pkg/faketikv/drive.go @@ -78,7 +78,7 @@ func (d *Driver) Prepare() error { var id uint64 id, err = d.client.AllocID(context.Background()) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if id > d.conf.MaxID { break diff --git a/pkg/faketikv/raft.go b/pkg/faketikv/raft.go index 970ed3ad4e34..6519d7117544 100644 --- a/pkg/faketikv/raft.go +++ b/pkg/faketikv/raft.go @@ -253,7 +253,7 @@ func (r *RaftEngine) allocID(storeID uint64) (uint64, error) { return 0, errors.Errorf("node %d not found", storeID) } id, err := node.client.AllocID(context.Background()) - return id, errors.WithStack(err) + return id, errors.AddStack(err) } const ( diff --git a/pkg/integration_test/cluster.go b/pkg/integration_test/cluster.go index 7d6354e8a3b1..94fee1389d5a 100644 --- a/pkg/integration_test/cluster.go +++ b/pkg/integration_test/cluster.go @@ -141,7 +141,7 @@ func (s *testServer) GetEtcdLeader() (string, error) { req := &pdpb.GetMembersRequest{Header: &pdpb.RequestHeader{ClusterId: s.server.ClusterID()}} members, err := s.server.GetMembers(context.TODO(), req) if err != nil { - return "", errors.WithStack(err) + return "", errors.AddStack(err) } return members.GetEtcdLeader().GetName(), nil } @@ -190,7 +190,7 @@ func (c *testCluster) RunServers(ctx context.Context, servers []*testServer) err } for _, c := range res { if err := <-c; err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } } return nil diff --git a/pkg/typeutil/duration.go b/pkg/typeutil/duration.go index c29c8de8ed6b..3ce7d56e82e6 100644 --- a/pkg/typeutil/duration.go +++ b/pkg/typeutil/duration.go @@ -40,11 +40,11 @@ func (d *Duration) MarshalJSON() ([]byte, error) { func (d *Duration) UnmarshalJSON(text []byte) error { s, err := strconv.Unquote(string(text)) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } duration, err := time.ParseDuration(s) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } d.Duration = duration return nil @@ -54,5 +54,5 @@ func (d *Duration) UnmarshalJSON(text []byte) error { func (d *Duration) UnmarshalText(text []byte) error { var err error d.Duration, err = time.ParseDuration(string(text)) - return errors.WithStack(err) + return errors.AddStack(err) } diff --git a/pkg/typeutil/size.go b/pkg/typeutil/size.go index 3b58c73ccfac..bcb7d68df9dd 100644 --- a/pkg/typeutil/size.go +++ b/pkg/typeutil/size.go @@ -32,11 +32,11 @@ func (b ByteSize) MarshalJSON() ([]byte, error) { func (b *ByteSize) UnmarshalJSON(text []byte) error { s, err := strconv.Unquote(string(text)) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } v, err := gh.ParseBytes(s) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } *b = ByteSize(v) return nil @@ -46,7 +46,7 @@ func (b *ByteSize) UnmarshalJSON(text []byte) error { func (b *ByteSize) UnmarshalText(text []byte) error { v, err := gh.ParseBytes(string(text)) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } *b = ByteSize(v) return nil diff --git a/pkg/typeutil/string_slice.go b/pkg/typeutil/string_slice.go index e62df9032ec5..7d17f3f639f1 100644 --- a/pkg/typeutil/string_slice.go +++ b/pkg/typeutil/string_slice.go @@ -32,7 +32,7 @@ func (s StringSlice) MarshalJSON() ([]byte, error) { func (s *StringSlice) UnmarshalJSON(text []byte) error { data, err := strconv.Unquote(string(text)) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if len(data) == 0 { *s = nil diff --git a/server/api/diagnose.go b/server/api/diagnose.go index 9319659b0ff4..d0435b15eb07 100644 --- a/server/api/diagnose.go +++ b/server/api/diagnose.go @@ -115,7 +115,7 @@ func (d *diagnoseHandler) membersDiagnose(rdd *[]*Recommendation) error { req := &pdpb.GetMembersRequest{Header: &pdpb.RequestHeader{ClusterId: d.svr.ClusterID()}} members, err := d.svr.GetMembers(context.Background(), req) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } lenMembers := len(members.Members) if lenMembers > 0 { diff --git a/server/api/label.go b/server/api/label.go index 4cb4dcedecfe..0b953787a96e 100644 --- a/server/api/label.go +++ b/server/api/label.go @@ -102,11 +102,11 @@ func newStoresLabelFilter(name, value string) (*storesLabelFilter, error) { // add (?i) to set a case-insensitive flag keyPattern, err := regexp.Compile("(?i)" + name) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } valuePattern, err := regexp.Compile("(?i)" + value) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } return &storesLabelFilter{ keyPattern: keyPattern, diff --git a/server/api/member.go b/server/api/member.go index 139caa758702..c38643976acb 100644 --- a/server/api/member.go +++ b/server/api/member.go @@ -53,7 +53,7 @@ func (h *memberHandler) getMembers() (*pdpb.GetMembersResponse, error) { req := &pdpb.GetMembersRequest{Header: &pdpb.RequestHeader{ClusterId: h.svr.ClusterID()}} members, err := h.svr.GetMembers(context.Background(), req) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } // Fill leader priorities. for _, m := range members.GetMembers() { diff --git a/server/api/store.go b/server/api/store.go index 891cc8f7801d..11c808bae6c3 100644 --- a/server/api/store.go +++ b/server/api/store.go @@ -360,7 +360,7 @@ func newStoreStateFilter(u *url.URL) (*storeStateFilter, error) { for _, s := range v { state, err := strconv.Atoi(s) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } storeState := metapb.StoreState(state) diff --git a/server/api/util.go b/server/api/util.go index c94ab46cdace..cfa8c5452621 100644 --- a/server/api/util.go +++ b/server/api/util.go @@ -70,11 +70,11 @@ func readJSON(r io.ReadCloser, data interface{}) error { b, err := ioutil.ReadAll(r) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } err = json.Unmarshal(b, data) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } return nil @@ -83,7 +83,7 @@ func readJSON(r io.ReadCloser, data interface{}) error { func postJSON(url string, data []byte) error { resp, err := server.DialClient.Post(url, "application/json", bytes.NewBuffer(data)) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } res, err := ioutil.ReadAll(resp.Body) resp.Body.Close() @@ -112,7 +112,7 @@ func doDelete(url string) error { func doGet(url string) (*http.Response, error) { resp, err := server.DialClient.Get(url) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } if resp.StatusCode != http.StatusOK { return nil, errors.Errorf("http get url %s return code %d", url, resp.StatusCode) diff --git a/server/config.go b/server/config.go index a2d3c19fda11..2bc7be595e39 100644 --- a/server/config.go +++ b/server/config.go @@ -224,7 +224,7 @@ func (c *Config) Parse(arguments []string) error { // Parse first to get config file. err := c.FlagSet.Parse(arguments) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } // Load config file if specified. @@ -251,7 +251,7 @@ func (c *Config) Parse(arguments []string) error { // Parse again to replace with command line options. err = c.FlagSet.Parse(arguments) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if len(c.FlagSet.Args()) != 0 { @@ -268,15 +268,15 @@ func (c *Config) validate() error { } dataDir, err := filepath.Abs(c.DataDir) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } logFile, err := filepath.Abs(c.Log.File.Filename) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } rel, err := filepath.Rel(dataDir, filepath.Dir(logFile)) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if !strings.HasPrefix(rel, "..") { return errors.New("log directory shouldn't be the subdirectory of data directory") @@ -370,7 +370,7 @@ func (c *Config) String() string { // configFromFile loads config from file. func (c *Config) configFromFile(path string) (*toml.MetaData, error) { meta, err := toml.DecodeFile(path, c) - return &meta, errors.WithStack(err) + return &meta, errors.AddStack(err) } // ScheduleConfig is the schedule configuration. @@ -628,7 +628,7 @@ func (s SecurityConfig) ToTLSConfig() (*tls.Config, error) { } tlsConfig, err := tlsInfo.ClientConfig() if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } return tlsConfig, nil } @@ -660,7 +660,7 @@ func ParseUrls(s string) ([]url.URL, error) { for _, item := range items { u, err := url.Parse(item) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } urls = append(urls, *u) diff --git a/server/core/kv.go b/server/core/kv.go index 58c61842bb3b..6c78de2e3325 100644 --- a/server/core/kv.go +++ b/server/core/kv.go @@ -109,7 +109,7 @@ func (kv *KV) DeleteRegion(region *metapb.Region) error { func (kv *KV) SaveConfig(cfg interface{}) error { value, err := json.Marshal(cfg) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } return kv.Save(configPath, string(value)) } @@ -125,7 +125,7 @@ func (kv *KV) LoadConfig(cfg interface{}) (bool, error) { } err = json.Unmarshal([]byte(value), cfg) if err != nil { - return false, errors.WithStack(err) + return false, errors.AddStack(err) } return true, nil } @@ -143,7 +143,7 @@ func (kv *KV) LoadStores(stores *StoresInfo) error { for _, s := range res { store := &metapb.Store{} if err := store.Unmarshal([]byte(s)); err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } storeInfo := NewStoreInfo(store) leaderWeight, err := kv.loadFloatWithDefaultValue(kv.storeLeaderWeightPath(storeInfo.GetId()), 1.0) @@ -186,7 +186,7 @@ func (kv *KV) loadFloatWithDefaultValue(path string, def float64) (float64, erro } val, err := strconv.ParseFloat(res, 64) if err != nil { - return 0, errors.WithStack(err) + return 0, errors.AddStack(err) } return val, nil } @@ -214,7 +214,7 @@ func (kv *KV) LoadRegions(regions *RegionsInfo) error { for _, s := range res { region := &metapb.Region{} if err := region.Unmarshal([]byte(s)); err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } nextID = region.GetId() + 1 @@ -265,13 +265,13 @@ func (kv *KV) loadProto(key string, msg proto.Message) (bool, error) { return false, nil } err = proto.Unmarshal([]byte(value), msg) - return true, errors.WithStack(err) + return true, errors.AddStack(err) } func (kv *KV) saveProto(key string, msg proto.Message) error { value, err := proto.Marshal(msg) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } return kv.Save(key, string(value)) } diff --git a/server/etcd_kv.go b/server/etcd_kv.go index 8553ec308b4b..af36b76bf66b 100644 --- a/server/etcd_kv.go +++ b/server/etcd_kv.go @@ -84,10 +84,10 @@ func (kv *etcdKVBase) Save(key, value string) error { resp, err := kv.server.leaderTxn().Then(clientv3.OpPut(key, value)).Commit() if err != nil { log.Errorf("save to etcd error: %v", err) - return errors.WithStack(err) + return errors.AddStack(err) } if !resp.Succeeded { - return errors.WithStack(errTxnFailed) + return errors.AddStack(errTxnFailed) } return nil } @@ -98,10 +98,10 @@ func (kv *etcdKVBase) Delete(key string) error { resp, err := kv.server.leaderTxn().Then(clientv3.OpDelete(key)).Commit() if err != nil { log.Errorf("delete from etcd error: %v", err) - return errors.WithStack(err) + return errors.AddStack(err) } if !resp.Succeeded { - return errors.WithStack(errTxnFailed) + return errors.AddStack(errTxnFailed) } return nil } @@ -119,5 +119,5 @@ func kvGet(c *clientv3.Client, key string, opts ...clientv3.OpOption) (*clientv3 log.Warnf("kv gets too slow: key %v cost %v err %v", key, cost, err) } - return resp, errors.WithStack(err) + return resp, errors.AddStack(err) } diff --git a/server/grpc_service.go b/server/grpc_service.go index 5bf55e505f28..4cc211bbbdcd 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -71,7 +71,7 @@ func (s *Server) Tso(stream pdpb.PD_TsoServer) error { return nil } if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if err = s.validateRequest(request.GetHeader()); err != nil { return err @@ -87,7 +87,7 @@ func (s *Server) Tso(stream pdpb.PD_TsoServer) error { Count: count, } if err := stream.Send(response); err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } } } @@ -284,10 +284,10 @@ func (s *heartbeatServer) Send(m *pdpb.RegionHeartbeatResponse) error { if err != nil { atomic.StoreInt32(&s.closed, 1) } - return errors.WithStack(err) + return errors.AddStack(err) case <-time.After(regionHeartbeatSendTimeout): atomic.StoreInt32(&s.closed, 1) - return errors.WithStack(errSendRegionHeartbeatTimeout) + return errors.AddStack(errSendRegionHeartbeatTimeout) } } @@ -298,7 +298,7 @@ func (s *heartbeatServer) Recv() (*pdpb.RegionHeartbeatRequest, error) { req, err := s.stream.Recv() if err != nil { atomic.StoreInt32(&s.closed, 1) - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } return req, nil } @@ -312,7 +312,7 @@ func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error { Header: s.notBootstrappedHeader(), } err := server.Send(resp) - return errors.WithStack(err) + return errors.AddStack(err) } var lastBind time.Time @@ -322,7 +322,7 @@ func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error { return nil } if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if err = s.validateRequest(request.GetHeader()); err != nil { @@ -649,7 +649,7 @@ func (s *Server) UpdateGCSafePoint(ctx context.Context, request *pdpb.UpdateGCSa // TODO: Call it in gRPC intercepter. func (s *Server) validateRequest(header *pdpb.RequestHeader) error { if !s.IsLeader() { - return errors.WithStack(notLeaderError) + return errors.AddStack(notLeaderError) } if header.GetClusterId() != s.clusterID { return status.Errorf(codes.FailedPrecondition, "mismatch cluster id, need %d but got %d", s.clusterID, header.GetClusterId()) diff --git a/server/handler.go b/server/handler.go index b65d1f0d32c6..a65bb63abfae 100644 --- a/server/handler.go +++ b/server/handler.go @@ -63,7 +63,7 @@ func newHandler(s *Server) *Handler { func (h *Handler) getCoordinator() (*coordinator, error) { cluster := h.s.GetRaftCluster() if cluster == nil { - return nil, errors.WithStack(ErrNotBootstrapped) + return nil, errors.AddStack(ErrNotBootstrapped) } return cluster.coordinator, nil } @@ -81,7 +81,7 @@ func (h *Handler) GetSchedulers() ([]string, error) { func (h *Handler) GetStores() ([]*core.StoreInfo, error) { cluster := h.s.GetRaftCluster() if cluster == nil { - return nil, errors.WithStack(ErrNotBootstrapped) + return nil, errors.AddStack(ErrNotBootstrapped) } storeMetas := cluster.GetStores() stores := make([]*core.StoreInfo, 0, len(storeMetas)) @@ -337,7 +337,7 @@ func (h *Handler) AddTransferLeaderOperator(regionID uint64, storeID uint64) err step := schedule.TransferLeader{FromStore: region.GetLeader().GetStoreId(), ToStore: newLeader.GetStoreId()} op := schedule.NewOperator("adminTransferLeader", regionID, region.GetRegionEpoch(), schedule.OpAdmin|schedule.OpLeader, step) if ok := c.addOperator(op); !ok { - return errors.WithStack(errAddOperator) + return errors.AddStack(errAddOperator) } return nil } @@ -388,7 +388,7 @@ func (h *Handler) AddTransferRegionOperator(regionID uint64, storeIDs map[uint64 op := schedule.NewOperator("adminMoveRegion", regionID, region.GetRegionEpoch(), schedule.OpAdmin|schedule.OpRegion, steps...) if ok := c.addOperator(op); !ok { - return errors.WithStack(errAddOperator) + return errors.AddStack(errAddOperator) } return nil } @@ -420,7 +420,7 @@ func (h *Handler) AddTransferPeerOperator(regionID uint64, fromStoreID, toStoreI op := schedule.CreateMovePeerOperator("adminMovePeer", c.cluster, region, schedule.OpAdmin, fromStoreID, toStoreID, newPeer.GetId()) if ok := c.addOperator(op); !ok { - return errors.WithStack(errAddOperator) + return errors.AddStack(errAddOperator) } return nil } @@ -462,7 +462,7 @@ func (h *Handler) AddAddPeerOperator(regionID uint64, toStoreID uint64) error { } op := schedule.NewOperator("adminAddPeer", regionID, region.GetRegionEpoch(), schedule.OpAdmin|schedule.OpRegion, steps...) if ok := c.addOperator(op); !ok { - return errors.WithStack(errAddOperator) + return errors.AddStack(errAddOperator) } return nil } @@ -485,7 +485,7 @@ func (h *Handler) AddRemovePeerOperator(regionID uint64, fromStoreID uint64) err op := schedule.CreateRemovePeerOperator("adminRemovePeer", c.cluster, schedule.OpAdmin, region, fromStoreID) if ok := c.addOperator(op); !ok { - return errors.WithStack(errAddOperator) + return errors.AddStack(errAddOperator) } return nil } @@ -528,7 +528,7 @@ func (h *Handler) AddMergeRegionOperator(regionID uint64, targetID uint64) error return err } if ok := c.addOperator(op1, op2); !ok { - return errors.WithStack(ErrAddOperator) + return errors.AddStack(ErrAddOperator) } return nil } @@ -552,7 +552,7 @@ func (h *Handler) AddSplitRegionOperator(regionID uint64, policy string) error { } op := schedule.NewOperator("adminSplitRegion", regionID, region.GetRegionEpoch(), schedule.OpAdmin, step) if ok := c.addOperator(op); !ok { - return errors.WithStack(errAddOperator) + return errors.AddStack(errAddOperator) } return nil } @@ -574,7 +574,7 @@ func (h *Handler) AddScatterRegionOperator(regionID uint64) error { return nil } if ok := c.addOperator(op); !ok { - return errors.WithStack(errAddOperator) + return errors.AddStack(errAddOperator) } return nil } diff --git a/server/join.go b/server/join.go index 70624bb2c2d3..c77e3a21f5e8 100644 --- a/server/join.go +++ b/server/join.go @@ -92,7 +92,7 @@ func PrepareJoinCluster(cfg *Config) error { TLS: tlsConfig, }) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } defer client.Close() diff --git a/server/leader.go b/server/leader.go index 12aff713aa88..ce0c898a82c0 100644 --- a/server/leader.go +++ b/server/leader.go @@ -212,7 +212,7 @@ func (s *Server) campaignLeader() error { } if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } leaderKey := s.getLeaderPath() @@ -222,7 +222,7 @@ func (s *Server) campaignLeader() error { Then(clientv3.OpPut(leaderKey, s.memberValue, clientv3.WithLease(leaseResp.ID))). Commit() if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if !resp.Succeeded { return errors.New("campaign leader failed, other server may campaign ok") @@ -234,7 +234,7 @@ func (s *Server) campaignLeader() error { ch, err := lessor.KeepAlive(ctx, leaseResp.ID) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } log.Debugf("campaign leader ok %s", s.Name()) @@ -344,7 +344,7 @@ func (s *Server) ResignLeader(nextLeader string) error { nextLeaderID := leaderIDs[rand.Intn(len(leaderIDs))] log.Infof("%s ready to resign leader, next leader: %v", s.Name(), nextLeaderID) err = s.etcd.Server.MoveLeader(s.serverLoopCtx, s.ID(), nextLeaderID) - return errors.WithStack(err) + return errors.AddStack(err) } func (s *Server) deleteLeaderKey() error { @@ -352,7 +352,7 @@ func (s *Server) deleteLeaderKey() error { leaderKey := s.getLeaderPath() resp, err := s.leaderTxn().Then(clientv3.OpDelete(leaderKey)).Commit() if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if !resp.Succeeded { return errors.New("resign leader failed, we are not leader already") diff --git a/server/schedulers/adjacent_region.go b/server/schedulers/adjacent_region.go index 2137b71972d3..62f6e0e05ff7 100644 --- a/server/schedulers/adjacent_region.go +++ b/server/schedulers/adjacent_region.go @@ -37,11 +37,11 @@ func init() { if len(args) == 2 { leaderLimit, err := strconv.ParseUint(args[0], 10, 64) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } peerLimit, err := strconv.ParseUint(args[1], 10, 64) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } return newBalanceAdjacentRegionScheduler(limiter, leaderLimit, peerLimit), nil } diff --git a/server/schedulers/evict_leader.go b/server/schedulers/evict_leader.go index b88511a01235..b41ce7e1dac8 100644 --- a/server/schedulers/evict_leader.go +++ b/server/schedulers/evict_leader.go @@ -29,7 +29,7 @@ func init() { } id, err := strconv.ParseUint(args[0], 10, 64) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } return newEvictLeaderScheduler(limiter, id), nil }) diff --git a/server/schedulers/grant_leader.go b/server/schedulers/grant_leader.go index 7a20e12fa5fa..5becc4765079 100644 --- a/server/schedulers/grant_leader.go +++ b/server/schedulers/grant_leader.go @@ -29,7 +29,7 @@ func init() { } id, err := strconv.ParseUint(args[0], 10, 64) if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } return newGrantLeaderScheduler(limiter, id), nil }) diff --git a/server/server.go b/server/server.go index eec25e3df569..f4d5677dd634 100644 --- a/server/server.go +++ b/server/server.go @@ -135,13 +135,13 @@ func (s *Server) startEtcd(ctx context.Context) error { log.Info("start embed etcd") etcd, err := embed.StartEtcd(s.etcdCfg) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } // Check cluster ID urlmap, err := types.NewURLsMap(s.cfg.InitialCluster) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } tlsConfig, err := s.cfg.Security.ToTLSConfig() if err != nil { @@ -167,7 +167,7 @@ func (s *Server) startEtcd(ctx context.Context) error { TLS: tlsConfig, }) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } etcdServerID := uint64(etcd.Server.ID()) @@ -344,7 +344,7 @@ func (s *Server) bootstrapCluster(req *pdpb.BootstrapRequest) (*pdpb.BootstrapRe // Set cluster meta clusterValue, err := clusterMeta.Marshal() if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } clusterRootPath := s.getClusterRootPath() @@ -363,13 +363,13 @@ func (s *Server) bootstrapCluster(req *pdpb.BootstrapRequest) (*pdpb.BootstrapRe storePath := makeStoreKey(clusterRootPath, storeMeta.GetId()) storeValue, err := storeMeta.Marshal() if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } ops = append(ops, clientv3.OpPut(storePath, string(storeValue))) regionValue, err := req.GetRegion().Marshal() if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } // Set region meta with region id. @@ -380,7 +380,7 @@ func (s *Server) bootstrapCluster(req *pdpb.BootstrapRequest) (*pdpb.BootstrapRe bootstrapCmp := clientv3.Compare(clientv3.CreateRevision(clusterRootPath), "=", 0) resp, err := s.txn().If(bootstrapCmp).Then(ops...).Commit() if err != nil { - return nil, errors.WithStack(err) + return nil, errors.AddStack(err) } if !resp.Succeeded { log.Warnf("cluster %d already bootstrapped", clusterID) @@ -658,7 +658,7 @@ func (s *Server) SetMemberLeaderPriority(id uint64, priority int) error { key := s.getMemberLeaderPriorityPath(id) res, err := s.leaderTxn().Then(clientv3.OpPut(key, strconv.Itoa(priority))).Commit() if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if !res.Succeeded { return errors.New("save leader priority failed, maybe not leader") @@ -671,7 +671,7 @@ func (s *Server) DeleteMemberLeaderPriority(id uint64) error { key := s.getMemberLeaderPriorityPath(id) res, err := s.leaderTxn().Then(clientv3.OpDelete(key)).Commit() if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if !res.Succeeded { return errors.New("delete leader priority failed, maybe not leader") @@ -691,7 +691,7 @@ func (s *Server) GetMemberLeaderPriority(id uint64) (int, error) { } priority, err := strconv.ParseInt(string(res.Kvs[0].Value), 10, 32) if err != nil { - return 0, errors.WithStack(err) + return 0, errors.AddStack(err) } return int(priority), nil } diff --git a/server/tso.go b/server/tso.go index 73259bfdf373..82eb64a0cd13 100644 --- a/server/tso.go +++ b/server/tso.go @@ -63,7 +63,7 @@ func (s *Server) saveTimestamp(ts time.Time) error { resp, err := s.leaderTxn().Then(clientv3.OpPut(key, string(data))).Commit() if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } if !resp.Succeeded { return errors.New("save timestamp failed, maybe we lost leader") diff --git a/server/util.go b/server/util.go index b1fcfc05eed9..6bc40d92c73c 100644 --- a/server/util.go +++ b/server/util.go @@ -109,7 +109,7 @@ func getProtoMsg(c *clientv3.Client, key string, msg proto.Message, opts ...clie } if err = proto.Unmarshal(value, msg); err != nil { - return false, errors.WithStack(err) + return false, errors.AddStack(err) } return true, nil @@ -133,7 +133,7 @@ func initOrGetClusterID(c *clientv3.Client, key string) (uint64, error) { Else(clientv3.OpGet(key)). Commit() if err != nil { - return 0, errors.WithStack(err) + return 0, errors.AddStack(err) } // Txn commits ok, return the generated cluster ID. @@ -213,7 +213,7 @@ func (t *slowLogTxn) Commit() (*clientv3.TxnResponse, error) { txnCounter.WithLabelValues(label).Inc() txnDuration.WithLabelValues(label).Observe(cost.Seconds()) - return resp, errors.WithStack(err) + return resp, errors.AddStack(err) } // GetMembers return a slice of Members. diff --git a/server/version.go b/server/version.go index 6b853fb88aa1..ca705d089a21 100644 --- a/server/version.go +++ b/server/version.go @@ -69,7 +69,7 @@ func ParseVersion(v string) (*semver.Version, error) { v = v[1:] } ver, err := semver.NewVersion(v) - return ver, errors.WithStack(err) + return ver, errors.AddStack(err) } // MustParseVersion wraps ParseVersion and will panic if error is not nil. diff --git a/table/namespace_classifier.go b/table/namespace_classifier.go index 1527084fe520..ec9add578dba 100644 --- a/table/namespace_classifier.go +++ b/table/namespace_classifier.go @@ -407,7 +407,7 @@ func (namespaceInfo *namespacesInfo) namespacePath(nsID uint64) string { func (namespaceInfo *namespacesInfo) saveNamespace(kv *core.KV, ns *Namespace) error { value, err := json.Marshal(ns) if err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } err = kv.Save(namespaceInfo.namespacePath(ns.GetID()), string(value)) return err @@ -428,7 +428,7 @@ func (namespaceInfo *namespacesInfo) loadNamespaces(kv *core.KV, rangeLimit int) for _, s := range res { ns := &Namespace{} if err := json.Unmarshal([]byte(s), ns); err != nil { - return errors.WithStack(err) + return errors.AddStack(err) } nextID = ns.GetID() + 1 namespaceInfo.setNamespace(ns)