-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schemachanger/rel: fix race due to failure to clone constraint slots
The fundamental race here is that while the slots themselves were being copied by value, the "any" clauses which are a slice were not. The second bug here is that the "inline" values were not being properly reset. That bug could lead to problems when the query was run again in the context of a different element set. We need to reset those inline values too. Fixes #88628 Release note: None
- Loading branch information
Showing
7 changed files
with
233 additions
and
10 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
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,77 @@ | ||
// 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 tests | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/jobs" | ||
"github.com/cockroachdb/cockroach/pkg/sql" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/errors" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
// TestSchemaChangesInParallel exists to try to shake out races in the | ||
// declarative schema changer infrastructure. At its time of writing, it | ||
// effectively reproduced a race in the rules engine's object pooling. | ||
func TestSchemaChangesInParallel(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
ctx := context.Background() | ||
s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{ | ||
Knobs: base.TestingKnobs{ | ||
GCJob: &sql.GCJobTestingKnobs{ | ||
SkipWaitingForMVCCGC: true, | ||
}, | ||
JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(), | ||
}, | ||
}) | ||
defer s.Stopper().Stop(ctx) | ||
|
||
const N = 4 | ||
run := func(i int) func() (retErr error) { | ||
return func() (retErr error) { | ||
conn, err := sqlDB.Conn(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
retErr = errors.CombineErrors(retErr, conn.Close()) | ||
}() | ||
for _, stmt := range []string{ | ||
fmt.Sprintf("CREATE DATABASE db%d", i), | ||
fmt.Sprintf("USE db%d", i), | ||
"CREATE TABLE t (i INT PRIMARY KEY, k INT)", | ||
"ALTER TABLE t ADD COLUMN j INT DEFAULT 42", | ||
"ALTER TABLE t DROP COLUMN k", | ||
"CREATE SEQUENCE s", | ||
"ALTER TABLE t ADD COLUMN l INT DEFAULT nextval('s')", | ||
fmt.Sprintf("DROP DATABASE db%d", i), | ||
} { | ||
if _, err := conn.ExecContext(ctx, stmt); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
} | ||
var g errgroup.Group | ||
for i := 0; i < N; i++ { | ||
g.Go(run(i)) | ||
} | ||
require.NoError(t, g.Wait()) | ||
} |