github.com/pingcap/chaos@v0.0.0-20190710112158-c86faf4b3719/cmd/tidb/main.go (about)

     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/chaos/cmd/util"
    12  	"github.com/pingcap/chaos/db/tidb"
    13  	"github.com/pingcap/chaos/pkg/check/porcupine"
    14  	"github.com/pingcap/chaos/pkg/control"
    15  	"github.com/pingcap/chaos/pkg/core"
    16  	"github.com/pingcap/chaos/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  }