diff --git a/testcase/bank2/client.go b/testcase/bank2/client.go index aefac696..982e8266 100644 --- a/testcase/bank2/client.go +++ b/testcase/bank2/client.go @@ -75,17 +75,18 @@ var ( // Config ... type Config struct { // NumAccounts is total accounts - NumAccounts int `toml:"num_accounts"` - Interval time.Duration `toml:"interval"` - Concurrency int `toml:"concurrency"` - RetryLimit int `toml:"retry_limit"` - EnableLongTxn bool `toml:"enable_long_txn"` - Contention string `toml:"contention"` - Pessimistic bool `toml:"pessimistic"` - MinLength int `toml:"min_length"` - MaxLength int `toml:"max_length"` - ReplicaRead string - DbName string + NumAccounts int `toml:"num_accounts"` + Interval time.Duration `toml:"interval"` + Concurrency int `toml:"concurrency"` + RetryLimit int `toml:"retry_limit"` + EnableLongTxn bool `toml:"enable_long_txn"` + Contention string `toml:"contention"` + Pessimistic bool `toml:"pessimistic"` + MinLength int `toml:"min_length"` + MaxLength int `toml:"max_length"` + ReplicaRead string + DbName string + RandomToggleFeature bool } // ClientCreator ... @@ -224,6 +225,9 @@ func (c *bank2Client) SetUp(ctx context.Context, _ []cluster.Node, clientNodes [ } c.startVerify(ctx, db) + if c.Config.RandomToggleFeature { + c.randomToggleFeature(ctx, db) + } return nil } @@ -261,6 +265,33 @@ func (c *bank2Client) Start(ctx context.Context, cfg interface{}, clientNodes [] return nil } +func (c *bank2Client) randomToggleFeature(ctx context.Context, db *sql.DB) { + go func() { + log.Info("random toggle feature is running...") + ticker := time.NewTicker(10 * time.Second) + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + tpls := []string{ + "set @@global.tidb_enable_async_commit=%d;", + "set config tikv gc.`enable-compaction-filter`=%d;", + } + for _, tpl := range tpls { + flag := rand.Intn(2) + sql := fmt.Sprintf(tpl, flag) + log.Infof("[bank2Client] toggle feature with sql: %s", sql) + _, err := db.Exec(sql) + if err != nil { + log.Warnf("[bank2Client] toggle feature failed: %v", err) + } + } + } + } + }() +} + func (c *bank2Client) startVerify(ctx context.Context, db *sql.DB) { c.verify(db) diff --git a/testcase/bank2/cmd/main.go b/testcase/bank2/cmd/main.go index 937bca7b..11e726b8 100644 --- a/testcase/bank2/cmd/main.go +++ b/testcase/bank2/cmd/main.go @@ -33,17 +33,18 @@ import ( ) var ( - accounts = flag.Int("accounts", 1000000, "the number of accounts") - interval = flag.Duration("interval", 2*time.Second, "the interval") - concurrency = flag.Int("concurrency", 200, "concurrency worker count") - retryLimit = flag.Int("retry-limit", 200, "retry count") - longTxn = flag.Bool("long-txn", true, "enable long-term transactions") - contention = flag.String("contention", "low", "contention level, support values: high / low, default value: low") - pessimistic = flag.Bool("pessimistic", false, "use pessimistic transaction") - minLength = flag.Int("min-value-length", 0, "minimum value inserted into rocksdb") - maxLength = flag.Int("max-value-length", 128, "maximum value inserted into rocksdb") - replicaRead = flag.String("tidb-replica-read", "leader", "tidb_replica_read mode, support values: leader / follower / leader-and-follower, default value: leader.") - dbname = flag.String("dbname", "test", "name of database to test") + accounts = flag.Int("accounts", 1000000, "the number of accounts") + interval = flag.Duration("interval", 2*time.Second, "the interval") + concurrency = flag.Int("concurrency", 200, "concurrency worker count") + retryLimit = flag.Int("retry-limit", 200, "retry count") + longTxn = flag.Bool("long-txn", true, "enable long-term transactions") + contention = flag.String("contention", "low", "contention level, support values: high / low, default value: low") + pessimistic = flag.Bool("pessimistic", false, "use pessimistic transaction") + minLength = flag.Int("min-value-length", 0, "minimum value inserted into rocksdb") + maxLength = flag.Int("max-value-length", 128, "maximum value inserted into rocksdb") + replicaRead = flag.String("tidb-replica-read", "leader", "tidb_replica_read mode, support values: leader / follower / leader-and-follower, default value: leader.") + dbname = flag.String("dbname", "test", "name of database to test") + randomToggleFeature = flag.Bool("random-toggle-feature", false, "") ) func main() { @@ -61,17 +62,18 @@ func main() { Provider: cluster.NewDefaultClusterProvider(), ClientCreator: client.ClientCreator{ Cfg: &client.Config{ - NumAccounts: *accounts, - Interval: *interval, - Concurrency: *concurrency, - RetryLimit: *retryLimit, - MinLength: *minLength, - MaxLength: *maxLength, - EnableLongTxn: *longTxn, - Contention: *contention, - Pessimistic: *pessimistic, - ReplicaRead: *replicaRead, - DbName: *dbname, + NumAccounts: *accounts, + Interval: *interval, + Concurrency: *concurrency, + RetryLimit: *retryLimit, + MinLength: *minLength, + MaxLength: *maxLength, + EnableLongTxn: *longTxn, + Contention: *contention, + Pessimistic: *pessimistic, + ReplicaRead: *replicaRead, + DbName: *dbname, + RandomToggleFeature: *randomToggleFeature, }, }, NemesisGens: util.ParseNemesisGenerators(fixture.Context.Nemesis),