Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
134886: roachtest: split perturbation/* tests r=kvoli a=andrewbaptist

This commit splits all the individual perturbations into separate files. This will make it easier to find and update a perturbation.

Epic: none

Release note: None

135051: docgen: update SQL diagrams for triggers r=DrewKimball a=taroface

Made updates to the CREATE TRIGGER and DROP TRIGGER SQL diagrams. These will be used with the docs added in cockroachdb/docs#19129

The generated diagrams:
![image](https://github.com/user-attachments/assets/8d0122a9-a604-4b5f-91d9-2922322fda56)

![image](https://github.com/user-attachments/assets/9224382e-76a9-42f6-b2a8-4ad4058cadcf)

Epic: none
Release note: none
Release justification: non-production code change

Co-authored-by: Andrew Baptist <[email protected]>
Co-authored-by: Ryan Kuo <[email protected]>
  • Loading branch information
3 people committed Nov 13, 2024
3 parents 2c18247 + 0cbc4e7 + 11bf877 commit eb6c671
Show file tree
Hide file tree
Showing 22 changed files with 720 additions and 512 deletions.
4 changes: 2 additions & 2 deletions docs/generated/sql/bnf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ FILES = [
"create_table_as_stmt",
"create_table_with_storage_param",
"create_table_stmt",
"create_trigger_stmt",
"create_trigger",
"create_type",
"create_view_stmt",
"deallocate_stmt",
Expand All @@ -135,7 +135,7 @@ FILES = [
"drop_sequence_stmt",
"drop_stmt",
"drop_table",
"drop_trigger_stmt",
"drop_trigger",
"drop_type",
"drop_view",
"execute_stmt",
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/create_trigger.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create_trigger_stmt ::=
'CREATE' 'TRIGGER' trigger_create_name ( 'BEFORE' | 'AFTER' ) ( ( ( 'INSERT' | 'DELETE' | 'UPDATE' | 'UPDATE' ) ) ( ( 'OR' ( 'INSERT' | 'DELETE' | 'UPDATE' | 'UPDATE' ) ) )* ) 'ON' table_name ( 'FOR' ( 'EACH' | ) ( 'ROW' ) | ) ( 'WHEN' a_expr | ) 'EXECUTE' ( 'FUNCTION' ) func_name '(' trigger_func_args ')'
2 changes: 0 additions & 2 deletions docs/generated/sql/bnf/create_trigger_stmt.bnf

This file was deleted.

3 changes: 3 additions & 0 deletions docs/generated/sql/bnf/drop_trigger.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
drop_trigger_stmt ::=
'DROP' 'TRIGGER' trigger_name 'ON' table_name ( 'RESTRICT' | )
| 'DROP' 'TRIGGER' 'IF' 'EXISTS' trigger_name 'ON' table_name ( 'RESTRICT' | )
3 changes: 0 additions & 3 deletions docs/generated/sql/bnf/drop_trigger_stmt.bnf

This file was deleted.

1 change: 1 addition & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,7 @@ GO_TARGETS = [
"//pkg/cmd/roachtest/spec:spec",
"//pkg/cmd/roachtest/spec:spec_test",
"//pkg/cmd/roachtest/test:test",
"//pkg/cmd/roachtest/tests/perturbation:perturbation",
"//pkg/cmd/roachtest/tests:tests",
"//pkg/cmd/roachtest/tests:tests_test",
"//pkg/cmd/roachtest/testselector:testselector",
Expand Down
27 changes: 27 additions & 0 deletions pkg/cmd/docgen/diagrams.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,22 @@ var specs = []stmtSpec{
replace: map[string]string{" name": "column_name"},
unlink: []string{"column_name"},
},
{
name: "create_trigger",
stmt: "create_trigger_stmt",
inline: []string{"opt_or_replace", "trigger_action_time", "trigger_event_list", "opt_trigger_transition_list", "trigger_for_each", "trigger_when", "function_or_procedure", "trigger_event", "trigger_transition_list", "trigger_for_opt_each", "trigger_for_type", "name_list", "trigger_transition", "transition_is_new", "transition_is_row", "opt_as", "table_alias_name"},
unlink: []string{"trigger_create_name"},
replace: map[string]string{
"'TRIGGER' name": "'TRIGGER' trigger_create_name",
"| 'INSTEAD' 'OF'": "",
"( 'REFERENCING' ( ( ( ( 'NEW' | 'OLD' ) ( 'ROW' | 'TABLE' ) ( 'AS' | ) ( name ) ) ) ( ( ( ( 'NEW' | 'OLD' ) ( 'ROW' | 'TABLE' ) ( 'AS' | ) ( name ) ) ) )* ) | )": "",
"| 'STATEMENT'": "",
"( 'OR' 'REPLACE' | )": "",
"'OF' ( ( name ) ( ( ',' name ) )* )": "",
"| 'TRUNCATE'": "",
"| 'PROCEDURE'": ""},
nosplit: true,
},
{
name: "create_type",
stmt: "create_type_stmt",
Expand Down Expand Up @@ -995,6 +1011,17 @@ var specs = []stmtSpec{
inline: []string{"opt_drop_behavior"},
match: []*regexp.Regexp{regexp.MustCompile("'DROP' 'TABLE'")},
},
{
name: "drop_trigger",
stmt: "drop_trigger_stmt",
inline: []string{"opt_drop_behavior"},
unlink: []string{"trigger_name"},
replace: map[string]string{
" name": " trigger_name",
"'CASCADE' | ": "",
},
nosplit: true,
},
{
name: "drop_type",
stmt: "drop_type_stmt",
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/roachtest/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ go_library(
"admission_control_index_backfill.go",
"admission_control_index_overload.go",
"admission_control_intent_resolution.go",
"admission_control_latency.go",
"admission_control_multi_store_overload.go",
"admission_control_multitenant_fairness.go",
"admission_control_row_level_ttl.go",
Expand Down Expand Up @@ -230,6 +229,7 @@ go_library(
"//pkg/cmd/roachtest/roachtestutil/task",
"//pkg/cmd/roachtest/spec",
"//pkg/cmd/roachtest/test",
"//pkg/cmd/roachtest/tests/perturbation",
"//pkg/gossip",
"//pkg/internal/sqlsmith",
"//pkg/internal/workloadreplay",
Expand Down Expand Up @@ -286,7 +286,6 @@ go_library(
"//pkg/util/uuid",
"//pkg/util/version",
"//pkg/workload",
"//pkg/workload/cli",
"//pkg/workload/debug",
"//pkg/workload/histogram",
"//pkg/workload/histogram/exporter",
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/roachtest/tests/admission_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ func registerAdmission(r registry.Registry) {
registerElasticIO(r)
registerDiskBandwidthOverload(r)
registerElasticWorkloadMixedVersion(r)
registerLatencyTests(r)
}
35 changes: 35 additions & 0 deletions pkg/cmd/roachtest/tests/perturbation/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "perturbation",
srcs = [
"add_node.go",
"decommission.go",
"elastic_workload.go",
"framework.go",
"index_backfill.go",
"kv_workload.go",
"network_partition.go",
"restart_node.go",
"slow_disk.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests/perturbation",
visibility = ["//visibility:public"],
deps = [
"//pkg/cmd/roachtest/cluster",
"//pkg/cmd/roachtest/option",
"//pkg/cmd/roachtest/registry",
"//pkg/cmd/roachtest/roachtestutil",
"//pkg/cmd/roachtest/spec",
"//pkg/cmd/roachtest/test",
"//pkg/roachprod/install",
"//pkg/roachprod/logger",
"//pkg/util/randutil",
"//pkg/util/retry",
"//pkg/util/timeutil",
"//pkg/workload/cli",
"//pkg/workload/histogram",
"@com_github_cockroachdb_errors//:errors",
"@com_github_stretchr_testify//require",
],
)
57 changes: 57 additions & 0 deletions pkg/cmd/roachtest/tests/perturbation/add_node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2024 The Cockroach Authors.
//
// Use of this software is governed by the CockroachDB Software License
// included in the /LICENSE file.

package perturbation

import (
"context"
"math/rand"
"time"

"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
)

// addNode will add a node during the start phase and wait for it to complete.
// It doesn't do anything during the stop phase.
type addNode struct{}

var _ perturbation = addNode{}

func (a addNode) setup() variations {
return setup(a, 5.0)
}

func (a addNode) setupMetamorphic(rng *rand.Rand) variations {
v := a.setup()
v = v.randomize(rng)
//TODO(#133606): With high vcpu and large writes, the test can fail due to
//the disk becoming saturated leading to 1-2s of fsync stall.
if v.vcpu >= 16 && v.maxBlockBytes == 4096 {
v.maxBlockBytes = 1024
}
return v
}

func (addNode) startTargetNode(ctx context.Context, t test.Test, v variations) {
}

func (a addNode) startPerturbation(ctx context.Context, t test.Test, v variations) time.Duration {
startTime := timeutil.Now()
v.startNoBackup(ctx, t, v.targetNodes())
// Wait out the time until the store is no longer suspect. The 31s is based
// on the 30s default server.time_after_store_suspect setting plus 1 sec for
// the store to propagate its gossip information.
waitDuration(ctx, 31*time.Second)
v.waitForRebalanceToStop(ctx, t)
return timeutil.Since(startTime)
}

// endPerturbation already waited for completion as part of start, so it doesn't
// need to wait again here.
func (addNode) endPerturbation(ctx context.Context, t test.Test, v variations) time.Duration {
waitDuration(ctx, v.validationDuration)
return v.validationDuration
}
93 changes: 93 additions & 0 deletions pkg/cmd/roachtest/tests/perturbation/decommission.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2024 The Cockroach Authors.
//
// Use of this software is governed by the CockroachDB Software License
// included in the /LICENSE file.

package perturbation

import (
"context"
"fmt"
"math/rand"
"time"

"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
"github.com/cockroachdb/cockroach/pkg/roachprod/install"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
)

// decommission will decommission the target node during the start phase. It
// allows optionally calling drain first. Draining first is the best practice
// recommendation, however it should not cause a latency impact either way.
type decommission struct {
drain bool
}

var _ perturbation = decommission{}

func (d decommission) setup() variations {
d.drain = true
return setup(d, 5.0)
}

func (d decommission) setupMetamorphic(rng *rand.Rand) variations {
v := d.setup()
d.drain = rng.Intn(2) == 0
v = v.randomize(rng)
v.perturbation = d
//TODO(#133606): With high vcpu and large writes, the test can fail due to
//the disk becoming saturated leading to 1-2s of fsync stall.
if v.vcpu >= 16 && v.maxBlockBytes == 4096 {
v.maxBlockBytes = 1024
}
return v
}

func (d decommission) startTargetNode(ctx context.Context, t test.Test, v variations) {
v.startNoBackup(ctx, t, v.targetNodes())
}

func (d decommission) startPerturbation(
ctx context.Context, t test.Test, v variations,
) time.Duration {
startTime := timeutil.Now()
// TODO(baptist): If we want to support multiple decommissions in parallel,
// run drain and decommission in separate goroutine.
if d.drain {
t.L().Printf("draining target nodes")
for _, node := range v.targetNodes() {
drainCmd := fmt.Sprintf(
"./cockroach node drain --self --certs-dir=%s --port={pgport:%d}",
install.CockroachNodeCertsDir,
node,
)
v.Run(ctx, option.WithNodes(v.Node(node)), drainCmd)
}
// Wait for all the other nodes to see the drain over gossip.
time.Sleep(10 * time.Second)
}

t.L().Printf("decommissioning nodes")
for _, node := range v.targetNodes() {
decommissionCmd := fmt.Sprintf(
"./cockroach node decommission --self --certs-dir=%s --port={pgport:%d}",
install.CockroachNodeCertsDir,
node,
)
v.Run(ctx, option.WithNodes(v.Node(node)), decommissionCmd)
}

t.L().Printf("stopping decommissioned nodes")
v.Stop(ctx, t.L(), option.DefaultStopOpts(), v.targetNodes())
return timeutil.Since(startTime)
}

// endPerturbation already waited for completion as part of start, so it doesn't
// need to wait again here.
func (d decommission) endPerturbation(
ctx context.Context, t test.Test, v variations,
) time.Duration {
waitDuration(ctx, v.validationDuration)
return v.validationDuration
}
71 changes: 71 additions & 0 deletions pkg/cmd/roachtest/tests/perturbation/elastic_workload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2024 The Cockroach Authors.
//
// Use of this software is governed by the CockroachDB Software License
// included in the /LICENSE file.

package perturbation

import (
"context"
"fmt"
"math/rand"
"time"

"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
)

// elasticWorkload will start a workload with elastic priority. It uses the same
// characteristics as the normal workload. However since the normal workload
// runs at 50% CPU this adds another 2x the stable rate so it will be slowed
// down by AC.
// TODO(baptist): Run against the same database to hit transaction conflicts and
// priority inversions.
type elasticWorkload struct{}

var _ perturbation = elasticWorkload{}

func (e elasticWorkload) setup() variations {
return setup(e, 5.0)
}

func (e elasticWorkload) setupMetamorphic(rng *rand.Rand) variations {
v := e.setup()
// NB: Running an elastic workload can sometimes increase the latency of
// almost all regular requests. To prevent this, we set the min latency to
// 100ms instead of the default.
v.profileOptions = append(v.profileOptions, roachtestutil.ProfMinimumLatency(100*time.Millisecond))
return v.randomize(rng)
}

func (e elasticWorkload) startTargetNode(ctx context.Context, t test.Test, v variations) {
v.startNoBackup(ctx, t, v.targetNodes())
initCmd := fmt.Sprintf("./cockroach workload init kv --db elastic --splits %d {pgurl:1}", v.splits)
v.Run(ctx, option.WithNodes(v.Node(1)), initCmd)
}

func (e elasticWorkload) startPerturbation(
ctx context.Context, t test.Test, v variations,
) time.Duration {
startTime := timeutil.Now()
runCmd := fmt.Sprintf(
"./cockroach workload run kv --db elastic --txn-qos=background --duration=%s --max-block-bytes=%d --min-block-bytes=%d --concurrency=500 {pgurl%s}",
v.perturbationDuration, v.maxBlockBytes, v.maxBlockBytes, v.stableNodes())
v.Run(ctx, option.WithNodes(v.workloadNodes()), runCmd)

// Wait a few seconds to allow the latency to resume after stopping the
// workload. This makes it easier to separate the perturbation from the
// validation phases.
waitDuration(ctx, 5*time.Second)
return timeutil.Since(startTime)
}

// endPerturbation implements perturbation.
func (e elasticWorkload) endPerturbation(
ctx context.Context, t test.Test, v variations,
) time.Duration {
waitDuration(ctx, v.validationDuration)
return v.validationDuration
}
Loading

0 comments on commit eb6c671

Please sign in to comment.