cockroachdb / cockroachdb/cockroach
schemachanger: add locking for names
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Presently a declarative schema change job is bound to the set of descriptors undergoing a schema change and this serves in effect as a lock which prevents concurrent schema changes which may conflict. This locking doesn't cover catalog "resources" which aren't tied to the descriptor, such as names. Consider for example:
```
BEGIN;
ALTER TABLE foo RENAME TO bar;
CREATE UNIQUE INDEX idx ON baz (x);
COMMIT;
```
The rename will correctly be scheduled to the schema change's PostCommitNonRevertible phase which occurs after the backfill succeeds, but there's nothing preventing a concurrent schema change from renaming yet another table to `bar` while the backfill is ongoing and then this non-cancelable schema change will fail and infinitely retry.
@ajwerner proposes that we lock the parent schema when renaming a table, and so forth for other descriptor types. Effectively, their parent owns the names. We already do this for functions, effectively. This is attractive but falls short for databases, which currently have no parent. Perhaps they should have a root descriptor of some kind?
Jira issue: CRDB-23989
Epic CRDB-60938
Contributor guide
Assessment
This issue has not been assessed yet.