Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bank2: toggle feature randomly #393

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 42 additions & 11 deletions testcase/bank2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)

Expand Down
46 changes: 24 additions & 22 deletions testcase/bank2/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Copy link
Contributor

@mahjonp mahjonp Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a little vague to me since there are only two toggle features here(tidb_enable_async_commit and enable-compaction-filter). Rest LGTM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that random-toggle-feature maybe not a good name, but I have no idea about the name.

)

func main() {
Expand All @@ -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),
Expand Down