Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 06ac82e

Browse files
authored
*: borrow the pingcap/chaos's way to manage workloads of TiDB (#23)
* merge pingcap/chaos repo Signed-off-by: mahjonp <[email protected]>
1 parent aba3d31 commit 06ac82e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+6086
-3
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ bin
22
*/bin/**
33

44
.idea
5+
.DS_Store
56
vendor
67
test-infra/vendor
78

89
.vscode
10+

Jepsen-LICENSE

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
SOLIPSISTIC ECLIPSE PUBLIC LICENSE
2+
Version 1, NOVEMBER 2014
3+
Copyright (C) 2014
4+
5+
Everyone is permitted to copy and distribute verbatim copies of this license
6+
document. Modified copies of this document are permitted provided that they
7+
denounce BOTH the original AND their copy as mere sense data with no verifiable
8+
cause outside the mind.
9+
10+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
11+
12+
0. The term `work` refers to the false sense-data distributed with this license.
13+
14+
1. The term `you` refers to the only being who verifiably exists.
15+
16+
2. The term `author` refers to the set of delusions whereby you incorrectly
17+
assign external agency to the work.
18+
19+
3. You may copy, modify and distribute the work in a manner consistent with the
20+
Eclipse Public License provided that you do not believe the Eclipse Foundation
21+
or the author exists, and provided that you affirm publicly when referring to
22+
the work, or when questioned or interrogated by beings who putatively exist,
23+
that the work does not exist.

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@
178178
APPENDIX: How to apply the Apache License to your work.
179179

180180
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "[]"
181+
boilerplate notice, with the fields enclosed by brackets "{}"
182182
replaced with your own identifying information. (Don't include
183183
the brackets!) The text should be enclosed in the appropriate
184184
comment syntax for the file format. We also recommend that a
185185
file or class name and description of purpose be included on the
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright {yyyy} {name of copyright owner}
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
default: build
2+
3+
all: build
4+
5+
build: chaos verifier
6+
7+
chaos: rawkv tidb txnkv
8+
9+
tidb:
10+
GO111MODULE=on go build -o bin/chaos-tidb cmd/tidb/main.go
11+
12+
rawkv:
13+
GO111MODULE=on go build -o bin/chaos-rawkv cmd/rawkv/main.go
14+
15+
txnkv:
16+
GO111MODULE=on go build -o bin/chaos-txnkv cmd/txnkv/main.go
17+
18+
verifier:
19+
GO111MODULE=on go build -o bin/chaos-verifier cmd/verifier/main.go

Porcupine-LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
=====================
3+
4+
**Copyright (c) 2017-2018 Anish Athalye ([email protected])**
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
this software and associated documentation files (the "Software"), to deal in
8+
the Software without restriction, including without limitation the rights to
9+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10+
of the Software, and to permit persons to whom the Software is furnished to do
11+
so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Pocket
22

3-
Pocket is toolkit for testing TiDB with random SQLs.
3+
Pocket borrows [pingcap/chaos](https://github.com/pingcap/chaos)'s way to manage workloads of TiDB cluster running on K8s, and uses [pingcap/chaos-mesh](https://github.com/pingcap/chaos-mesh) to perform nemesises.
4+

cmd/rawkv/main.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"log"
7+
"time"
8+
9+
"github.com/pingcap/tipocket/cmd/util"
10+
"github.com/pingcap/tipocket/db/rawkv"
11+
"github.com/pingcap/tipocket/pkg/check/porcupine"
12+
"github.com/pingcap/tipocket/pkg/control"
13+
"github.com/pingcap/tipocket/pkg/core"
14+
"github.com/pingcap/tipocket/pkg/model"
15+
"github.com/pingcap/tipocket/pkg/verify"
16+
)
17+
18+
var (
19+
requestCount = flag.Int("request-count", 500, "client test request count")
20+
round = flag.Int("round", 3, "client test request count")
21+
runTime = flag.Duration("run-time", 10*time.Minute, "client test run time")
22+
clientCase = flag.String("case", "register", "client test case, like register")
23+
historyFile = flag.String("history", "./history.log", "history file")
24+
nemesises = flag.String("nemesis", "", "nemesis, seperated by name, like random_kill,all_kill")
25+
)
26+
27+
func main() {
28+
flag.Parse()
29+
30+
cfg := control.Config{
31+
DB: "rawkv",
32+
RequestCount: *requestCount,
33+
RunRound: *round,
34+
RunTime: *runTime,
35+
History: *historyFile,
36+
}
37+
38+
var creator core.ClientCreator
39+
switch *clientCase {
40+
case "register":
41+
creator = rawkv.RegisterClientCreator{}
42+
default:
43+
log.Fatalf("invalid client test case %s", *clientCase)
44+
}
45+
46+
verifySuit := verify.Suit{
47+
Model: model.RegisterModel(),
48+
Checker: porcupine.Checker{},
49+
Parser: model.RegisterParser(),
50+
}
51+
suit := util.Suit{
52+
Config: &cfg,
53+
ClientCreator: creator,
54+
Nemesises: *nemesises,
55+
VerifySuit: verifySuit,
56+
}
57+
suit.Run(context.Background(), []string{})
58+
}

cmd/tidb/main.go

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"log"
7+
"net/http"
8+
_ "net/http/pprof"
9+
"time"
10+
11+
"github.com/pingcap/tipocket/cmd/util"
12+
"github.com/pingcap/tipocket/db/tidb"
13+
"github.com/pingcap/tipocket/pkg/check/porcupine"
14+
"github.com/pingcap/tipocket/pkg/control"
15+
"github.com/pingcap/tipocket/pkg/core"
16+
"github.com/pingcap/tipocket/pkg/verify"
17+
)
18+
19+
var (
20+
requestCount = flag.Int("request-count", 500, "client test request count")
21+
round = flag.Int("round", 3, "client test request count")
22+
runTime = flag.Duration("run-time", 10*time.Minute, "client test run time")
23+
clientCase = flag.String("case", "bank", "client test case, like bank,multi_bank")
24+
historyFile = flag.String("history", "./history.log", "history file")
25+
nemesises = flag.String("nemesis", "", "nemesis, seperated by name, like random_kill,all_kill")
26+
checkerNames = flag.String("checker", "porcupine", "checker name, eg, porcupine, tidb_bank_tso")
27+
pprofAddr = flag.String("pprof", "0.0.0.0:8080", "Pprof address")
28+
)
29+
30+
func main() {
31+
flag.Parse()
32+
33+
go func() {
34+
http.ListenAndServe(*pprofAddr, nil)
35+
}()
36+
37+
cfg := control.Config{
38+
DB: "tidb",
39+
RequestCount: *requestCount,
40+
RunRound: *round,
41+
RunTime: *runTime,
42+
History: *historyFile,
43+
}
44+
45+
var creator core.ClientCreator
46+
switch *clientCase {
47+
case "bank":
48+
creator = tidb.BankClientCreator{}
49+
case "multi_bank":
50+
creator = tidb.MultiBankClientCreator{}
51+
case "long_fork":
52+
creator = tidb.LongForkClientCreator{}
53+
case "sequential":
54+
creator = tidb.SequentialClientCreator{}
55+
default:
56+
log.Fatalf("invalid client test case %s", *clientCase)
57+
}
58+
59+
parser := tidb.BankParser()
60+
model := tidb.BankModel()
61+
var checker core.Checker
62+
switch *checkerNames {
63+
case "porcupine":
64+
checker = porcupine.Checker{}
65+
case "tidb_bank_tso":
66+
checker = tidb.BankTsoChecker()
67+
case "long_fork_checker":
68+
checker = tidb.LongForkChecker()
69+
parser = tidb.LongForkParser()
70+
model = nil
71+
case "sequential_checker":
72+
checker = tidb.NewSequentialChecker()
73+
parser = tidb.NewSequentialParser()
74+
model = nil
75+
default:
76+
log.Fatalf("invalid checker %s", *checkerNames)
77+
}
78+
79+
verifySuit := verify.Suit{
80+
Model: model,
81+
Checker: checker,
82+
Parser: parser,
83+
}
84+
suit := util.Suit{
85+
Config: &cfg,
86+
ClientCreator: creator,
87+
Nemesises: *nemesises,
88+
VerifySuit: verifySuit,
89+
}
90+
suit.Run(context.Background(), []string{})
91+
}

cmd/txnkv/main.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"log"
7+
"time"
8+
9+
"github.com/pingcap/tipocket/cmd/util"
10+
"github.com/pingcap/tipocket/db/txnkv"
11+
"github.com/pingcap/tipocket/pkg/check/porcupine"
12+
"github.com/pingcap/tipocket/pkg/control"
13+
"github.com/pingcap/tipocket/pkg/core"
14+
"github.com/pingcap/tipocket/pkg/model"
15+
"github.com/pingcap/tipocket/pkg/verify"
16+
)
17+
18+
var (
19+
requestCount = flag.Int("request-count", 500, "client test request count")
20+
round = flag.Int("round", 3, "client test request count")
21+
runTime = flag.Duration("run-time", 10*time.Minute, "client test run time")
22+
clientCase = flag.String("case", "register", "client test case, like register")
23+
historyFile = flag.String("history", "./history.log", "history file")
24+
nemesises = flag.String("nemesis", "", "nemesis, seperated by name, like random_kill,all_kill")
25+
)
26+
27+
func main() {
28+
flag.Parse()
29+
30+
cfg := control.Config{
31+
DB: "txnkv",
32+
RequestCount: *requestCount,
33+
RunRound: *round,
34+
RunTime: *runTime,
35+
History: *historyFile,
36+
}
37+
38+
var creator core.ClientCreator
39+
switch *clientCase {
40+
case "register":
41+
creator = txnkv.RegisterClientCreator{}
42+
default:
43+
log.Fatalf("invalid client test case %s", *clientCase)
44+
}
45+
46+
verifySuit := verify.Suit{
47+
Model: model.RegisterModel(),
48+
Checker: porcupine.Checker{},
49+
Parser: model.RegisterParser(),
50+
}
51+
suit := util.Suit{
52+
Config: &cfg,
53+
ClientCreator: creator,
54+
Nemesises: *nemesises,
55+
VerifySuit: verifySuit,
56+
}
57+
suit.Run(context.Background(), []string{})
58+
}

cmd/util/suit.go

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package util
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"os"
8+
"os/signal"
9+
"strings"
10+
"syscall"
11+
12+
"github.com/pingcap/tipocket/pkg/control"
13+
"github.com/pingcap/tipocket/pkg/core"
14+
"github.com/pingcap/tipocket/pkg/nemesis"
15+
"github.com/pingcap/tipocket/pkg/verify"
16+
)
17+
18+
// Suit is a basic chaos testing suit with configurations to run chaos.
19+
type Suit struct {
20+
*control.Config
21+
core.ClientCreator
22+
// nemesis, seperated by comma.
23+
Nemesises string
24+
25+
VerifySuit verify.Suit
26+
}
27+
28+
// Run runs the suit.
29+
func (suit *Suit) Run(ctx context.Context, nodes []string) {
30+
var nemesisGens []core.NemesisGenerator
31+
for _, name := range strings.Split(suit.Nemesises, ",") {
32+
var g core.NemesisGenerator
33+
name := strings.TrimSpace(name)
34+
if len(name) == 0 {
35+
continue
36+
}
37+
38+
switch name {
39+
case "random_kill", "all_kill", "minor_kill", "major_kill":
40+
g = nemesis.NewKillGenerator(suit.Config.DB, name)
41+
case "random_drop", "all_drop", "minor_drop", "major_drop":
42+
g = nemesis.NewDropGenerator(name)
43+
default:
44+
log.Fatalf("invalid nemesis generator %s", name)
45+
}
46+
47+
nemesisGens = append(nemesisGens, g)
48+
}
49+
50+
sctx, cancel := context.WithCancel(ctx)
51+
52+
if len(nodes) != 0 {
53+
suit.Config.Nodes = nodes
54+
} else {
55+
// By default, we run TiKV/TiDB cluster on 5 nodes.
56+
for i := 1; i <= 5; i++ {
57+
name := fmt.Sprintf("n%d", i)
58+
suit.Config.Nodes = append(suit.Config.Nodes, name)
59+
}
60+
}
61+
62+
c := control.NewController(
63+
sctx,
64+
suit.Config,
65+
suit.ClientCreator,
66+
nemesisGens,
67+
suit.VerifySuit,
68+
)
69+
70+
sigs := make(chan os.Signal, 1)
71+
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
72+
73+
go func() {
74+
<-sigs
75+
c.Close()
76+
cancel()
77+
}()
78+
79+
c.Run()
80+
}

0 commit comments

Comments
 (0)