Skip to content

Commit ab13de5

Browse files
craig[bot]jayshrivastavaknzchengxiong-ruanjoshimhoff
committed
107475: changefeedccl: update nemeses test to use the declarative schema changer r=HonoreDB a=jayshrivastava ### sql: only use public indexes when fingerprinting Previously, running `SHOW EXPERIMENTAL_FINGERPRINTS` on a table in the middle of a schema change would sometimes cause an error due to missing indexes. The root cause of this error is that fingerprinting attempted to read non-public indexes which exist during the schema change: ``` 1 foo_pkey 2 crdb_internal_index_2_name_placeholder 3 crdb_internal_index_3_name_placeholder ``` The fix to this change is a one line change which ensures fingerprinting reads active indexes only. This change also adds a regression test for this scenario. There was a test util method in `changefeedccl` which was useful for this test. This change moves that util method to `schematestutils` so it can be called outside of `changefeedccl`. Epic: none Release note: None --- ### changefeedccl: update nemeses test to use the declarative schema changer This change updates the nemeses test, which asserts the behavior of changefeeds under a randomized DML/DDL workload. Previously, the test would only run with the legacy schema changer. This is not ideal because, by default, the declarative schema changer is used in production. This change makes it so that the declarative schema changer is used 90% of the time instead. Informs: cockroachdb#106906 Epic: none Release note: None 108019: rpc: fix various test bugs r=aliher1911,pavelkalinnikov a=knz Fixes cockroachdb#108008. TLDR: Prior to this patch, multiple unit tests in the `rpc` package were misconfiguring their heartbeat interval and timeout. This patch fixes this. The issue was that there were two separate locations for these tunable parameters: - `RPCHeartbeat{Interval,Timeout}` fields in `ContextOptions` (previously via `*base.Config`, recently as direct fields in `ContextOptions`) - also, two private fields `heartbeat{Interval,Timeout}` The former was copied into the latter during `NewContext()`. Only the latter (the private fields) matter for the actual behavior. Prior to this commit, the tests would call `NewContext()` and then afterwards would override the fields in `ContextOptions`. These overrides were thus ineffective because the value was already copied by that time. In addition to this design bug, there were a couple of additional bugs lurking: the overrides defined by the tests were problematic in some cases. If these overrides had been effective, the tests would break. The problem was discovered after 8d2d2bf merged, because in that commit some of the overrides from broken tests were taken on board and became effective. This started causing flakes. The fix is to remove the ambiguity in configuration and remove the problematic overrides from offending tests. Release note: None Epic: CRDB-28893 108067: sql: unskip TestCancelSchemaChange r=chengxiong-ruan a=chengxiong-ruan Informs cockroachdb#51796 This commit unskip TestCancelSchemaChange by fixing several wrong assumption of schema changer jobs. Also removed some variables which made no effects on the test. Release note: None Release justification: test only change. 108075: storage: fix overwrite RemoteStorage factory bug r=joshimhoff a=joshimhoff Tomorrow AM, I plan to add a unit test that runs an integration test server with in-memory shared storage. If that ends up being difficult, I may back out and test manually with a local cockroach binary. But we should add such a test eventually either way. **storage: fix overwrite RemoteStorage factory bug** As of this commit, if both cfg.SharedStorage and cfg.RemoteStorageFactory are set, CRDB uses cfg.SharedStorage. Note that eventually we will enable using both at the same time, but with the abstractions available today, that is not easy. We prefer cfg.SharedStorage, since the Locator -> Storage mapping contained in it is needed for CRDB to function properly. Release note: None. Epic: None. 108094: timeutil/ptp: fix conversion from seconds to Time r=knz,erikgrinaker a=pavelkalinnikov Epic: none Release note (bug fix): since 22.2.0, using a PTP clock device (enabled by the --clock-device flag) would generate timestamps in the far future. It now generates the correct time. This could cause nodes to crash due to incorrect timestamps, or in the worst case irreversibly advance the cluster's HLC clock into the far future. 108097: ccl/sqlproxyccl: avoid holding onto the lock in ListenForDenied r=JeffSwenson a=jaylim-crl #### ccl/sqlproxyccl: avoid holding onto the lock in ListenForDenied Previously, ListenForDenied would grab the watcher's lock (which is tied to the scope of the proxy) before calling checkConnection. As part of the updated ACL work, checkConnection now will grab a lock when it calls Initialize on a given tenant. Given that checkConnection can be blocking, grabbing onto the global watcher lock isn't ideal as it could hold up new connections, leading to timeout issues. This commit updates ListenForDenied such that the watcher's lock gets released before invoking checkConnection. #### ccl/sqlproxyccl: avoid tenant lookups if we know the type of connection Previously, we were performing a tenant lookup call before checking on the type of connection. This can be unnecessary (e.g. doing a lookup call for the private endpoints ACL, even if we knew that the connection was a public one). This commit addresses that. Release note: None Epic: none Co-authored-by: Jayant Shrivastava <[email protected]> Co-authored-by: Raphael 'kena' Poss <[email protected]> Co-authored-by: Chengxiong Ruan <[email protected]> Co-authored-by: Josh Imhoff <[email protected]> Co-authored-by: Pavel Kalinnikov <[email protected]> Co-authored-by: Jay <[email protected]>
7 parents 8fb2f86 + b65ea13 + 2135554 + bdca2a4 + f8e7dea + 2f8cd09 + 8d6e4c9 commit ab13de5

25 files changed

+303
-208
lines changed

pkg/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ ALL_TESTS = [
694694
"//pkg/util/timeofday:timeofday_test",
695695
"//pkg/util/timetz:timetz_test",
696696
"//pkg/util/timeutil/pgdate:pgdate_test",
697+
"//pkg/util/timeutil/ptp:ptp_test",
697698
"//pkg/util/timeutil:timeutil_test",
698699
"//pkg/util/tochar:tochar_test",
699700
"//pkg/util/tracing/collector:collector_test",
@@ -2416,6 +2417,7 @@ GO_TARGETS = [
24162417
"//pkg/util/timeutil/pgdate:pgdate",
24172418
"//pkg/util/timeutil/pgdate:pgdate_test",
24182419
"//pkg/util/timeutil/ptp:ptp",
2420+
"//pkg/util/timeutil/ptp:ptp_test",
24192421
"//pkg/util/timeutil:timeutil",
24202422
"//pkg/util/timeutil:timeutil_test",
24212423
"//pkg/util/tochar:tochar",

pkg/ccl/changefeedccl/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ go_test(
218218
"//pkg/ccl/changefeedccl/changefeedbase",
219219
"//pkg/ccl/changefeedccl/changefeedpb",
220220
"//pkg/ccl/changefeedccl/kvevent",
221+
"//pkg/ccl/changefeedccl/schemafeed/schematestutils",
221222
"//pkg/ccl/kvccl/kvtenantccl",
222223
"//pkg/ccl/multiregionccl",
223224
"//pkg/ccl/multiregionccl/multiregionccltestutils",
@@ -254,7 +255,6 @@ go_test(
254255
"//pkg/sql/catalog/bootstrap",
255256
"//pkg/sql/catalog/catpb",
256257
"//pkg/sql/catalog/colinfo",
257-
"//pkg/sql/catalog/descbuilder",
258258
"//pkg/sql/catalog/descpb",
259259
"//pkg/sql/catalog/desctestutils",
260260
"//pkg/sql/catalog/schemaexpr",
@@ -279,7 +279,6 @@ go_test(
279279
"//pkg/sql/sessiondata",
280280
"//pkg/sql/sessiondatapb",
281281
"//pkg/sql/types",
282-
"//pkg/storage",
283282
"//pkg/testutils",
284283
"//pkg/testutils/jobutils",
285284
"//pkg/testutils/serverutils",

pkg/ccl/changefeedccl/cdctest/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ go_library(
3131
"//pkg/util/fsm",
3232
"//pkg/util/hlc",
3333
"//pkg/util/log",
34-
"//pkg/util/randutil",
3534
"//pkg/util/syncutil",
3635
"//pkg/util/timeutil",
3736
"@com_github_cockroachdb_errors//:errors",

pkg/ccl/changefeedccl/cdctest/nemeses.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818

1919
"github.com/cockroachdb/cockroach/pkg/util/fsm"
2020
"github.com/cockroachdb/cockroach/pkg/util/log"
21-
"github.com/cockroachdb/cockroach/pkg/util/randutil"
2221
"github.com/cockroachdb/errors"
2322
)
2423

@@ -30,7 +29,9 @@ import (
3029
// duplicates, which the two cdctest.Validator implementations verify for the
3130
// real output of a changefeed. The output rows and resolved timestamps of the
3231
// tested feed are fed into them to check for anomalies.
33-
func RunNemesis(f TestFeedFactory, db *gosql.DB, isSinkless bool) (Validator, error) {
32+
func RunNemesis(
33+
f TestFeedFactory, db *gosql.DB, isSinkless bool, rng *rand.Rand,
34+
) (Validator, error) {
3435
// possible additional nemeses:
3536
// - schema changes
3637
// - merges
@@ -42,7 +43,6 @@ func RunNemesis(f TestFeedFactory, db *gosql.DB, isSinkless bool) (Validator, er
4243
// - sink chaos
4344

4445
ctx := context.Background()
45-
rng, _ := randutil.NewPseudoRand()
4646

4747
eventPauseCount := 10
4848
if isSinkless {

pkg/ccl/changefeedccl/changefeed_test.go

Lines changed: 8 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/cdctest"
3838
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/changefeedbase"
3939
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/kvevent"
40+
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/schemafeed/schematestutils"
4041
_ "github.com/cockroachdb/cockroach/pkg/ccl/kvccl/kvtenantccl" // multi-tenant tests
4142
_ "github.com/cockroachdb/cockroach/pkg/ccl/multiregionccl" // locality-related table mutations
4243
_ "github.com/cockroachdb/cockroach/pkg/ccl/partitionccl"
@@ -55,8 +56,6 @@ import (
5556
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
5657
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
5758
"github.com/cockroachdb/cockroach/pkg/sql"
58-
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
59-
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descbuilder"
6059
"github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils"
6160
"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
6261
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
@@ -68,7 +67,6 @@ import (
6867
"github.com/cockroachdb/cockroach/pkg/sql/randgen"
6968
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
7069
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
71-
"github.com/cockroachdb/cockroach/pkg/storage"
7270
"github.com/cockroachdb/cockroach/pkg/testutils"
7371
"github.com/cockroachdb/cockroach/pkg/testutils/jobutils"
7472
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
@@ -77,7 +75,6 @@ import (
7775
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
7876
"github.com/cockroachdb/cockroach/pkg/util"
7977
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
80-
"github.com/cockroachdb/cockroach/pkg/util/encoding"
8178
"github.com/cockroachdb/cockroach/pkg/util/hlc"
8279
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
8380
"github.com/cockroachdb/cockroach/pkg/util/log"
@@ -2151,7 +2148,7 @@ func TestChangefeedSchemaChangeAllowBackfill(t *testing.T) {
21512148
`add_column_def: [2]->{"after": {"a": 2}}`,
21522149
})
21532150
sqlDB.Exec(t, `ALTER TABLE add_column_def ADD COLUMN b STRING DEFAULT 'd'`)
2154-
ts := fetchDescVersionModificationTime(t, s, `add_column_def`, 7)
2151+
ts := schematestutils.FetchDescVersionModificationTime(t, s.TestServer.Server, `d`, `public`, `add_column_def`, 7)
21552152
assertPayloads(t, addColumnDef, []string{
21562153
fmt.Sprintf(`add_column_def: [1]->{"after": {"a": 1, "b": "d"}, "updated": "%s"}`,
21572154
ts.AsOfSystemTime()),
@@ -2171,7 +2168,7 @@ func TestChangefeedSchemaChangeAllowBackfill(t *testing.T) {
21712168
`add_col_comp: [2]->{"after": {"a": 2, "b": 7}}`,
21722169
})
21732170
sqlDB.Exec(t, `ALTER TABLE add_col_comp ADD COLUMN c INT AS (a + 10) STORED`)
2174-
ts := fetchDescVersionModificationTime(t, s, `add_col_comp`, 7)
2171+
ts := schematestutils.FetchDescVersionModificationTime(t, s.TestServer.Server, `d`, `public`, `add_col_comp`, 7)
21752172
assertPayloads(t, addColComp, []string{
21762173
fmt.Sprintf(`add_col_comp: [1]->{"after": {"a": 1, "b": 6, "c": 11}, "updated": "%s"}`,
21772174
ts.AsOfSystemTime()),
@@ -2192,7 +2189,7 @@ func TestChangefeedSchemaChangeAllowBackfill(t *testing.T) {
21922189
})
21932190
sqlDB.Exec(t, `ALTER TABLE drop_column DROP COLUMN b`)
21942191
sqlDB.Exec(t, `INSERT INTO drop_column VALUES (3)`)
2195-
ts := fetchDescVersionModificationTime(t, s, `drop_column`, 2)
2192+
ts := schematestutils.FetchDescVersionModificationTime(t, s.TestServer.Server, `d`, `public`, `drop_column`, 2)
21962193

21972194
// Backfill for DROP COLUMN b.
21982195
assertPayloads(t, dropColumn, []string{
@@ -2243,9 +2240,9 @@ func TestChangefeedSchemaChangeAllowBackfill(t *testing.T) {
22432240
// version 2. Then, when adding column c, it goes from 9->17, with the schema change being visible at
22442241
// the 7th step (version 15). Finally, when adding column d, it goes from 17->25 ith the schema change
22452242
// being visible at the 7th step (version 23).
2246-
dropTS := fetchDescVersionModificationTime(t, s, `multiple_alters`, 2)
2247-
addTS := fetchDescVersionModificationTime(t, s, `multiple_alters`, 15)
2248-
addTS2 := fetchDescVersionModificationTime(t, s, `multiple_alters`, 23)
2243+
dropTS := schematestutils.FetchDescVersionModificationTime(t, s.TestServer.Server, `d`, `public`, `multiple_alters`, 2)
2244+
addTS := schematestutils.FetchDescVersionModificationTime(t, s.TestServer.Server, `d`, `public`, `multiple_alters`, 15)
2245+
addTS2 := schematestutils.FetchDescVersionModificationTime(t, s.TestServer.Server, `d`, `public`, `multiple_alters`, 23)
22492246

22502247
assertPayloads(t, multipleAlters, []string{
22512248
fmt.Sprintf(`multiple_alters: [1]->{"after": {"a": 1}, "updated": "%s"}`, dropTS.AsOfSystemTime()),
@@ -2296,7 +2293,7 @@ func TestChangefeedSchemaChangeBackfillScope(t *testing.T) {
22962293
sqlDB.Exec(t, `ALTER TABLE add_column_def ADD COLUMN b STRING DEFAULT 'd'`)
22972294

22982295
// The primary index swap occurs at version 7.
2299-
ts := fetchDescVersionModificationTime(t, s, `add_column_def`, 7)
2296+
ts := schematestutils.FetchDescVersionModificationTime(t, s.TestServer.Server, `d`, `public`, `add_column_def`, 7)
23002297
assertPayloads(t, combinedFeed, []string{
23012298
fmt.Sprintf(`add_column_def: [1]->{"after": {"a": 1, "b": "d"}, "updated": "%s"}`,
23022299
ts.AsOfSystemTime()),
@@ -2319,82 +2316,6 @@ func TestChangefeedSchemaChangeBackfillScope(t *testing.T) {
23192316
}
23202317
}
23212318

2322-
// fetchDescVersionModificationTime fetches the `ModificationTime` of the specified
2323-
// `version` of `tableName`'s table descriptor.
2324-
func fetchDescVersionModificationTime(
2325-
t testing.TB, s TestServerWithSystem, tableName string, version int,
2326-
) hlc.Timestamp {
2327-
tblKey := s.Codec.TablePrefix(keys.DescriptorTableID)
2328-
header := kvpb.RequestHeader{
2329-
Key: tblKey,
2330-
EndKey: tblKey.PrefixEnd(),
2331-
}
2332-
dropColTblID := sqlutils.QueryTableID(t, s.DB, `d`, "public", tableName)
2333-
req := &kvpb.ExportRequest{
2334-
RequestHeader: header,
2335-
MVCCFilter: kvpb.MVCCFilter_All,
2336-
StartTime: hlc.Timestamp{},
2337-
}
2338-
hh := kvpb.Header{Timestamp: hlc.NewClockForTesting(nil).Now()}
2339-
res, pErr := kv.SendWrappedWith(context.Background(),
2340-
s.SystemServer.DB().NonTransactionalSender(), hh, req)
2341-
if pErr != nil {
2342-
t.Fatal(pErr.GoError())
2343-
}
2344-
for _, file := range res.(*kvpb.ExportResponse).Files {
2345-
it, err := storage.NewMemSSTIterator(file.SST, false /* verify */, storage.IterOptions{
2346-
KeyTypes: storage.IterKeyTypePointsAndRanges,
2347-
LowerBound: keys.MinKey,
2348-
UpperBound: keys.MaxKey,
2349-
})
2350-
if err != nil {
2351-
t.Fatal(err)
2352-
}
2353-
defer it.Close()
2354-
for it.SeekGE(storage.NilKey); ; it.Next() {
2355-
if ok, err := it.Valid(); err != nil {
2356-
t.Fatal(err)
2357-
} else if !ok {
2358-
continue
2359-
}
2360-
k := it.UnsafeKey()
2361-
if _, hasRange := it.HasPointAndRange(); hasRange {
2362-
t.Fatalf("unexpected MVCC range key at %s", k)
2363-
}
2364-
remaining, _, _, err := s.Codec.DecodeIndexPrefix(k.Key)
2365-
if err != nil {
2366-
t.Fatal(err)
2367-
}
2368-
_, tableID, err := encoding.DecodeUvarintAscending(remaining)
2369-
if err != nil {
2370-
t.Fatal(err)
2371-
}
2372-
if tableID != uint64(dropColTblID) {
2373-
continue
2374-
}
2375-
unsafeValue, err := it.UnsafeValue()
2376-
require.NoError(t, err)
2377-
if unsafeValue == nil {
2378-
t.Fatal(errors.New(`value was dropped or truncated`))
2379-
}
2380-
value := roachpb.Value{RawBytes: unsafeValue, Timestamp: k.Timestamp}
2381-
b, err := descbuilder.FromSerializedValue(&value)
2382-
if err != nil {
2383-
t.Fatal(err)
2384-
}
2385-
require.NotNil(t, b)
2386-
if b.DescriptorType() == catalog.Table {
2387-
tbl := b.BuildImmutable().(catalog.TableDescriptor)
2388-
if int(tbl.GetVersion()) == version {
2389-
return tbl.GetModificationTime()
2390-
}
2391-
}
2392-
}
2393-
}
2394-
t.Fatal(errors.New(`couldn't find table desc for given version`))
2395-
return hlc.Timestamp{}
2396-
}
2397-
23982319
// Regression test for #34314
23992320
func TestChangefeedAfterSchemaChangeBackfill(t *testing.T) {
24002321
defer leaktest.AfterTest(t)()

pkg/ccl/changefeedccl/helpers_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ func maybeDisableDeclarativeSchemaChangesForTest(
7373
return disable
7474
}
7575

76-
// disableDeclarativeSchemaChangesForTest tests that are disabled due to differences
77-
// in changefeed behaviour and are tracked by issue #80545.
78-
func disableDeclarativeSchemaChangesForTest(t testing.TB, sqlDB *sqlutils.SQLRunner) {
79-
sqlDB.Exec(t, "SET use_declarative_schema_changer='off'")
80-
sqlDB.Exec(t, "SET CLUSTER SETTING sql.defaults.use_declarative_schema_changer='off'")
81-
}
82-
8376
func waitForSchemaChange(
8477
t testing.TB, sqlDB *sqlutils.SQLRunner, stmt string, arguments ...interface{},
8578
) {

pkg/ccl/changefeedccl/nemeses_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
2020
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
2121
"github.com/cockroachdb/cockroach/pkg/util/log"
22+
"github.com/cockroachdb/cockroach/pkg/util/randutil"
2223
)
2324

2425
func TestChangefeedNemeses(t *testing.T) {
@@ -27,12 +28,15 @@ func TestChangefeedNemeses(t *testing.T) {
2728
skip.UnderRace(t, "takes >1 min under race")
2829

2930
testFn := func(t *testing.T, s TestServer, f cdctest.TestFeedFactory) {
31+
rng, seed := randutil.NewPseudoRand()
32+
t.Logf("random seed: %d", seed)
33+
3034
sqlDB := sqlutils.MakeSQLRunner(s.DB)
31-
disableDeclarativeSchemaChangesForTest(t, sqlDB)
35+
_ = maybeDisableDeclarativeSchemaChangesForTest(t, sqlDB, rng)
3236
// TODO(dan): Ugly hack to disable `eventPause` in sinkless feeds. See comment in
3337
// `RunNemesis` for details.
3438
isSinkless := strings.Contains(t.Name(), "sinkless")
35-
v, err := cdctest.RunNemesis(f, s.DB, isSinkless)
39+
v, err := cdctest.RunNemesis(f, s.DB, isSinkless, rng)
3640
if err != nil {
3741
t.Fatalf("%+v", err)
3842
}

pkg/ccl/changefeedccl/schemafeed/schematestutils/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ go_library(
66
importpath = "github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/schemafeed/schematestutils",
77
visibility = ["//visibility:public"],
88
deps = [
9+
"//pkg/keys",
10+
"//pkg/kv",
11+
"//pkg/kv/kvpb",
12+
"//pkg/roachpb",
913
"//pkg/sql/catalog",
1014
"//pkg/sql/catalog/catpb",
15+
"//pkg/sql/catalog/descbuilder",
1116
"//pkg/sql/catalog/descpb",
1217
"//pkg/sql/catalog/tabledesc",
1318
"//pkg/sql/types",
19+
"//pkg/storage",
20+
"//pkg/testutils/serverutils",
21+
"//pkg/testutils/sqlutils",
22+
"//pkg/util/encoding",
1423
"//pkg/util/hlc",
24+
"@com_github_cockroachdb_errors//:errors",
1525
"@com_github_gogo_protobuf//proto",
26+
"@com_github_stretchr_testify//require",
1627
],
1728
)

0 commit comments

Comments
 (0)