-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: husharp <jinhao.hu@pingcap.com>
- Loading branch information
Showing
77 changed files
with
2,246 additions
and
1,779 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# pd-dev | ||
|
||
pd-dev is a tool for developing and testing PD. It provides the following functions: | ||
|
||
- [pd-api-bench](./pd-api-bench/README.md): A tool for testing the performance of PD's API. | ||
- [pd-tso-bench](./pd-tso-bench/README.md): A tool for testing the performance of PD's TSO. | ||
- [pd-heartbeat-bench](./pd-heartbeat-bench/README.md): A tool for testing the performance of PD's heartbeat. | ||
- [pd-simulator](./pd-simulator/README.md): A tool for simulating the PD cluster. | ||
- [regions-dump](./regions-dump/README.md): A tool for dumping the region information of the PD cluster. | ||
- [stores-dump](./stores-dump/README.md): A tool for dumping the store information of the PD cluster. | ||
|
||
## Build | ||
|
||
1. [Go](https://golang.org/) Version 1.21 or later | ||
2. In the root directory of the [PD project](https://github.com/tikv/pd), use the `make pd-dev` command to compile and generate `bin/pd-dev` | ||
|
||
## Usage | ||
|
||
This section describes how to use the `pd-dev` tool. | ||
|
||
### Cases | ||
|
||
Please read related README files for more details, we support the following cases: | ||
|
||
`./pd-dev --mode api` | ||
|
||
`./pd-dev --mode tso` | ||
|
||
`./pd-dev --mode heartbeat` | ||
|
||
`./pd-dev --mode simulator` | ||
|
||
`./pd-dev --mode regions-dump` | ||
|
||
`./pd-dev --mode stores-dump` | ||
|
||
`./pd-dev --mode analysis` | ||
|
||
`./pd-dev --mode backup` | ||
|
||
`./pd-dev --mode ut` | ||
|
||
### flag description | ||
|
||
--pd string | ||
> pd address (default "127.0.0.1:2379") | ||
--cacert string | ||
> path of file that contains list of trusted SSL CAs | ||
--cert string | ||
> path of file that contains X509 certificate in PEM format | ||
--key string | ||
> path of file that contains X509 key in PEM format | ||
--config string | ||
> path of configuration file | ||
### TLS | ||
|
||
You can use the following command to generate a certificate for testing TLS: | ||
|
||
```shell | ||
mkdir cert | ||
./cert_opt.sh generate cert | ||
./bin/pd-dev --mode api -http-cases GetRegionStatus-1+1,GetMinResolvedTS-1+1 -client 1 -debug true -cacert ./cert/ca.pem -cert ./cert/pd-server.pem -key ./cert/pd-server-key.pem | ||
./cert_opt.sh cleanup cert | ||
rm -rf cert | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2024 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, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/pingcap/log" | ||
flag "github.com/spf13/pflag" | ||
analysis "github.com/tikv/pd/tools/pd-dev/pd-analysis" | ||
api "github.com/tikv/pd/tools/pd-dev/pd-api-bench" | ||
backup "github.com/tikv/pd/tools/pd-dev/pd-backup" | ||
heartbeat "github.com/tikv/pd/tools/pd-dev/pd-heartbeat-bench" | ||
simulator "github.com/tikv/pd/tools/pd-dev/pd-simulator" | ||
tso "github.com/tikv/pd/tools/pd-dev/pd-tso-bench" | ||
ut "github.com/tikv/pd/tools/pd-dev/pd-ut" | ||
region "github.com/tikv/pd/tools/pd-dev/regions-dump" | ||
store "github.com/tikv/pd/tools/pd-dev/stores-dump" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func switchDevelopmentMode(ctx context.Context, mode string) { | ||
log.Info("pd-dev start", zap.String("mode", mode)) | ||
switch mode { | ||
case "api": | ||
api.Run(ctx) | ||
case "heartbeat": | ||
heartbeat.Run(ctx) | ||
case "tso": | ||
tso.Run(ctx) | ||
case "simulator": | ||
simulator.Run(ctx) | ||
case "regions-dump": | ||
region.Run() | ||
case "stores-dump": | ||
store.Run() | ||
case "analysis": | ||
analysis.Run() | ||
case "backup": | ||
backup.Run() | ||
case "ut": | ||
ut.Run() | ||
default: | ||
log.Fatal("please input a mode to run, or provide a config file to run all modes") | ||
} | ||
} | ||
|
||
func main() { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
|
||
sc := make(chan os.Signal, 1) | ||
signal.Notify(sc, | ||
syscall.SIGHUP, | ||
syscall.SIGINT, | ||
syscall.SIGTERM, | ||
syscall.SIGQUIT) | ||
var sig os.Signal | ||
go func() { | ||
sig = <-sc | ||
cancel() | ||
}() | ||
|
||
// parse first argument | ||
if len(os.Args) < 2 { | ||
log.Fatal("please input a mode to run, or provide a config file to run all modes") | ||
} | ||
|
||
var mode string | ||
fs := flag.NewFlagSet("pd-dev", flag.ContinueOnError) | ||
fs.StringVar(&mode, "mode", "", "mode to run") | ||
fs.Parse(os.Args[1:]) | ||
switchDevelopmentMode(ctx, mode) | ||
|
||
log.Info("pd-dev Exit") | ||
switch sig { | ||
case syscall.SIGTERM: | ||
exit(0) | ||
default: | ||
exit(1) | ||
} | ||
} | ||
|
||
func exit(code int) { | ||
os.Exit(code) | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2024 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, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package analysis | ||
|
||
import ( | ||
flag "github.com/spf13/pflag" | ||
"github.com/tikv/pd/tools/pd-dev/util" | ||
) | ||
|
||
// Config is the heartbeat-bench configuration. | ||
type Config struct { | ||
*util.GeneralConfig | ||
Input string `toml:"input" json:"input"` | ||
Output string `toml:"output" json:"output"` | ||
Style string `toml:"style" json:"style"` | ||
Operator string `toml:"operator" json:"operator"` | ||
Start string `toml:"start" json:"start"` | ||
End string `toml:"end" json:"end"` | ||
} | ||
|
||
// NewConfig return a set of settings. | ||
func newConfig() *Config { | ||
cfg := &Config{ | ||
GeneralConfig: &util.GeneralConfig{}, | ||
} | ||
cfg.FlagSet = flag.NewFlagSet("pd-analysis", flag.ContinueOnError) | ||
fs := cfg.FlagSet | ||
cfg.GeneralConfig = util.NewGeneralConfig(fs) | ||
fs.ParseErrorsWhitelist.UnknownFlags = true | ||
|
||
fs.StringVar(&cfg.Input, "input", "", "input pd log file, required") | ||
fs.StringVar(&cfg.Output, "output", "", "output file, default output to stdout") | ||
fs.StringVar(&cfg.Style, "style", "", "analysis style, e.g. transfer-counter") | ||
fs.StringVar(&cfg.Operator, "operator", "", "operator style, e.g. balance-region, balance-leader, transfer-hot-read-leader, move-hot-read-region, transfer-hot-write-leader, move-hot-write-region") | ||
fs.StringVar(&cfg.Start, "start", "", "start time, e.g. 2019/09/10 12:20:07, default: total file") | ||
fs.StringVar(&cfg.End, "end", "", "end time, e.g. 2019/09/10 14:20:07, default: total file") | ||
|
||
return cfg | ||
} |
Oops, something went wrong.