Skip to content

Commit

Permalink
Merge #94233
Browse files Browse the repository at this point in the history
94233: roachtest: update `failover` tests to use `SHOW RANGES` r=erikgrinaker a=erikgrinaker

This patch updates the `failover` roachtests to use the new `SHOW RANGES` syntax, because of the recent `crdb_internal.ranges` changes.

Resolves #94218.
Resolves #94217.
Resolves #94216.
Resolves #94215.
Resolves #94214.
Resolves #94213.
Resolves #94212.
Resolves #94210.
Touches #93644.

Epic: none
Release note: None

Co-authored-by: Erik Grinaker <[email protected]>
  • Loading branch information
craig[bot] and erikgrinaker committed Dec 23, 2022
2 parents 4232883 + 9b847ca commit e649575
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/cmd/roachtest/tests/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,16 @@ func relocateRanges(
where := fmt.Sprintf("(%s) AND %d = ANY(replicas)", predicate, source)
for {
require.NoError(t, conn.QueryRowContext(ctx,
`SELECT count(*) FROM crdb_internal.ranges WHERE `+where).Scan(&count))
`SELECT count(distinct range_id) FROM [SHOW CLUSTER RANGES WITH TABLES] WHERE `+where).
Scan(&count))
if count == 0 {
break
}
t.Status(fmt.Sprintf("moving %d ranges off of n%d (%s)", count, source, predicate))
for _, target := range to {
_, err := conn.ExecContext(ctx, `ALTER RANGE RELOCATE FROM $1::int TO $2::int FOR `+
`SELECT range_id FROM crdb_internal.ranges WHERE `+where, source, target)
`SELECT DISTINCT range_id FROM [SHOW CLUSTER RANGES WITH TABLES] WHERE `+where,
source, target)
require.NoError(t, err)
}
time.Sleep(time.Second)
Expand All @@ -729,13 +731,15 @@ func relocateLeases(t test.Test, ctx context.Context, conn *gosql.DB, predicate
where := fmt.Sprintf("%s AND lease_holder != %d", predicate, to)
for {
require.NoError(t, conn.QueryRowContext(ctx,
`SELECT count(*) FROM crdb_internal.ranges WHERE `+where).Scan(&count))
`SELECT count(distinct range_id) FROM [SHOW CLUSTER RANGES WITH TABLES, DETAILS] WHERE `+
where).
Scan(&count))
if count == 0 {
break
}
t.Status(fmt.Sprintf("moving %d leases to n%d (%s)", count, to, predicate))
_, err := conn.ExecContext(ctx, `ALTER RANGE RELOCATE LEASE TO $1::int FOR `+
`SELECT range_id FROM crdb_internal.ranges WHERE `+where, to)
`SELECT DISTINCT range_id FROM [SHOW CLUSTER RANGES WITH TABLES, DETAILS] WHERE `+where, to)
// When a node recovers, it may not have gossiped its store key yet.
if err != nil && !strings.Contains(err.Error(), "KeyNotPresentError") {
require.NoError(t, err)
Expand Down

0 comments on commit e649575

Please sign in to comment.