From 5f7fa698dec2101a651552cefc39f3144c8f4545 Mon Sep 17 00:00:00 2001 From: Jeffrey Xiao Date: Tue, 21 May 2019 10:25:21 -0400 Subject: [PATCH] roachtest: revert not disabling merge queue Roachtests need to remain compatible with 19.1 and having the merge queue enabled when performing a split will throw an error. Release note: None --- pkg/cmd/roachtest/election.go | 2 ++ pkg/workload/indexes/indexes.go | 15 +++++++++++++++ pkg/workload/workload.go | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/pkg/cmd/roachtest/election.go b/pkg/cmd/roachtest/election.go index d5a246b721cb..a6880c553440 100644 --- a/pkg/cmd/roachtest/election.go +++ b/pkg/cmd/roachtest/election.go @@ -42,6 +42,8 @@ func registerElectionAfterRestart(r *registry) { c.Run(ctx, c.Node(1), `./cockroach sql --insecure -e " CREATE DATABASE IF NOT EXISTS test; CREATE TABLE test.kv (k INT PRIMARY KEY, v INT); + -- Prevent the merge queue from immediately discarding our splits. + SET CLUSTER SETTING kv.range_merge.queue_enabled = false; ALTER TABLE test.kv SPLIT AT SELECT generate_series(0, 10000, 100)"`) start := timeutil.Now() diff --git a/pkg/workload/indexes/indexes.go b/pkg/workload/indexes/indexes.go index 679963ddbcdd..9a51c3f5ecd1 100644 --- a/pkg/workload/indexes/indexes.go +++ b/pkg/workload/indexes/indexes.go @@ -96,6 +96,10 @@ func (w *indexes) Hooks() workload.Hooks { return nil }, PostLoad: func(sqlDB *gosql.DB) error { + // Prevent the merge queue from immediately discarding our splits. + if err := maybeDisableMergeQueue(sqlDB); err != nil { + return err + } // Split at the beginning of each index so that as long as the // table has a single index, all writes will be multi-range. for i := 0; i < w.idxs; i++ { @@ -109,6 +113,17 @@ func (w *indexes) Hooks() workload.Hooks { } } +func maybeDisableMergeQueue(sqlDB *gosql.DB) error { + var ok bool + if err := sqlDB.QueryRow( + `SELECT count(*) > 0 FROM [ SHOW ALL CLUSTER SETTINGS ] AS _ (v) WHERE v = 'kv.range_merge.queue_enabled'`, + ).Scan(&ok); err != nil || !ok { + return err + } + _, err := sqlDB.Exec("SET CLUSTER SETTING kv.range_merge.queue_enabled = false") + return err +} + // Tables implements the Generator interface. func (w *indexes) Tables() []workload.Table { // Construct the schema with all indexes. diff --git a/pkg/workload/workload.go b/pkg/workload/workload.go index 60c6a37df5f0..a194aa472c74 100644 --- a/pkg/workload/workload.go +++ b/pkg/workload/workload.go @@ -541,8 +541,24 @@ func Setup( return size, nil } +func maybeDisableMergeQueue(db *gosql.DB) error { + var ok bool + if err := db.QueryRow( + `SELECT count(*) > 0 FROM [ SHOW ALL CLUSTER SETTINGS ] AS _ (v) WHERE v = 'kv.range_merge.queue_enabled'`, + ).Scan(&ok); err != nil || !ok { + return err + } + _, err := db.Exec("SET CLUSTER SETTING kv.range_merge.queue_enabled = false") + return err +} + // Split creates the range splits defined by the given table. func Split(ctx context.Context, db *gosql.DB, table Table, concurrency int) error { + // Prevent the merge queue from immediately discarding our splits. + if err := maybeDisableMergeQueue(db); err != nil { + return err + } + if table.Splits.NumBatches <= 0 { return nil }