diff --git a/client/base_client.go b/client/base_client.go index 930c43f8f715..a08329a780ce 100644 --- a/client/base_client.go +++ b/client/base_client.go @@ -20,9 +20,9 @@ import ( "sync" "time" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" - "github.com/pkg/errors" "github.com/tikv/pd/pkg/grpcutil" "go.uber.org/zap" "google.golang.org/grpc" diff --git a/client/client.go b/client/client.go index 8eab3fdc196c..c258d3a6ca54 100644 --- a/client/client.go +++ b/client/client.go @@ -24,11 +24,6 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" -<<<<<<< HEAD - "github.com/pkg/errors" -======= - "github.com/tikv/pd/pkg/errs" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) "go.uber.org/zap" ) diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 2211196fadf4..50d7ace2b457 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -23,11 +23,6 @@ import ( grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/pingcap/errors" "github.com/pingcap/log" -<<<<<<< HEAD - "github.com/pkg/errors" -======= - "github.com/tikv/pd/pkg/autoscaling" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) "github.com/tikv/pd/pkg/dashboard" "github.com/tikv/pd/pkg/logutil" "github.com/tikv/pd/pkg/metricutil" diff --git a/go.mod b/go.mod index 622d733f970a..f8dee4d94adb 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.13 require ( github.com/BurntSushi/toml v0.3.1 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 - github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5 github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e github.com/coreos/go-semver v0.2.0 github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf @@ -29,15 +28,11 @@ require ( github.com/pingcap-incubator/tidb-dashboard v0.0.0-20200807020752-01f0abe88e93 github.com/pingcap/check v0.0.0-20191216031241-8a5a85928f12 github.com/pingcap/errcode v0.0.0-20180921232412-a1a7271709d9 + github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011 github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d github.com/pingcap/kvproto v0.0.0-20200818080353-7aaed8998596 github.com/pingcap/log v0.0.0-20200511115504-543df19646ad -<<<<<<< HEAD github.com/pingcap/sysutil v0.0.0-20200408114249-ed3bd6f7fdb1 - github.com/pkg/errors v0.9.1 -======= - github.com/pingcap/sysutil v0.0.0-20200715082929-4c47bcac246a ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) github.com/prometheus/client_golang v1.0.0 github.com/sasha-s/go-deadlock v0.2.0 github.com/sirupsen/logrus v1.2.0 diff --git a/go.sum b/go.sum index 2f4779b0827c..5f590fd42916 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5 h1:BjkPE3785EwPhhyuFkbINB+2a1xATwk8SNDWnJiD41g= -github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5/go.mod h1:jtAfVaU/2cu1+wdSRPWE2c1N2qeAA3K4RH9pYgqwets= github.com/cenkalti/backoff/v4 v4.0.2 h1:JIufpQLbh4DkbQoii76ItQIUFzevQSqOLZca4eamEDs= github.com/cenkalti/backoff/v4 v4.0.2/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -306,7 +304,6 @@ github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NM github.com/pingcap/sysutil v0.0.0-20200408114249-ed3bd6f7fdb1 h1:PI8YpTl45F8ilNkrPtT4IdbcZB1SCEa+gK/U5GJYl3E= github.com/pingcap/sysutil v0.0.0-20200408114249-ed3bd6f7fdb1/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/pkg/autoscaling/datasource/prometheus.go b/pkg/autoscaling/datasource/prometheus.go deleted file mode 100644 index 074c6d989c82..000000000000 --- a/pkg/autoscaling/datasource/prometheus.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2020 TiKV Project Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package datasource - -import ( - "context" - "fmt" - "time" - - "github.com/pingcap/errors" - "github.com/pingcap/log" - promClient "github.com/prometheus/client_golang/api" - promAPI "github.com/prometheus/client_golang/api/prometheus/v1" - promModel "github.com/prometheus/common/model" - types "github.com/tikv/pd/pkg/autoscaling" - "go.uber.org/zap" -) - -const ( - tikvSumCPUUsageMetricsPattern = `sum(increase(tikv_thread_cpu_seconds_total[%s])) by (instance)` - tidbSumCPUUsageMetricsPattern = `sum(increase(process_cpu_seconds_total{job="tidb"}[%s])) by (instance)` - tikvCPUQuotaMetricsPattern = `tikv_server_cpu_cores_quota` - tidbCPUQuotaMetricsPattern = `tidb_server_maxprocs` - instanceLabelName = "instance" - - httpRequestTimeout = 5 * time.Second -) - -// PrometheusQuerier query metrics from Prometheus -type PrometheusQuerier struct { - api promAPI.API -} - -// NewPrometheusQuerier returns a PrometheusQuerier -func NewPrometheusQuerier(client promClient.Client) *PrometheusQuerier { - return &PrometheusQuerier{ - api: promAPI.NewAPI(client), - } -} - -type promQLBuilderFn func(*QueryOptions) (string, error) - -var queryBuilderFnMap = map[types.MetricType]promQLBuilderFn{ - types.CPUQuota: buildCPUQuotaPromQL, - types.CPUUsage: buildCPUUsagePromQL, -} - -// Query do the real query on Prometheus and returns metric value for each instance -func (prom *PrometheusQuerier) Query(options *QueryOptions) (QueryResult, error) { - builderFn, ok := queryBuilderFnMap[options.metric] - if !ok { - return nil, errors.Errorf("unsupported metric type %v", options.metric) - } - - query, err := builderFn(options) - if err != nil { - return nil, err - } - - resp, err := prom.queryMetricsFromPrometheus(query, options.timestamp) - if err != nil { - return nil, err - } - - result, err := extractInstancesFromResponse(resp, options.instances) - if err != nil { - return nil, err - } - - return result, nil -} - -func (prom *PrometheusQuerier) queryMetricsFromPrometheus(query string, timestamp time.Time) (promModel.Value, error) { - ctx, cancel := context.WithTimeout(context.Background(), httpRequestTimeout) - defer cancel() - - resp, warnings, err := prom.api.Query(ctx, query, timestamp) - - if err != nil { - return nil, err - } - - if warnings != nil && len(warnings) > 0 { - log.Warn("prometheus query returns with warnings", zap.Strings("warnings", warnings)) - } - - return resp, nil -} - -func extractInstancesFromResponse(resp promModel.Value, instances []string) (QueryResult, error) { - if resp == nil { - return nil, errors.New("metrics response from Prometheus is empty") - } - - if resp.Type() != promModel.ValVector { - return nil, errors.Errorf("expected vector type values, got %s", resp.Type().String()) - } - - vector, ok := resp.(promModel.Vector) - - if !ok { - return nil, errors.New("type conversion error") - } - - if len(vector) == 0 { - return nil, errors.New("no results returned from Prometheus") - } - - instancesSet := map[string]struct{}{} - for _, instance := range instances { - instancesSet[instance] = struct{}{} - } - - result := make(QueryResult) - - for _, sample := range vector { - if instance, ok := sample.Metric[instanceLabelName]; ok { - if _, ok := instancesSet[string(instance)]; ok { - result[string(instance)] = float64(sample.Value) - } - } - } - - return result, nil -} - -var cpuUsagePromQLTemplate = map[types.ComponentType]string{ - types.TiDB: tidbSumCPUUsageMetricsPattern, - types.TiKV: tikvSumCPUUsageMetricsPattern, -} - -var cpuQuotaPromQLTemplate = map[types.ComponentType]string{ - types.TiDB: tidbCPUQuotaMetricsPattern, - types.TiKV: tikvCPUQuotaMetricsPattern, -} - -func buildCPUQuotaPromQL(options *QueryOptions) (string, error) { - pattern, ok := cpuQuotaPromQLTemplate[options.component] - if !ok { - return "", errors.Errorf("unsupported component type %v", options.component) - } - - query := pattern - return query, nil -} - -func buildCPUUsagePromQL(options *QueryOptions) (string, error) { - pattern, ok := cpuUsagePromQLTemplate[options.component] - if !ok { - return "", errors.Errorf("unsupported component type %v", options.component) - } - - query := fmt.Sprintf(pattern, options.duration.String()) - return query, nil -} diff --git a/pkg/etcdutil/etcdutil.go b/pkg/etcdutil/etcdutil.go index 6c7d9991c202..9a838f1dec15 100644 --- a/pkg/etcdutil/etcdutil.go +++ b/pkg/etcdutil/etcdutil.go @@ -20,8 +20,8 @@ import ( "time" "github.com/gogo/protobuf/proto" + "github.com/pingcap/errors" "github.com/pingcap/log" - "github.com/pkg/errors" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/etcdserver" "go.etcd.io/etcd/pkg/types" diff --git a/server/api/component.go b/server/api/component.go index a8c445599811..e0b56263e0c2 100644 --- a/server/api/component.go +++ b/server/api/component.go @@ -14,11 +14,11 @@ package api import ( - "errors" "net/http" "github.com/gorilla/mux" "github.com/pingcap/errcode" + "github.com/pingcap/errors" "github.com/tikv/pd/pkg/apiutil" "github.com/tikv/pd/server" "github.com/unrolled/render" diff --git a/server/cluster/coordinator.go b/server/cluster/coordinator.go index 9a2eeb455646..636d854e229c 100644 --- a/server/cluster/coordinator.go +++ b/server/cluster/coordinator.go @@ -24,11 +24,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/log" -<<<<<<< HEAD - "github.com/pkg/errors" "github.com/tikv/pd/pkg/keyutil" -======= ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) "github.com/tikv/pd/pkg/logutil" "github.com/tikv/pd/server/config" "github.com/tikv/pd/server/schedule" diff --git a/server/cluster/version.go b/server/cluster/version.go index 62421587b31a..a48e9805d7c7 100644 --- a/server/cluster/version.go +++ b/server/cluster/version.go @@ -15,8 +15,8 @@ package cluster import ( "github.com/coreos/go-semver/semver" + "github.com/pingcap/errors" "github.com/pingcap/log" - "github.com/pkg/errors" "go.uber.org/zap" ) diff --git a/server/election/leadership.go b/server/election/leadership.go deleted file mode 100644 index f3f6d5d7e743..000000000000 --- a/server/election/leadership.go +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2020 TiKV Project Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package election - -import ( - "context" - "sync/atomic" - - "github.com/pingcap/errors" - "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/pingcap/log" - "github.com/tikv/pd/pkg/etcdutil" - "github.com/tikv/pd/server/kv" - "go.etcd.io/etcd/clientv3" - "go.uber.org/zap" -) - -// GetLeader gets the coresponding leader from etcd by given leaderPath (as the key). -func GetLeader(c *clientv3.Client, leaderPath string) (*pdpb.Member, int64, error) { - leader := &pdpb.Member{} - ok, rev, err := etcdutil.GetProtoMsgWithModRev(c, leaderPath, leader) - if err != nil { - return nil, 0, err - } - if !ok { - return nil, 0, nil - } - - return leader, rev, nil -} - -// Leadership is used to manage the leadership campaigning. -type Leadership struct { - // purpose is used to show what this election for - Purpose string - // The lease which is used to get this leadership - lease atomic.Value // stored as *lease - client *clientv3.Client - // leaderKey and leaderValue are key-value pair in etcd - leaderKey string - leaderValue string -} - -// NewLeadership creates a new Leadership. -func NewLeadership(client *clientv3.Client, purpose string) *Leadership { - leadership := &Leadership{ - Purpose: purpose, - client: client, - } - return leadership -} - -// getLease gets the lease of leadership, only if leadership is valid, -// i.e the owner is a true leader, the lease is not nil. -func (ls *Leadership) getLease() *lease { - l := ls.lease.Load() - if l == nil { - return nil - } - return l.(*lease) -} - -func (ls *Leadership) setLease(lease *lease) { - ls.lease.Store(lease) -} - -// ResetLease sets the lease of leadership to nil. -func (ls *Leadership) resetLease() { - ls.setLease(nil) -} - -// Campaign is used to campaign the leader with given lease and returns a leadership -func (ls *Leadership) Campaign(leaseTimeout int64, leaderPath, leaderData string) error { - ls.leaderKey = leaderPath - ls.leaderValue = leaderData - // Create a new lease to campaign - ls.setLease(&lease{ - Purpose: ls.Purpose, - client: ls.client, - lease: clientv3.NewLease(ls.client), - }) - if err := ls.getLease().Grant(leaseTimeout); err != nil { - return err - } - // The leader key must not exist, so the CreateRevision is 0. - resp, err := kv.NewSlowLogTxn(ls.client). - If(clientv3.Compare(clientv3.CreateRevision(leaderPath), "=", 0)). - Then(clientv3.OpPut(leaderPath, leaderData, clientv3.WithLease(ls.getLease().ID))). - Commit() - log.Info("check campaign resp", zap.Any("resp", resp), zap.Error(err)) - if err != nil { - return errors.WithStack(err) - } - if !resp.Succeeded { - return errors.New("failed to campaign leader, other server may campaign ok") - } - log.Info("write leaderDate to leaderPath ok", zap.String("leaderPath", leaderPath), zap.String("purpose", ls.Purpose)) - return nil -} - -// Keep will keep the leadership available by update the lease's expired time continuously -func (ls *Leadership) Keep(ctx context.Context) { - ls.getLease().KeepAlive(ctx) -} - -// Check returns whether the leadership is still avalibale -func (ls *Leadership) Check() bool { - return ls != nil && ls.getLease() != nil && !ls.getLease().IsExpired() -} - -// LeaderTxn returns txn() with a leader comparison to guarantee that -// the transaction can be executed only if the server is leader. -func (ls *Leadership) LeaderTxn(cs ...clientv3.Cmp) clientv3.Txn { - txn := kv.NewSlowLogTxn(ls.client) - return txn.If(append(cs, ls.leaderCmp())...) -} - -func (ls *Leadership) leaderCmp() clientv3.Cmp { - return clientv3.Compare(clientv3.Value(ls.leaderKey), "=", ls.leaderValue) -} - -// DeleteLeader deletes the coresponding leader from etcd by given leaderPath (as the key). -func (ls *Leadership) DeleteLeader() error { - // delete leader itself and let others start a new election again. - resp, err := ls.LeaderTxn().Then(clientv3.OpDelete(ls.leaderKey)).Commit() - if err != nil { - return errors.WithStack(err) - } - if !resp.Succeeded { - return errors.New("resign leader failed, we are not leader already") - } - - return nil -} - -// Reset does some defer job such as closing lease, resetting lease etc. -func (ls *Leadership) Reset() { - ls.getLease().Close() - ls.resetLease() -} diff --git a/server/kv/etcd_kv.go b/server/kv/etcd_kv.go index 7ba79f152cb0..b0d5458efa04 100644 --- a/server/kv/etcd_kv.go +++ b/server/kv/etcd_kv.go @@ -21,11 +21,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/log" -<<<<<<< HEAD - "github.com/pkg/errors" -======= - "github.com/tikv/pd/pkg/errs" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) "github.com/tikv/pd/pkg/etcdutil" "go.etcd.io/etcd/clientv3" "go.uber.org/zap" diff --git a/server/member/leader.go b/server/member/leader.go index 0be4ea1aaf00..198a3b263c1f 100644 --- a/server/member/leader.go +++ b/server/member/leader.go @@ -29,11 +29,6 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" -<<<<<<< HEAD:server/member/leader.go - "github.com/pkg/errors" -======= - "github.com/tikv/pd/pkg/errs" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644):server/member/member.go "github.com/tikv/pd/pkg/etcdutil" "github.com/tikv/pd/server/config" "github.com/tikv/pd/server/kv" diff --git a/server/member/lease.go b/server/member/lease.go index ea5156ea4b72..2c00d7e490c0 100644 --- a/server/member/lease.go +++ b/server/member/lease.go @@ -20,11 +20,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/log" -<<<<<<< HEAD:server/member/lease.go - "github.com/pkg/errors" -======= - "github.com/tikv/pd/pkg/etcdutil" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644):server/election/lease.go "go.etcd.io/etcd/clientv3" "go.uber.org/zap" ) diff --git a/server/schedule/placement/rule_list.go b/server/schedule/placement/rule_list.go index d7f3e570ccdf..7dcd41be1bc6 100644 --- a/server/schedule/placement/rule_list.go +++ b/server/schedule/placement/rule_list.go @@ -16,19 +16,10 @@ package placement import ( "bytes" "encoding/hex" -<<<<<<< HEAD - "sort" - "strings" - - "github.com/pkg/errors" -======= - "fmt" "sort" "strings" "github.com/pingcap/errors" - "github.com/tikv/pd/pkg/errs" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) ) type splitPointType int diff --git a/server/schedule/placement/rule_manager.go b/server/schedule/placement/rule_manager.go index 0361c494ee94..8be530cb23c1 100644 --- a/server/schedule/placement/rule_manager.go +++ b/server/schedule/placement/rule_manager.go @@ -19,8 +19,8 @@ import ( "encoding/json" "sync" + "github.com/pingcap/errors" "github.com/pingcap/log" - "github.com/pkg/errors" "github.com/tikv/pd/server/core" "go.uber.org/zap" ) diff --git a/server/schedulers/utils.go b/server/schedulers/utils.go index d22eb28f2048..78e63e10427a 100644 --- a/server/schedulers/utils.go +++ b/server/schedulers/utils.go @@ -22,11 +22,6 @@ import ( "github.com/montanaflynn/stats" "github.com/pingcap/errors" "github.com/pingcap/log" -<<<<<<< HEAD - "github.com/pkg/errors" -======= - "github.com/tikv/pd/pkg/typeutil" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) "github.com/tikv/pd/server/core" "github.com/tikv/pd/server/schedule/operator" "github.com/tikv/pd/server/schedule/opt" diff --git a/server/tso/tso.go b/server/tso/tso.go index 100b906e806f..3122b02a0158 100644 --- a/server/tso/tso.go +++ b/server/tso/tso.go @@ -24,11 +24,6 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" -<<<<<<< HEAD - "github.com/pkg/errors" -======= - "github.com/tikv/pd/pkg/errs" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) "github.com/tikv/pd/pkg/etcdutil" "github.com/tikv/pd/pkg/tsoutil" "github.com/tikv/pd/pkg/typeutil" diff --git a/server/versioninfo/versioninfo.go b/server/versioninfo/versioninfo.go index 7b7443e59108..f04293bd2190 100644 --- a/server/versioninfo/versioninfo.go +++ b/server/versioninfo/versioninfo.go @@ -13,16 +13,6 @@ package versioninfo -<<<<<<< HEAD -======= -import ( - "github.com/coreos/go-semver/semver" - "github.com/pingcap/errors" - "github.com/pingcap/log" - "go.uber.org/zap" -) - ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) const ( // CommunityEdition is the default edition for building. CommunityEdition = "Community" diff --git a/tests/cluster.go b/tests/cluster.go index a47c075af714..dd1f707a84e9 100644 --- a/tests/cluster.go +++ b/tests/cluster.go @@ -25,11 +25,6 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" -<<<<<<< HEAD - "github.com/pkg/errors" -======= - "github.com/tikv/pd/pkg/autoscaling" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) "github.com/tikv/pd/pkg/dashboard" "github.com/tikv/pd/pkg/swaggerserver" "github.com/tikv/pd/server" diff --git a/tools/pd-tso-bench/main.go b/tools/pd-tso-bench/main.go index 4264b48ac92e..6c82929bf584 100644 --- a/tools/pd-tso-bench/main.go +++ b/tools/pd-tso-bench/main.go @@ -25,11 +25,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/log" -<<<<<<< HEAD - "github.com/pkg/errors" -======= - "github.com/prometheus/client_golang/prometheus/promhttp" ->>>>>>> bcfa77a... *: unify error handling by removing pkg/errors (#2644) pd "github.com/tikv/pd/client" "go.uber.org/zap" ) diff --git a/tools/stores-dump/main.go b/tools/stores-dump/main.go deleted file mode 100644 index 19868440ee36..000000000000 --- a/tools/stores-dump/main.go +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2020 TiKV Project Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "bufio" - "flag" - "fmt" - "math" - "os" - "path" - "strconv" - "strings" - "time" - - "github.com/pingcap/errors" - "github.com/pingcap/kvproto/pkg/metapb" - "github.com/tikv/pd/pkg/etcdutil" - "go.etcd.io/etcd/clientv3" - "go.etcd.io/etcd/pkg/transport" -) - -var ( - clusterID = flag.Uint64("cluster-id", 0, "please make cluster ID match with TiKV") - endpoints = flag.String("endpoints", "http://127.0.0.1:2379", "endpoints urls") - filePath = flag.String("file", "stores.dump", "dump file path and name") - caPath = flag.String("cacert", "", "path of file that contains list of trusted SSL CAs") - certPath = flag.String("cert", "", "path of file that contains X509 certificate in PEM format") - keyPath = flag.String("key", "", "path of file that contains X509 key in PEM format") -) - -const ( - etcdTimeout = 1200 * time.Second - pdRootPath = "/pd" - minKVRangeLimit = 100 - clusterPath = "raft" -) - -var ( - rootPath = "" -) - -func checkErr(err error) { - if err != nil { - fmt.Println(err.Error()) - os.Exit(1) - } -} - -func main() { - flag.Parse() - - rootPath = path.Join(pdRootPath, strconv.FormatUint(*clusterID, 10)) - f, err := os.Create(*filePath) - checkErr(err) - defer f.Close() - - urls := strings.Split(*endpoints, ",") - - tlsInfo := transport.TLSInfo{ - CertFile: *certPath, - KeyFile: *keyPath, - TrustedCAFile: *caPath, - } - tlsConfig, err := tlsInfo.ClientConfig() - checkErr(err) - - client, err := clientv3.New(clientv3.Config{ - Endpoints: urls, - DialTimeout: etcdTimeout, - TLS: tlsConfig, - }) - checkErr(err) - - err = loadStores(client, f) - checkErr(err) - fmt.Println("successful!") -} - -func loadStores(client *clientv3.Client, f *os.File) error { - nextID := uint64(0) - endKey := path.Join(clusterPath, "s", fmt.Sprintf("%020d", uint64(math.MaxUint64))) - w := bufio.NewWriter(f) - defer w.Flush() - for { - key := path.Join(clusterPath, "s", fmt.Sprintf("%020d", nextID)) - _, res, err := loadRange(client, key, endKey, minKVRangeLimit) - if err != nil { - return err - } - for _, str := range res { - store := &metapb.Store{} - if err := store.Unmarshal([]byte(str)); err != nil { - return errors.WithStack(err) - } - - nextID = store.GetId() + 1 - fmt.Fprintln(w, store) - } - if len(res) < minKVRangeLimit { - return nil - } - } -} - -func loadRange(client *clientv3.Client, key, endKey string, limit int) ([]string, []string, error) { - key = path.Join(rootPath, key) - endKey = path.Join(rootPath, endKey) - - withRange := clientv3.WithRange(endKey) - withLimit := clientv3.WithLimit(int64(limit)) - resp, err := etcdutil.EtcdKVGet(client, key, withRange, withLimit) - if err != nil { - return nil, nil, err - } - keys := make([]string, 0, len(resp.Kvs)) - values := make([]string, 0, len(resp.Kvs)) - for _, item := range resp.Kvs { - keys = append(keys, strings.TrimPrefix(strings.TrimPrefix(string(item.Key), rootPath), "/")) - values = append(values, string(item.Value)) - } - return keys, values, nil -}