Skip to content

Commit 297a94a

Browse files
craig[bot]mgartnerkvoli
committed
145256: roachtest/tlp: randomly force generic query plans r=mgartner a=mgartner Generic query plans are now forced for 25% of TLP queries. Note that only one type of TLP query uses placeholders, which are required for "interesting" generic query plans, simple `SELECT .. WHERE ..` queries. Joins and grouping do not yet use placeholders. Fixes #128912 Release note: None 145429: roachtest: deflake lease-preferences roachtest r=wenyihu6 a=kvoli `server.span_stats.span_batch_limit` no longer needs to be set after `kv.enqueue_in_replicate_queue_on_span_config_update.enabled` defaults to true in versions on or after `v24.1`. Informs: #141359 Informs: #145055 --- The `lease-preferences/*` roachtests wait for lease preferences to be initially conformed before purposefully forcing leases out of conformance. Its possible to the initial lease preference conformance to take up to 10 minutes (a replica scanner cycle). Allow this much time. Note the non-initial conformance should be quicker, as leases are checked on acquisition, to see whether they violate the lease preferences. Resolves: #141359 Resolves: #145055 Release note: None Co-authored-by: Marcus Gartner <[email protected]> Co-authored-by: Austen McClernon <[email protected]>
3 parents a382a18 + d338105 + 979dc0f commit 297a94a

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

pkg/cmd/roachtest/tests/lease_preferences.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,16 @@ func runLeasePreferences(
172172
// waitForLessPreferred=false). This duration is used to ensure the lease
173173
// preference satisfaction is reasonably permanent.
174174
const stableDuration = 30 * time.Second
175+
// initialWaitDuration is how long the test will wait for initial lease
176+
// preference conformance. This duration is approx. a replica scanner cycle.
177+
const initialWaitDuration = 10 * time.Minute
175178

176179
numNodes := c.Spec().NodeCount
177180
allNodes := make([]int, 0, numNodes)
178181
for i := 1; i <= numNodes; i++ {
179182
allNodes = append(allNodes, i)
180183
}
181184

182-
// TODO(kvoli): temporary workaround for
183-
// https://github.com/cockroachdb/cockroach/issues/105274
184-
settings := install.MakeClusterSettings()
185-
settings.ClusterSettings["server.span_stats.span_batch_limit"] = "4096"
186-
settings.ClusterSettings["kv.enqueue_in_replicate_queue_on_span_config_update.enabled"] = "true"
187-
188185
startNodes := func(nodes ...int) {
189186
for _, node := range nodes {
190187
// Don't start a backup schedule because this test is timing sensitive.
@@ -198,7 +195,7 @@ func runLeasePreferences(
198195
// dc=N: n2N-1 n2N
199196
fmt.Sprintf("--locality=region=fake-region,zone=fake-zone,dc=%d", (node-1)/2+1),
200197
"--vmodule=replica_proposal=2,lease_queue=3,lease=3")
201-
c.Start(ctx, t.L(), opts, settings, c.Node(node))
198+
c.Start(ctx, t.L(), opts, install.MakeClusterSettings(), c.Node(node))
202199

203200
}
204201
}
@@ -215,9 +212,13 @@ func runLeasePreferences(
215212
conn := c.Conn(ctx, t.L(), numNodes)
216213
defer conn.Close()
217214

218-
checkLeasePreferenceConformance := func(ctx context.Context) {
215+
checkLeasePreferenceConformance := func(ctx context.Context, initial bool) {
216+
duration := spec.postEventWaitDuration
217+
if initial {
218+
duration = initialWaitDuration
219+
}
219220
result, err := waitForLeasePreferences(
220-
ctx, t, c, spec.checkNodes, spec.waitForLessPreferred, stableDuration, spec.postEventWaitDuration)
221+
ctx, t, c, spec.checkNodes, spec.waitForLessPreferred, stableDuration, duration)
221222
require.NoError(t, err, result)
222223
require.Truef(t, !result.violating(), "violating lease preferences %s", result)
223224
if spec.waitForLessPreferred {
@@ -260,7 +261,7 @@ func runLeasePreferences(
260261
leasePreference: spec.preferences,
261262
})
262263
t.L().Printf("waiting for initial lease preference conformance")
263-
checkLeasePreferenceConformance(ctx)
264+
checkLeasePreferenceConformance(ctx, true /* initial */)
264265

265266
// Run the spec event function. The event function will move leases to
266267
// non-conforming localities.
@@ -273,7 +274,7 @@ func runLeasePreferences(
273274
// Wait for the preference conformance with some leases in non-conforming
274275
// localities.
275276
t.L().Printf("waiting for post-event lease preference conformance")
276-
checkLeasePreferenceConformance(ctx)
277+
checkLeasePreferenceConformance(ctx, false /* initial */)
277278
}
278279

279280
type leasePreferencesResult struct {

pkg/cmd/roachtest/tests/tlp.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
gosql "database/sql"
1111
"fmt"
12+
"math/rand"
1213
"os"
1314
"path/filepath"
1415
"strings"
@@ -172,7 +173,7 @@ func runOneTLP(
172173
continue
173174
}
174175

175-
if err := runTLPQuery(t, conn, tlpSmither, logStmt); err != nil {
176+
if err := runTLPQuery(t, conn, rnd, tlpSmither, logStmt); err != nil {
176177
t.Fatal(err)
177178
}
178179
}
@@ -209,15 +210,29 @@ func runMutationStatement(
209210
// partitioned query. See GenerateTLP for more information on TLP and the
210211
// generated queries.
211212
func runTLPQuery(
212-
t task.Tasker, conn *gosql.DB, smither *sqlsmith.Smither, logStmt func(string),
213-
) error {
213+
t task.Tasker, conn *gosql.DB, rnd *rand.Rand, smither *sqlsmith.Smither, logStmt func(string),
214+
) (err error) {
214215
// Ignore panics from GenerateTLP.
215216
defer func() {
216217
if r := recover(); r != nil {
217218
return
218219
}
219220
}()
220221

222+
// Force generic query plans for 25% of queries.
223+
generic := false
224+
const forceGeneric = "SET plan_cache_mode = force_generic_plan"
225+
if rnd.Intn(4) == 0 {
226+
generic = true
227+
_, err = conn.Exec(forceGeneric)
228+
if err != nil {
229+
return err
230+
}
231+
defer func() {
232+
_, err = conn.Exec("RESET plan_cache_mode")
233+
}()
234+
}
235+
221236
unpartitioned, partitioned, args := smither.GenerateTLP()
222237
combined := sqlsmith.CombinedTLP(unpartitioned, partitioned)
223238

@@ -263,6 +278,9 @@ func runTLPQuery(
263278
}
264279

265280
diff := unsortedMatricesDiff(unpartitionedRows, partitionedRows)
281+
if generic {
282+
logStmt(forceGeneric)
283+
}
266284
logStmt(unpartitioned)
267285
logStmt(partitioned)
268286
return errors.Newf(

0 commit comments

Comments
 (0)