Skip to content

sql/schemachanger: enable add column by default in declarative schema changer#76983

Merged
craig[bot] merged 21 commits intocockroachdb:masterfrom
fqazi:enableAddColumn
May 17, 2022
Merged

sql/schemachanger: enable add column by default in declarative schema changer#76983
craig[bot] merged 21 commits intocockroachdb:masterfrom
fqazi:enableAddColumn

Conversation

@fqazi
Copy link
Copy Markdown
Collaborator

@fqazi fqazi commented Feb 24, 2022

These changes will enable add column by default in the declarative schema changer and the following fixes:

  1. Add support for retrying schema changes when retriable errors are encountered
  2. Add support for refreshing stats during declarative schema changes
  3. Block add column when cross-database references are observed in the declarative schema changer
  4. Block implicit record types inside expressions for the declarative schema changer
  5. Add schema change-related event log entries
  6. Properly combine multiple declarative schema change operations inside CTEs, which is required for support geometry related builtins that add columns
  7. Enforce schema usage related privileges in the declarative schema changer
  8. Add add column related telemetry
  9. Generate appropriate errors when a newly added column conflicts with a system column
  10. Support empty column family names
  11. Add columns in the user-specified order inside the declarative schema changer
  12. Enforce constraints when adding new columns, specifically detecting if default values will violate them

Along with the following known issues and limitations (tracked by issue: #80545)

  1. Legacy schema changer will be used whenever serial and generated columns are observed.
  2. Regional by row tables will default to the legacy schema changer since we are missing proper support for updating zone configs
  3. Columns with the unique constraint will default to the legacy schema changer
  4. Default expressions using sequences will default to the legacy schema changer
  5. A number of tests cases depending on the MVCC backfiller are using the legacy schema changer for now

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@fqazi fqazi force-pushed the enableAddColumn branch 3 times, most recently from a4d1a10 to d0d552d Compare February 25, 2022 18:16
@fqazi fqazi force-pushed the enableAddColumn branch 11 times, most recently from 2057b22 to 751cc3d Compare April 26, 2022 03:47
@fqazi fqazi changed the title Enable add column sql/schemachanger: enable add column by default in declarative schema changer Apr 26, 2022
@fqazi fqazi force-pushed the enableAddColumn branch 2 times, most recently from 076619a to 9a4ed6e Compare April 26, 2022 13:51
@fqazi fqazi marked this pull request as ready for review April 26, 2022 13:56
@fqazi fqazi requested review from a team as code owners April 26, 2022 13:56
@fqazi fqazi requested a review from a team April 26, 2022 13:56
@fqazi fqazi requested review from a team as code owners April 26, 2022 13:56
@fqazi fqazi requested review from samiskin and removed request for a team April 26, 2022 13:56
@fqazi fqazi force-pushed the enableAddColumn branch from 9a4ed6e to 3c06f3f Compare April 26, 2022 13:58
SET CLUSTER SETTING kv.closed_timestamp.target_duration = '1s';
SET CLUSTER SETTING changefeed.experimental_poll_interval = '10ms';
SET CLUSTER SETTING sql.defaults.vectorize=on;
SET CLUSTER SETTING sql.defaults.use_declarative_schema_changer='off';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment explaining which tests break with this on?

Copy link
Copy Markdown
Contributor

@HonoreDB HonoreDB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excited to see this! Two questions:

  • I see you're turning off the declarative schema changer in changefeed tests. What breaks when add column uses the declarative schema changer? Will it be possible to remove that from the tests before merging this? (cdc team could make a PR to this branch if you need).
  • You mention Support empty column family names as one of the fixes. cdc interacts with column family names--will we need to handle the possibility of a public column having an empty column family name? If so, is there a unique identifier we can use that can't conflict with other family names in the same table?

@fqazi fqazi force-pushed the enableAddColumn branch from 3c06f3f to 512b20c Compare April 26, 2022 14:45
@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented May 17, 2022

Ah, I need to handle offline descriptors here as well for hydration.

@fqazi fqazi force-pushed the enableAddColumn branch 2 times, most recently from c2a33ca to a63bdfc Compare May 17, 2022 16:34
fqazi added 2 commits May 17, 2022 12:45
Previously, when looking up descriptors in the cached
uncommitted descriptors we would not hydrate type information,
which could lead to certain operations like add columns
inside the declarative schema changer failing. This change,
adds logic to hydrate table descriptors inside the uncommitted
descriptor cache when used for lookups. Additionally, synthetic
descriptors are skipped when hydrating types, since during execution
these can be injected to mark descriptors as dropped for the statement
phase.

Release note: None
Previously, add column was not enabled by default with the declarative
schema changer, which does not support the new MVCC back filler fully
yet. This was inadequate, since we have a number of tests depending
on the new backfiller now, which only works with the legacy schema
changer. To address this, this patch will temporarily force the
legacy schema changer for these tests. Additionally, update
existing schame changer test related expected files.

Release note: None
@fqazi fqazi force-pushed the enableAddColumn branch from a63bdfc to ada7157 Compare May 17, 2022 16:53
@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented May 17, 2022

@ajwerner @chengxiong-ruan TFTR!

@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented May 17, 2022

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented May 17, 2022

Build succeeded:

@craig craig bot merged commit 9e64c79 into cockroachdb:master May 17, 2022
@postamar
Copy link
Copy Markdown

This is a huge step forward, great work!

ajwerner added a commit to ajwerner/cockroach that referenced this pull request May 23, 2022
Prior to this change, we never enforced nullability of values when performing
index backfills. Up until cockroachdb#76983, all column additions used the legacy schema
changer and its column backfill protocol. The column backfiller indeed checks
on nullability violations for columns [here](https://github.com/cockroachdb/cockroach/blob/d5313438aaa61a71a5a66c5718963bbb0fd7268b/pkg/sql/backfill/backfill.go#L355-L357).

Release note (bug fix): Prior to this change, virtual computed columns which
were marked as NOT NULL could be added to new secondary index. After this
change, attempts to add such columns to a secondary index will result in an
error. Note that such invalid columns can still be added to tables. Work to
resolve that bug is tracked in cockroachdb#81675.
ajwerner added a commit to ajwerner/cockroach that referenced this pull request May 25, 2022
Prior to this change, we never enforced nullability of values when performing
index backfills. Up until cockroachdb#76983, all column additions used the legacy schema
changer and its column backfill protocol. The column backfiller indeed checks
on nullability violations for columns [here](https://github.com/cockroachdb/cockroach/blob/d5313438aaa61a71a5a66c5718963bbb0fd7268b/pkg/sql/backfill/backfill.go#L355-L357).

Release note (bug fix): Prior to this change, virtual computed columns which
were marked as NOT NULL could be added to new secondary index. After this
change, attempts to add such columns to a secondary index will result in an
error. Note that such invalid columns can still be added to tables. Work to
resolve that bug is tracked in cockroachdb#81675.
craig bot pushed a commit that referenced this pull request May 25, 2022
81279: storage: specify and test iterator visibility semantics r=jbowens a=erikgrinaker

`@jbowens` I split this out from the range key PR in #77417, since we'll need to audit/update existing code for the new point key batch semantics, and it seems cleaner/easier to do this separately. As you know, the test currently fails because existing batch iterators see concurrent batch writes.

This only covers point keys, but range keys should have identical semantics, and the tests will be extended for range keys in #77417.

---

This patch specifies and tests iterator visibility semantics. See
comment on `Engine.NewMVCCIterator` for details.

Release note: None

81403: kvserver: address assorted comments from previous refactor of `TransferLeaseTarget()` r=aayushshah15 a=aayushshah15

This commit addresses miscelleneous review comments from #80834.

Release note: None

81679: sql: enforce nullability when evaluating expressions in index backfills r=ajwerner a=ajwerner

Prior to this change, we never enforced nullability of values when performing
index backfills. Up until #76983, all column additions used the legacy schema
changer and its column backfill protocol. The column backfiller indeed checks
on nullability violations for columns [here](https://github.com/cockroachdb/cockroach/blob/d5313438aaa61a71a5a66c5718963bbb0fd7268b/pkg/sql/backfill/backfill.go#L355-L357).

Release note (bug fix): Prior to this change, virtual computed columns which
were marked as NOT NULL could be added to new secondary index. After this
change, attempts to add such columns to a secondary index will result in an
error. Note that such invalid columns can still be added to tables. Work to
resolve that bug is tracked in #81675.

81777: util/metric: delete Rate r=andreimatei a=andreimatei

This exponentially moving Rate was unused. It also was exporting to
Prometheus as a gauge. It seems unlikely that we'll use this in the
future; I think we're happy enough with counters and computing rates in
the monitoring system. The Rate seems to have come from a time when we
liked moving measurements more; since then, we've adapted the Histogram,
for example, to include non-windowed state.

Release note: None

81798: sql: enable streamer for lookup joins r=yuzefovich a=yuzefovich

We've just fixed an issue with incorrectly using leaf txns for mutations
because of the streamer, so I think it is ok to fully enable the
streamer. I expect that there might be some fallout, so I'm curious to
see the run of nightlies.

Release note: None

81804: build: use bazel for roachtest stress r=rickystewart a=nicktrav

Currently, the Roachtest Stress TeamCity job uses `make` (via the
`mkrelease.sh` script) for building the required binaries. Recently, the
pipeline started hanging while building the binary. Rather than
investigating and fixing the existing `make`-based pipeline, convert the
job to using Bazel for building the binaries.

Retain the existing entrypoint to the job, converting it to use [the
existing pattern][1] of calling `run_bazel` with the required
environment variables, invoking an `_impl.sh` script. The existing logic
is moved into the new `_impl.sh` script, with some minor additions to
source some additional scripts.

Additionally, the TeamCity job itself was updated to set pass in the
`TARGET_CLOUD` environment variable (set to `gce`), and remove the need
to build within a container (instead deferring to Bazel to manage the
build environment). The diff for the TeamCity pipeline is as follows
(for posterity):

```diff
18c18
<
---
>       <param name="env.TARGET_CLOUD" value="gce" />
24c24
<           <param name="plugin.docker.imageId" value="%builder.dockerImage%" />
---
>
28,29c28,29
< export BUILD_TAG="$(git describe --abbrev=0 --tags --match=v[0-9]*)"
< ./build/teamcity-roachtest-stress.sh]]></param>
---
> build_tag="$(git describe --abbrev=0 --tags --match=v[0-9]*)"
> CLOUD=${TARGET_CLOUD} BUILD_TAG="${build_tag}" ./build/teamcity-roachtest-stress.sh]]></param>
```

Release note: None.

[1]: https://github.com/cockroachdb/cockroach/blob/12198a51408e7333cd4f96b221e6734239479765/build/teamcity/cockroach/nightlies/roachtest_nightly_gce.sh#L10-L11

81813: liveness: run sync disk write in a stopper task r=stevendanna,nicktrav a=erikgrinaker

**liveness: move stopper to `NodeLivenessOptions`**

Release note: None

**liveness: run sync disk write in a stopper task**

This patch runs the sync disk write during node heartbeats in a stopper
task. The write is done in a goroutine, so that we can respect the
caller's context cancellation (even though the write itself won't).
However, this could race with engine shutdown when stopping the node,
violating the Pebble contract and triggering the race detector.  Running
it as a stopper task will cause the node to wait for the disk write to
complete before closing the engine.

Of course, if the disk stalls then node shutdown will now never
complete. This is very unfortunate, since stopping the node is often
the only mitigation to recover stuck ranges with stalled disks. This is
mitigated by Pebble panic'ing the node on stalled disks, and Kubernetes
and other orchestration tools killing the process after some time.

Touches #81786.
Resolves #81511.
Resolves #81827.

Release note: None

81828: sql: deflake TestPrimaryKeyDropIndexNotCancelable r=chengxiong-ruan a=ajwerner

The problem was that we weren't atomically setting the boolean, at least, I
think. I repro'd another flake of it pretty quickly.

Release note: None

Co-authored-by: Erik Grinaker <grinaker@cockroachlabs.com>
Co-authored-by: Aayush Shah <aayush.shah15@gmail.com>
Co-authored-by: Andrew Werner <awerner32@gmail.com>
Co-authored-by: Andrei Matei <andrei@cockroachlabs.com>
Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
Co-authored-by: Nick Travers <travers@cockroachlabs.com>
Co-authored-by: Andrew Werner <ajwerner@cockroachlabs.com>
ajwerner added a commit to ajwerner/cockroach that referenced this pull request Jun 28, 2022
Prior to this change, we never enforced nullability of values when performing
index backfills. Up until cockroachdb#76983, all column additions used the legacy schema
changer and its column backfill protocol. The column backfiller indeed checks
on nullability violations for columns [here](https://github.com/cockroachdb/cockroach/blob/d5313438aaa61a71a5a66c5718963bbb0fd7268b/pkg/sql/backfill/backfill.go#L355-L357).

Release note (bug fix): Prior to this change, virtual computed columns which
were marked as NOT NULL could be added to new secondary index. After this
change, attempts to add such columns to a secondary index will result in an
error. Note that such invalid columns can still be added to tables. Work to
resolve that bug is tracked in cockroachdb#81675.
ajwerner added a commit to ajwerner/cockroach that referenced this pull request Jun 28, 2022
Prior to this change, we never enforced nullability of values when performing
index backfills. Up until cockroachdb#76983, all column additions used the legacy schema
changer and its column backfill protocol. The column backfiller indeed checks
on nullability violations for columns [here](https://github.com/cockroachdb/cockroach/blob/d5313438aaa61a71a5a66c5718963bbb0fd7268b/pkg/sql/backfill/backfill.go#L355-L357).

Release note (bug fix): Prior to this change, virtual computed columns which
were marked as NOT NULL could be added to new secondary index. After this
change, attempts to add such columns to a secondary index will result in an
error. Note that such invalid columns can still be added to tables. Work to
resolve that bug is tracked in cockroachdb#81675.
ajwerner added a commit to ajwerner/cockroach that referenced this pull request Jul 7, 2022
Prior to this change, we never enforced nullability of values when performing
index backfills. Up until cockroachdb#76983, all column additions used the legacy schema
changer and its column backfill protocol. The column backfiller indeed checks
on nullability violations for columns [here](https://github.com/cockroachdb/cockroach/blob/d5313438aaa61a71a5a66c5718963bbb0fd7268b/pkg/sql/backfill/backfill.go#L355-L357).

Release note (bug fix): Prior to this change, virtual computed columns which
were marked as NOT NULL could be added to new secondary index. After this
change, attempts to add such columns to a secondary index will result in an
error. Note that such invalid columns can still be added to tables. Work to
resolve that bug is tracked in cockroachdb#81675.
ajwerner added a commit to ajwerner/cockroach that referenced this pull request Jul 7, 2022
Prior to this change, we never enforced nullability of values when performing
index backfills. Up until cockroachdb#76983, all column additions used the legacy schema
changer and its column backfill protocol. The column backfiller indeed checks
on nullability violations for columns [here](https://github.com/cockroachdb/cockroach/blob/d5313438aaa61a71a5a66c5718963bbb0fd7268b/pkg/sql/backfill/backfill.go#L355-L357).

Release note (bug fix): Prior to this change, virtual computed columns which
were marked as NOT NULL could be added to new secondary index. After this
change, attempts to add such columns to a secondary index will result in an
error. Note that such invalid columns can still be added to tables. Work to
resolve that bug is tracked in cockroachdb#81675.
ajwerner added a commit to ajwerner/cockroach that referenced this pull request Jul 7, 2022
Prior to this change, we never enforced nullability of values when performing
index backfills. Up until cockroachdb#76983, all column additions used the legacy schema
changer and its column backfill protocol. The column backfiller indeed checks
on nullability violations for columns [here](https://github.com/cockroachdb/cockroach/blob/d5313438aaa61a71a5a66c5718963bbb0fd7268b/pkg/sql/backfill/backfill.go#L355-L357).

Release note (bug fix): Prior to this change, virtual computed columns which
were marked as NOT NULL could be added to new secondary index. After this
change, attempts to add such columns to a secondary index will result in an
error. Note that such invalid columns can still be added to tables. Work to
resolve that bug is tracked in cockroachdb#81675.
ajwerner added a commit to ajwerner/cockroach that referenced this pull request Jul 7, 2022
Prior to this change, we never enforced nullability of values when performing
index backfills. Up until cockroachdb#76983, all column additions used the legacy schema
changer and its column backfill protocol. The column backfiller indeed checks
on nullability violations for columns [here](https://github.com/cockroachdb/cockroach/blob/d5313438aaa61a71a5a66c5718963bbb0fd7268b/pkg/sql/backfill/backfill.go#L355-L357).

Release note (bug fix): Prior to this change, virtual computed columns which
were marked as NOT NULL could be added to new secondary index. After this
change, attempts to add such columns to a secondary index will result in an
error. Note that such invalid columns can still be added to tables. Work to
resolve that bug is tracked in cockroachdb#81675.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants