Skip to content

Commit

Permalink
Add sequential test (#29)
Browse files Browse the repository at this point in the history
* tidb: add sequential test

* pkg: allow none model checker

* tidb: reneme request to seqRequest and response to seqResponse
  • Loading branch information
overvenus authored and benpigchu committed May 23, 2019
1 parent f434f96 commit 7dc2454
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 56 deletions.
19 changes: 17 additions & 2 deletions cmd/tidb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"flag"
"log"
"net/http"
_ "net/http/pprof"
"time"

"github.com/pingcap/chaos/cmd/util"
Expand All @@ -22,11 +24,16 @@ var (
historyFile = flag.String("history", "./history.log", "history file")
nemesises = flag.String("nemesis", "", "nemesis, seperated by name, like random_kill,all_kill")
checkerNames = flag.String("checker", "porcupine", "checker name, eg, porcupine, tidb_bank_tso")
pprofAddr = flag.String("pprof", "0.0.0.0:8080", "Pprof address")
)

func main() {
flag.Parse()

go func() {
http.ListenAndServe(*pprofAddr, nil)
}()

cfg := control.Config{
DB: "tidb",
RequestCount: *requestCount,
Expand All @@ -41,24 +48,32 @@ func main() {
creator = tidb.BankClientCreator{}
case "multi_bank":
creator = tidb.MultiBankClientCreator{}
case "sequential":
creator = tidb.SequentialClientCreator{}
default:
log.Fatalf("invalid client test case %s", *clientCase)
}

parser := tidb.BankParser()
model := tidb.BankModel()
var checker core.Checker
switch *checkerNames {
case "porcupine":
checker = porcupine.Checker{}
case "tidb_bank_tso":
checker = tidb.BankTsoChecker()
case "sequential_checker":
checker = tidb.NewSequentialChecker()
parser = tidb.NewSequentialParser()
model = nil
default:
log.Fatalf("invalid checker %s", *checkerNames)
}

verifySuit := verify.Suit{
Model: tidb.BankModel(),
Model: model,
Checker: checker,
Parser: tidb.BankParser(),
Parser: parser,
}
suit := util.Suit{
Config: &cfg,
Expand Down
2 changes: 2 additions & 0 deletions cmd/verifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func main() {
case "tidb_bank_tso":
// Actually we can omit BankModel, since BankTsoChecker does not require a Model.
s.Model, s.Parser, s.Checker = tidb.BankModel(), tidb.BankParser(), tidb.BankTsoChecker()
case "sequential":
s.Parser, s.Checker = tidb.NewSequentialParser(), tidb.NewSequentialChecker()
case "register":
s.Model, s.Parser, s.Checker = model.RegisterModel(), model.RegisterParser(), porcupine.Checker{}
case "":
Expand Down
45 changes: 33 additions & 12 deletions db/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path"
"strconv"
"strings"
"sync"
"time"

"github.com/pingcap/chaos/pkg/util"
Expand All @@ -27,6 +28,7 @@ var (

pdConfig = path.Join(deployDir, "./conf/pd.toml")
tikvConfig = path.Join(deployDir, "./conf/tikv.toml")
tidbConfig = path.Join(deployDir, "./conf/tidb.toml")

pdLog = path.Join(deployDir, "./log/pd.log")
tikvLog = path.Join(deployDir, "./log/tikv.log")
Expand All @@ -36,6 +38,7 @@ var (
// Cluster is the TiKV/TiDB database cluster.
// Note: Cluster does not implement `core.DB` interface.
type Cluster struct {
once sync.Once
nodes []string
installBlocker util.BlockRunner
IncludeTidb bool
Expand All @@ -50,15 +53,18 @@ func (cluster *Cluster) SetUp(ctx context.Context, nodes []string, node string)
ssh.Exec(ctx, node, "killall", "-9", "tikv-server")
ssh.Exec(ctx, node, "killall", "-9", "pd-server")

cluster.nodes = nodes

cluster.installBlocker.Init(len(nodes))
cluster.once.Do(func() {
cluster.nodes = nodes
cluster.installBlocker.Init(len(nodes))
})

log.Printf("install archieve on node %s", node)

var err error
cluster.installBlocker.Run(func() {
err = util.InstallArchive(ctx, node, archiveURL, deployDir)
if !util.IsFileExist(ctx, node, deployDir) {
err = util.InstallArchive(ctx, node, archiveURL, deployDir)
}
})
if err != nil {
return err
Expand All @@ -72,27 +78,45 @@ func (cluster *Cluster) SetUp(ctx context.Context, nodes []string, node string)
"election-interval=\"500ms\"",
"tso-save-interval=\"500ms\"",
"[replication]",
"max-replicas=5",
"max-replicas=3",
}

if err := util.WriteFile(ctx, node, pdConfig, strconv.Quote(strings.Join(pdCfs, "\n"))); err != nil {
return err
}

tikvCfs := []string{
"[server]",
"status-addr=\"0.0.0.0:20180\"",
"[raftstore]",
"pd-heartbeat-tick-interval=\"500ms\"",
"pd-store-heartbeat-tick-interval=\"1s\"",
"raft_store_max_leader_lease=\"900ms\"",
"capacity =\"100G\"",
"pd-heartbeat-tick-interval=\"3s\"",
"raft_store_max_leader_lease=\"50ms\"",
"raft_base_tick_interval=\"100ms\"",
"raft_heartbeat_ticks=3",
"raft_election_timeout_ticks=10",
"sync-log = true",
"[coprocessor]",
"region-max-keys = 5",
"region-split-keys = 2",
}

if err := util.WriteFile(ctx, node, tikvConfig, strconv.Quote(strings.Join(tikvCfs, "\n"))); err != nil {
return err
}

tidbCfs := []string{
"lease = \"1s\"",
"split-table = true",
"[tikv-client]",
"commit-timeout = \"10ms\"",
"max-txn-time-use = 590",
}

if err := util.WriteFile(ctx, node, tidbConfig, strconv.Quote(strings.Join(tidbCfs, "\n"))); err != nil {
return err
}

return cluster.start(ctx, node, true)
}

Expand Down Expand Up @@ -178,10 +202,6 @@ WAIT:
return err
}

if inSetUp {
time.Sleep(30 * time.Second)
}

if !util.IsDaemonRunning(ctx, node, tikvBinary, tikvPID) {
return fmt.Errorf("fail to start tikv on node %s", node)
}
Expand All @@ -191,6 +211,7 @@ WAIT:
"--store=tikv",
fmt.Sprintf("--path=%s", strings.Join(pdEndpoints, ",")),
fmt.Sprintf("--log-file=%s", tidbLog),
fmt.Sprintf("--config=%s", tidbConfig),
}

log.Printf("start tidb-server on node %s", node)
Expand Down
Loading

0 comments on commit 7dc2454

Please sign in to comment.