Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: use leased database descriptors, implement db schema changes in job #52975

Merged
merged 1 commit into from
Aug 20, 2020

Conversation

thoszhang
Copy link
Contributor

@thoszhang thoszhang commented Aug 18, 2020

This commit introduces the use of leased database descriptors, and
implements database schema changes in the schema change job.

The main changes:

  • The descriptor collection now provides access to database descriptors,
    and name resolution uses leased database descriptors where
    appropriate.
  • The resolver API now allows resolving mutable database descriptors,
    which we now fetch and use consistently in schema changes.
  • The former incoherent database cache (database.Cache) has been
    replaced, and database caching no longer relies on gossip. However:
  • The deprecated database cache and uncommittedDatabases set are
    still in use in the 20.1 mixed-version state, and the use of leased
    descriptors is version-gated. The cache itself is no longer exposed to
    users of the descriptor collection, and when reading descriptors, the
    choice of caching mechanism should be mostly transparent to the
    caller.
  • The schema change job now handles database schema changes (rename,
    drop, grant/revoke), which involves draining names, waiting for old
    leases to drain, etc.

Closes #41942.
Closes #52567.

Release note (sql change, bug fix): Renaming and dropping databases now
satisfy the same transactional guarantees as online schema changes on
tables: Changes will become visible if and only if the transaction
commits, and a successful result indicates changes having propagated to
the entire cluster. This fixes some long-standing problems with
inconsistent database state being visible after renames and drops. (As a
side effect of coherent caching for databases, database names can no
longer be recycled in multiple schema changes in the same transaction.)

@cockroach-teamcity
Copy link
Member

This change is Reviewable

pkg/sql/catalog/descpb/structured.proto Show resolved Hide resolved
pkg/sql/database.go Show resolved Hide resolved
pkg/sql/database.go Outdated Show resolved Hide resolved
pkg/sql/descriptor.go Outdated Show resolved Hide resolved
pkg/sql/logictest/testdata/logic_test/jobs Show resolved Hide resolved
pkg/sql/resolver.go Outdated Show resolved Hide resolved
pkg/sql/schema_changer.go Outdated Show resolved Hide resolved
pkg/sql/schema_changer.go Outdated Show resolved Hide resolved
pkg/sql/schema_changer.go Outdated Show resolved Hide resolved
pkg/sql/sem/tree/name_resolution.go Show resolved Hide resolved
@thoszhang thoszhang force-pushed the db-descs branch 2 times, most recently from 7470508 to 71f782c Compare August 19, 2020 16:04
@thoszhang thoszhang marked this pull request as ready for review August 19, 2020 17:20
@thoszhang thoszhang requested a review from a team August 19, 2020 17:20
@thoszhang thoszhang requested a review from a team as a code owner August 19, 2020 17:20
@thoszhang thoszhang requested review from miretskiy and ajwerner and removed request for a team and miretskiy August 19, 2020 17:20
@thoszhang
Copy link
Contributor Author

Still need to add the mixed-version logic tests but this is ready for a look.

@thoszhang thoszhang force-pushed the db-descs branch 5 times, most recently from 06e6f61 to e622663 Compare August 19, 2020 20:44
pkg/sql/schema_changer.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

:lgtm:

What's up with the tenant tests?

Reviewed 5 of 10 files at r1, 2 of 55 files at r3, 65 of 65 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @lucy-zhang and @rohany)


pkg/sql/catalog/descs/collection.go, line 418 at r4 (raw file):

// func (tc *Collection) GetDatabaseVersion() {
//
// }

?

Copy link
Contributor Author

@thoszhang thoszhang left a comment

Choose a reason for hiding this comment

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

What's up with the tenant tests?

I'm unskipping the 3node-tenant configuration for these tests, which will close #52567. I need to write a commit message.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner, @lucy-zhang, and @rohany)


pkg/sql/catalog/descs/collection.go, line 418 at r4 (raw file):

Previously, ajwerner wrote…
// func (tc *Collection) GetDatabaseVersion() {
//
// }

?

Oops.

@thoszhang thoszhang force-pushed the db-descs branch 3 times, most recently from e9da118 to 9415d79 Compare August 19, 2020 23:48
@thoszhang thoszhang force-pushed the db-descs branch 3 times, most recently from bfe5202 to c47a3ea Compare August 20, 2020 00:48
This commit introduces the use of leased database descriptors, and
implements database schema changes in the schema change job.

The main changes:

* The descriptor collection now provides access to database descriptors,
  and name resolution uses leased database descriptors where
  appropriate.
* The resolver API now allows resolving mutable database descriptors,
  which we now fetch and use consistently in schema changes.
* The former incoherent database cache (`database.Cache`) has been
  replaced, and database caching no longer relies on gossip. However:
* The deprecated database cache and `uncommittedDatabases` set are
  still in use in the 20.1 mixed-version state, and the use of leased
  descriptors is version-gated. The cache itself is no longer exposed to
  users of the descriptor collection, and when reading descriptors, the
  choice of caching mechanism should be mostly transparent to the
  caller.
* The schema change job now handles database schema changes (rename,
  drop, grant/revoke), which involves draining names, waiting for old
  leases to drain, etc.

Release note (sql change, bug fix): Renaming and dropping databases now
satisfy the same transactional guarantees as online schema changes on
tables: Changes will become visible if and only if the transaction
commits, and a successful result indicates changes having propagated to
the entire cluster. This fixes some long-standing problems with
inconsistent database state being visible after renames and drops. (As a
side effect of coherent caching for databases, database names can no
longer be recycled in multiple schema changes in the same transaction.)
@thoszhang
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Aug 20, 2020

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants