forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
87383: roachtest: move CheckReplicaDivergenceOnDB to util r=renatolabs a=tbg This had no business sitting on `Cluster`. Release note: None Release justification: testing code Co-authored-by: Tobias Grieger <[email protected]>
- Loading branch information
Showing
8 changed files
with
85 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "roachtestutil", | ||
srcs = ["consistency_check.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/roachprod/logger", | ||
"@com_github_cockroachdb_errors//:errors", | ||
], | ||
) | ||
|
||
get_x_data(name = "get_x_data") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
// | ||
|
||
package roachtestutil | ||
|
||
import ( | ||
"context" | ||
gosql "database/sql" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/roachprod/logger" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// CheckReplicaDivergenceOnDB runs a stats-only consistency check via the | ||
// provided DB. It ignores transient errors that can result from the | ||
// implementation of crdb_internal.check_consistency, so a nil result | ||
// does not prove anything. | ||
func CheckReplicaDivergenceOnDB(ctx context.Context, l *logger.Logger, db *gosql.DB) error { | ||
// NB: we set a statement_timeout since context cancellation won't work here, | ||
// see: | ||
// https://github.com/cockroachdb/cockroach/pull/34520 | ||
// | ||
// We've seen the consistency checks hang indefinitely in some cases. | ||
rows, err := db.QueryContext(ctx, ` | ||
SET statement_timeout = '5m'; | ||
SELECT t.range_id, t.start_key_pretty, t.status, t.detail | ||
FROM | ||
crdb_internal.check_consistency(true, '', '') as t | ||
WHERE t.status NOT IN ('RANGE_CONSISTENT', 'RANGE_INDETERMINATE')`) | ||
if err != nil { | ||
// TODO(tbg): the checks can fail for silly reasons like missing gossiped | ||
// descriptors, etc. -- not worth failing the test for. Ideally this would | ||
// be rock solid. | ||
l.Printf("consistency check failed with %v; ignoring", err) | ||
return nil | ||
} | ||
defer rows.Close() | ||
var finalErr error | ||
for rows.Next() { | ||
var rangeID int32 | ||
var prettyKey, status, detail string | ||
if scanErr := rows.Scan(&rangeID, &prettyKey, &status, &detail); scanErr != nil { | ||
l.Printf("consistency check failed with %v; ignoring", scanErr) | ||
return nil | ||
} | ||
finalErr = errors.CombineErrors(finalErr, | ||
errors.Newf("r%d (%s) is inconsistent: %s %s\n", rangeID, prettyKey, status, detail)) | ||
} | ||
if err := rows.Err(); err != nil { | ||
l.Printf("consistency check failed with %v; ignoring", err) | ||
return nil | ||
} | ||
return finalErr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters