-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: only validate new regions when adding/dropping
When we added validation logic to make sure every region corresponded to a known node locality, we were a little too aggressive. The validation made it possible to end up in a state where any ALTER..REGION operation could hang. This could happen in a few situations; for example: - node is restarted with a different locality flag. - MR cluster is restored into a non-MR cluster. - c2c streaming is used with a MR source and non-MR destination. In all these cases, the problem was that the zone configuration could reference a region that no longer has any nodes with the corresponding locality. The validation was too aggressive, since it would validate those regions which already existed in the zone configuration. Now, only the newly added region is validated. Release note (bug fix): Fixed a bug that could cause ALTER DATABASE ... ADD/DROP REGION to hang if node localities were changed after regions were added.
- Loading branch information
Showing
7 changed files
with
190 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2023 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 tests | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option" | ||
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test" | ||
"github.com/cockroachdb/cockroach/pkg/roachprod/install" | ||
) | ||
|
||
// This test tests that we can add and drop regions even if the locality flags | ||
// of a node no longer match the regions that already were added to the | ||
// database. | ||
func runMismatchedLocalityTest(ctx context.Context, t test.Test, c cluster.Cluster) { | ||
// Start 3 nodes with a different localities. | ||
c.Put(ctx, t.Cockroach(), "./cockroach", c.All()) | ||
startOpts := option.DefaultStartOpts() | ||
startOpts.RoachprodOpts.ExtraArgs = []string{"--locality=region=east"} | ||
c.Start(ctx, t.L(), startOpts, install.MakeClusterSettings(), c.Nodes(1)) | ||
startOpts.RoachprodOpts.ExtraArgs = []string{"--locality=region=central"} | ||
c.Start(ctx, t.L(), startOpts, install.MakeClusterSettings(), c.Nodes(2)) | ||
startOpts.RoachprodOpts.ExtraArgs = []string{"--locality=region=west"} | ||
c.Start(ctx, t.L(), startOpts, install.MakeClusterSettings(), c.Nodes(3)) | ||
|
||
// Add the 3 regions to the database. | ||
db := c.Conn(ctx, t.L(), 1) | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb PRIMARY REGION "east";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb ADD REGION "central";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb ADD REGION "west";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Restart all the nodes with new localities. | ||
c.Stop(ctx, t.L(), option.DefaultStopOpts(), c.Nodes(1)) | ||
startOpts.RoachprodOpts.ExtraArgs = []string{"--locality=region=mars"} | ||
c.Start(ctx, t.L(), startOpts, install.MakeClusterSettings(), c.Nodes(1)) | ||
c.Stop(ctx, t.L(), option.DefaultStopOpts(), c.Nodes(2)) | ||
startOpts.RoachprodOpts.ExtraArgs = []string{"--locality=region=jupiter"} | ||
c.Start(ctx, t.L(), startOpts, install.MakeClusterSettings(), c.Nodes(2)) | ||
c.Stop(ctx, t.L(), option.DefaultStopOpts(), c.Nodes(3)) | ||
startOpts.RoachprodOpts.ExtraArgs = []string{"--locality=region=venus"} | ||
c.Start(ctx, t.L(), startOpts, install.MakeClusterSettings(), c.Nodes(3)) | ||
|
||
// Verify that we can add and drop regions for the database. There's no longer | ||
// any node with the old localities, but that's fine. | ||
db = c.Conn(ctx, t.L(), 3) | ||
if err := WaitFor3XReplication(ctx, t, db); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb ADD REGION "venus";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb DROP REGION "central";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb ADD REGION "jupiter";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb ADD REGION "mars";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb SET PRIMARY REGION "mars";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb DROP REGION "west";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := db.Exec(`ALTER DATABASE defaultdb DROP REGION "east";`); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
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