diff --git a/.gitignore b/.gitignore index 6345f4f4e30..4c2ce9d9eba 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ default.pd *.swp .DS_Store tags -/_tools/ +/.retools/ diff --git a/Makefile b/Makefile index 823be966b1e..672386e1391 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,10 @@ BASIC_TEST_PKGS := $(filter-out github.com/pingcap/pd/pkg/integration_test,$(TES PACKAGES := go list ./... PACKAGE_DIRECTORIES := $(PACKAGES) | sed 's|github.com/pingcap/pd/||' GOCHECKER := awk '{ print } END { if (NR > 0) { exit 1 } }' +RETOOL:= ./hack/retool -GOFAIL_ENABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|vendor)" | xargs retool do gofail enable) -GOFAIL_DISABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|vendor)" | xargs retool do gofail disable) +GOFAIL_ENABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|vendor)" | xargs ./hack/retool do gofail enable) +GOFAIL_DISABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|vendor)" | xargs ./hack/retool do gofail disable) LDFLAGS += -X "$(PD_PKG)/server.PDReleaseVersion=$(shell git describe --tags --dirty)" LDFLAGS += -X "$(PD_PKG)/server.PDBuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')" @@ -35,9 +36,9 @@ ifeq ("$(WITH_RACE)", "1") else CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o bin/pd-server cmd/pd-server/main.go endif - CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o bin/pd-ctl cmd/pd-ctl/main.go - CGO_ENABLED=0 go build -o bin/pd-tso-bench cmd/pd-tso-bench/main.go - CGO_ENABLED=0 go build -o bin/pd-recover cmd/pd-recover/main.go + CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o bin/pd-ctl tools/pd-ctl/main.go + CGO_ENABLED=0 go build -o bin/pd-tso-bench tools/pd-tso-bench/main.go + CGO_ENABLED=0 go build -o bin/pd-recover tools/pd-recover/main.go test: retool-setup # testing.. @@ -52,26 +53,26 @@ basic_test: # These need to be fixed before they can be ran regularly check-fail: - CGO_ENABLED=0 retool do gometalinter.v2 --disable-all \ + CGO_ENABLED=0 ./hack/retool do gometalinter.v2 --disable-all \ --enable errcheck \ $$($(PACKAGE_DIRECTORIES)) - CGO_ENABLED=0 retool do gosec $$($(PACKAGE_DIRECTORIES)) + CGO_ENABLED=0 ./hack/retool do gosec $$($(PACKAGE_DIRECTORIES)) check-all: static lint @echo "checking" retool-setup: @which retool >/dev/null 2>&1 || go get github.com/twitchtv/retool - @retool sync + @./hack/retool sync check: retool-setup check-all static: @ # Not running vet and fmt through metalinter becauase it ends up looking at vendor gofmt -s -l $$($(PACKAGE_DIRECTORIES)) 2>&1 | $(GOCHECKER) - retool do govet --shadow $$($(PACKAGE_DIRECTORIES)) 2>&1 | $(GOCHECKER) + ./hack/retool do govet --shadow $$($(PACKAGE_DIRECTORIES)) 2>&1 | $(GOCHECKER) - CGO_ENABLED=0 retool do gometalinter.v2 --disable-all --deadline 120s \ + CGO_ENABLED=0 ./hack/retool do gometalinter.v2 --disable-all --deadline 120s \ --enable misspell \ --enable megacheck \ --enable ineffassign \ @@ -79,7 +80,7 @@ static: lint: @echo "linting" - CGO_ENABLED=0 retool do revive -formatter friendly -config revive.toml $$($(PACKAGES)) + CGO_ENABLED=0 ./hack/retool do revive -formatter friendly -config revive.toml $$($(PACKAGES)) travis_coverage: ifeq ("$(TRAVIS_COVERAGE)", "1") @@ -100,7 +101,7 @@ endif bash ./hack/clean_vendor.sh simulator: - CGO_ENABLED=0 go build -o bin/simulator cmd/simulator/main.go + CGO_ENABLED=0 go build -o bin/pd-simulator tools/pd-simulator/main.go gofail-enable: # Converting gofail failpoints... diff --git a/pd-client/client.go b/client/client.go similarity index 100% rename from pd-client/client.go rename to client/client.go diff --git a/pd-client/client_test.go b/client/client_test.go similarity index 100% rename from pd-client/client_test.go rename to client/client_test.go diff --git a/pd-client/metrics.go b/client/metrics.go similarity index 100% rename from pd-client/metrics.go rename to client/metrics.go diff --git a/cmd/README.md b/cmd/README.md deleted file mode 100644 index 47c2fecd124..00000000000 --- a/cmd/README.md +++ /dev/null @@ -1,4 +0,0 @@ -## cmd - -This directory is meant to enforce vendoring for pd binaries without polluting -the pd client libraries with vendored dependencies. diff --git a/hack/retool b/hack/retool new file mode 100755 index 00000000000..de9950a7004 --- /dev/null +++ b/hack/retool @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# +# Add standard retool options +set -euo pipefail + + +cd $(dirname "$0")/.. +exec retool -tool-dir "$PWD/.retools" "$@" diff --git a/hack/retool-install.sh b/hack/retool-install.sh index ba3fbca887b..0ca3f0ca97c 100755 --- a/hack/retool-install.sh +++ b/hack/retool-install.sh @@ -3,21 +3,23 @@ set -euo pipefail # This script generates tools.json # It helps record what releases/branches are being used + +cd $(dirname "$0")/.. which retool >/dev/null || go get github.com/twitchtv/retool # tool environment # check runner -retool add gopkg.in/alecthomas/gometalinter.v2 v2.0.5 +./hack/retool add gopkg.in/alecthomas/gometalinter.v2 v2.0.5 # check spelling -retool add github.com/client9/misspell/cmd/misspell v0.3.4 +./hack/retool add github.com/client9/misspell/cmd/misspell v0.3.4 # checks correctness -retool add github.com/gordonklaus/ineffassign 7bae11eba15a3285c75e388f77eb6357a2d73ee2 -retool add honnef.co/go/tools/cmd/megacheck master -retool add github.com/dnephin/govet 4a96d43e39d340b63daa8bc5576985aa599885f6 +./hack/retool add github.com/gordonklaus/ineffassign 7bae11eba15a3285c75e388f77eb6357a2d73ee2 +./hack/retool add honnef.co/go/tools/cmd/megacheck master +./hack/retool add github.com/dnephin/govet 4a96d43e39d340b63daa8bc5576985aa599885f6 # slow checks -retool add github.com/kisielk/errcheck v1.1.0 +./hack/retool add github.com/kisielk/errcheck v1.1.0 # linter -retool add github.com/mgechev/revive 7773f47324c2bf1c8f7a5500aff2b6c01d3ed73b -retool add github.com/securego/gosec/cmd/gosec 1.0.0 +./hack/retool add github.com/mgechev/revive 7773f47324c2bf1c8f7a5500aff2b6c01d3ed73b +./hack/retool add github.com/securego/gosec/cmd/gosec 1.0.0 # go fail -retool add github.com/etcd-io/gofail master +./hack/retool add github.com/etcd-io/gofail master diff --git a/pdctl/README.md b/pdctl/README.md deleted file mode 100644 index 7d5e7f7aaba..00000000000 --- a/pdctl/README.md +++ /dev/null @@ -1,103 +0,0 @@ -pdctl -======== - -pdctl is a command line tool for pd - -## Build -1. Make sure [*Go*](https://golang.org/) (version 1.5+) is installed. -2. Use `make` in pd root path. `pdctl` will build in `bin` directory. - -## Usage - -### Example -run: - - ./pd-ctl store -d -u 127.0.0.1:2379 -show all stores status. '-u' specify the pd address, it can be overwritten by setting the environment variable PD_ADDR. Such as `export PD_ADDR=127.0.0.1:2379` - -### Flags -#### --pd,-u -+ The pd address -+ default: http://127.0.0.1:2379 -+ env variable: PD_ADDR - -#### --detach,-d -+ Run pdctl without readline -+ default: false - -### Command -#### store [delete] -show the store status or delete a store - -##### example -``` ->> store -{ - "count": 3, - "stores": [...] -} ->> store 1 - ...... ->> store delete 1 - ...... -``` - -#### config [show | set \ \] -show or set the balance config -##### example -``` ->> config show -{ - "min-region-count": 10, - "min-leader-count": 10, - "max-snapshot-count": 3, - "min-balance-diff-ratio": 0.01, - "max-store-down-duration": "30m0s", - "leader-schedule-limit": 8, - "leader-schedule-interval": "10s", - "storage-schedule-limit": 4, - "storage-schedule-interval": "30s" -} ->> config set leader-schedule-interval 20s -Success! -``` - -#### Member [leader | delete] -show the pd members status -##### example -``` ->> member -{ - "members": [......] -} ->> member leader -{ - "name": "pd", - "addr": "http://192.168.199.229:2379", - "id": 9724873857558226554 -} ->> member delete name pd2 -Success! -``` - -#### Region -show one or all regions status -##### Example -``` ->> region -{ - "count": 1, - "regions": [......] -} - ->> region 2 -{ - "region": { - "id": 2, - ...... - } - "leader": { - ...... - } -} -``` diff --git a/pkg/integration_test/client_test.go b/pkg/integration_test/client_test.go index 3e4ffe12a81..a40e4316e24 100644 --- a/pkg/integration_test/client_test.go +++ b/pkg/integration_test/client_test.go @@ -23,7 +23,7 @@ import ( "github.com/coreos/etcd/clientv3" . "github.com/pingcap/check" - pd "github.com/pingcap/pd/pd-client" + pd "github.com/pingcap/pd/client" "github.com/pingcap/pd/pkg/testutil" ) diff --git a/server/testutil.go b/server/testutil.go index 1b4cc7af41d..8297ec0dc4b 100644 --- a/server/testutil.go +++ b/server/testutil.go @@ -57,7 +57,7 @@ func NewTestServer() (*Config, *Server, CleanupFunc, error) { } // NewTestSingleConfig is only for test to create one pd. -// Because pd-client also needs this, so export here. +// Because PD client also needs this, so export here. func NewTestSingleConfig() *Config { cfg := &Config{ Name: "pd", @@ -93,7 +93,7 @@ func NewTestSingleConfig() *Config { } // NewTestMultiConfig is only for test to create multiple pd configurations. -// Because pd-client also needs this, so export here. +// Because PD client also needs this, so export here. func NewTestMultiConfig(count int) []*Config { cfgs := make([]*Config, count) diff --git a/tools/pd-ctl/README.md b/tools/pd-ctl/README.md new file mode 100644 index 00000000000..690d8c9f017 --- /dev/null +++ b/tools/pd-ctl/README.md @@ -0,0 +1,686 @@ +pd-ctl +======== + +pd-ctl is a command line tool for PD, pd-ctl obtains the state information of the cluster and tunes the cluster. + +## Build +1. [Go](https://golang.org/) Version 1.9 or later +2. In the root directory of the [PD project](https://github.com/pingcap/pd), use the `make` command to compile and generate `bin/pd-ctl` + +> **Note:** Generally, you don't need to compile source code as the PD Control tool already exists in the released Binary or Docker. However, dev users can refer to the above instruction for compiling source code. + +## Usage + +Single-command mode: + + ./pd-ctl store -d -u http://127.0.0.1:2379 + +Interactive mode: + + ./pd-ctl -u http://127.0.0.1:2379 + +Use environment variables: + +```bash +export PD_ADDR=http://127.0.0.1:2379 +./pd-ctl +``` + +Use TLS to encrypt: + +```bash +./pd-ctl -u https://127.0.0.1:2379 --cacert="path/to/ca" --cert="path/to/cert" --key="path/to/key" +``` + +## Command line flags + +### \-\-pd,-u + ++ PD address ++ Default address: http://127.0.0.1:2379 ++ Enviroment variable: PD_ADDR + +### \-\-detach,-d + ++ Use single command line mode (not entering readline) ++ Default: false + +### --cacert + ++ Specify the path to the certificate file of the trusted CA in PEM format ++ Default: "" + +### --cert + ++ Specify the path to the certificate of SSL in PEM format ++ Default: "" + +### --key + ++ Specify the path to the certificate key file of SSL in PEM format, which is the private key of the certificate specified by `--cert` ++ Default: "" + +### --version,-V + ++ Print the version information and exit ++ Default: false + +## Command + +### `cluster` + +Use this command to view the basic information of the cluster. + +Usage: + +```bash +>> cluster // To show the cluster information +{ + "id": 6493707687106161130, + "max_peer_count": 3 +} +``` + +### `config [show | set