Skip to content

Commit

Permalink
roachtest: metamorphically enable leader leases
Browse files Browse the repository at this point in the history
Part of cockroachdb#132762.

To increase test coverage of leader leases, this patch adds leader leases
to the set of possible lease types when tests opt-in to metamorphic leases.
As of fc68b0f, most roachtests do enable metamorphic leases, so this will
provide good coverage of leader leases.

Release note: None
  • Loading branch information
nvanbenschoten committed Nov 12, 2024
1 parent 9ce80e6 commit 9513109
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
6 changes: 5 additions & 1 deletion pkg/cmd/roachtest/registry/test_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,14 @@ const (
LeaderLeases
// MetamorphicLeases randomly chooses epoch or expiration
// leases (across the entire cluster).
// TODO(nvanbenschoten): add leader leases to this mix.
MetamorphicLeases
)

// LeaseTypes contains all lease types.
//
// The list does not contain aliases like "default" and "metamorphic".
var LeaseTypes = []LeaseType{EpochLeases, ExpirationLeases, LeaderLeases}

// CloudSet represents a set of clouds.
//
// Instances of CloudSet are immutable. The uninitialized (zero) value is not
Expand Down
20 changes: 14 additions & 6 deletions pkg/cmd/roachtest/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,18 @@ func (r *testRunner) runWorker(
c.clusterSettings = map[string]string{}
c.virtualClusterSettings = map[string]string{}

switch testSpec.Leases {
leases := testSpec.Leases
if leases == registry.MetamorphicLeases {
// 50% change of using the default lease type, 50% change of choosing
// a random, specific lease type.
if prng.Intn(2) == 0 {
leases = registry.DefaultLeases
} else {
leases = registry.LeaseTypes[prng.Intn(len(registry.LeaseTypes))]
}
c.status(fmt.Sprintf("metamorphically using %s leases", leases))
}
switch leases {
case registry.DefaultLeases:
case registry.EpochLeases:
c.clusterSettings["kv.expiration_leases_only.enabled"] = "false"
Expand All @@ -911,12 +922,9 @@ func (r *testRunner) runWorker(
c.clusterSettings["kv.expiration_leases_only.enabled"] = "false"
c.clusterSettings["kv.raft.leader_fortification.fraction_enabled"] = "1.0"
case registry.MetamorphicLeases:
enabled := prng.Float64() < 0.5
c.status(fmt.Sprintf("metamorphically setting kv.expiration_leases_only.enabled = %t",
enabled))
c.clusterSettings["kv.expiration_leases_only.enabled"] = fmt.Sprintf("%t", enabled)
t.Fatalf("metamorphic leases handled above")
default:
t.Fatalf("unknown lease type %s", testSpec.Leases)
t.Fatalf("unknown lease type %s", leases)
}

c.goCoverDir = t.GoCoverArtifactsDir()
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/roachtest/tests/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ var rangeLeaseRenewalDuration = func() time.Duration {
// requests are successful with nominal latencies. See also:
// https://github.com/cockroachdb/cockroach/issues/103654
func registerFailover(r registry.Registry) {
leaseTypes := []registry.LeaseType{registry.EpochLeases, registry.ExpirationLeases, registry.LeaderLeases}
for _, leases := range leaseTypes {
for _, leases := range registry.LeaseTypes {
var leasesStr string
switch leases {
case registry.EpochLeases:
Expand Down

0 comments on commit 9513109

Please sign in to comment.