Skip to content

Commit

Permalink
sql/schemachanger: enforce online schema change invariants with dep r…
Browse files Browse the repository at this point in the history
…ules

Previously we had implicit rules in opgen which were used to enforce
sequencing between transitions. This was brittle and made it hard to
collapse certain edges. Now that we can represent a not-join, we can
add the rules we want selectively, only when descriptors are not being
dropped.

Fixes cockroachdb#86691
Fixes cockroachdb#86626

Release justification: fixes a bug

Release note: None
  • Loading branch information
ajwerner authored and Marius Posta committed Sep 1, 2022
1 parent 878f39d commit e70db5e
Show file tree
Hide file tree
Showing 222 changed files with 8,957 additions and 3,857 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ added synthetic descriptor: name:"_crdb_internal_region" id:107 version:2 modifi
added synthetic descriptor: name:"table_regional_by_table" id:108 version:2 modification_time:<> parent_id:104 unexposed_parent_schema_id:106 columns:<name:"a" id:1 type:<family: IntFamily width: 64 precision: 0 locale: "" visible_type: 0 oid: 20 time_precision_is_set: false > nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:2 families:<name:"primary" id:0 column_names:"a" column_ids:1 default_column_id:0 > next_family_id:1 primary_index:<name:"table_regional_by_table_pkey" id:1 unique:true version:4 key_column_names:"a" key_column_directions:ASC key_column_ids:1 foreign_key:<table:0 index:0 name:"" validity:Validated shared_prefix_len:0 on_delete:NO_ACTION on_update:NO_ACTION match:SIMPLE > interleave:<> partitioning:<num_columns:0 num_implicit_columns:0 > type:FORWARD created_explicitly:false encoding_type:1 sharded:<is_sharded:false name:"" shard_buckets:0 > disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:1640995200000000000 constraint_id:1 not_visible:false > next_index_id:2 privileges:<users:<user_proto:"admin" privileges:2 with_grant_option:2 > users:<user_proto:"root" privileges:2 with_grant_option:2 > owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false drop_time:0 replacement_of:<id:0 time:<> > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<wall_time:1640995200000000000 > temporary:false locality_config:<regional_by_table:<region:"us-east2" > > partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 import_start_wall_time:0
# end StatementPhase
# begin PreCommitPhase
## PreCommitPhase stage 1 of 1 with 6 MutationType ops
## PreCommitPhase stage 1 of 1 with 20 MutationType ops
delete database namespace entry {0 0 multi_region_test_db} -> 104
delete object namespace entry {104 106 crdb_internal_region} -> 105
delete schema namespace entry {104 0 public} -> 106
delete object namespace entry {104 106 _crdb_internal_region} -> 107
delete object namespace entry {104 106 table_regional_by_table} -> 108
upsert descriptor #104
database:
+ declarativeSchemaChangerState:
Expand All @@ -44,10 +49,6 @@ upsert descriptor #104
id: 104
modificationTime: {}
...
public:
id: 106
- state: DROP
version: "2"
upsert descriptor #105
type:
arrayTypeId: 107
Expand All @@ -66,10 +67,6 @@ upsert descriptor #105
enumMembers:
- logicalRepresentation: us-east1
...
primaryRegion: us-east1
zoneConfigExtensions: {}
- state: DROP
version: "3"
upsert descriptor #106
schema:
+ declarativeSchemaChangerState:
Expand All @@ -87,10 +84,6 @@ upsert descriptor #106
id: 106
modificationTime: {}
...
withGrantOption: 2
version: 2
- state: DROP
version: "2"
upsert descriptor #107
...
family: ArrayFamily
Expand All @@ -110,10 +103,6 @@ upsert descriptor #107
id: 107
kind: ALIAS
...
withGrantOption: 2
version: 2
- state: DROP
version: "2"
upsert descriptor #108
...
createAsOfTime:
Expand All @@ -130,14 +119,12 @@ upsert descriptor #108
+ statementTag: DROP DATABASE
+ targetRanks: <redacted>
+ targets: <redacted>
+ dropTime: <redacted>"
families:
- columnIds:
...
replacementOf:
time: {}
- state: DROP
unexposedParentSchemaId: 106
version: "2"
delete all comments for table descriptors [108]
delete role settings for database on #104
create job #1 (non-cancelable: true): "DROP DATABASE multi_region_test_db CASCADE"
descriptor IDs: [104 105 106 107 108]
# end PreCommitPhase
Expand All @@ -147,100 +134,7 @@ notified job registry to adopt jobs: [1]
begin transaction #2
commit transaction #2
begin transaction #3
## PostCommitNonRevertiblePhase stage 1 of 2 with 20 MutationType ops
delete database namespace entry {0 0 multi_region_test_db} -> 104
delete object namespace entry {104 106 crdb_internal_region} -> 105
delete schema namespace entry {104 0 public} -> 106
delete object namespace entry {104 106 _crdb_internal_region} -> 107
delete object namespace entry {104 106 table_regional_by_table} -> 108
upsert descriptor #104
...
targets: <redacted>
id: 104
- modificationTime:
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: multi_region_test_db
privileges:
...
public:
id: 106
- version: "2"
+ state: DROP
+ version: "3"
upsert descriptor #105
...
id: 105
kind: MULTIREGION_ENUM
- modificationTime:
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: crdb_internal_region
parentId: 104
...
primaryRegion: us-east1
zoneConfigExtensions: {}
- version: "3"
+ state: DROP
+ version: "4"
upsert descriptor #106
...
targets: <redacted>
id: 106
- modificationTime:
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: public
parentId: 104
...
withGrantOption: 2
version: 2
- version: "2"
+ state: DROP
+ version: "3"
upsert descriptor #107
...
id: 107
kind: ALIAS
- modificationTime:
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: _crdb_internal_region
parentId: 104
...
withGrantOption: 2
version: 2
- version: "2"
+ state: DROP
+ version: "3"
upsert descriptor #108
...
targetRanks: <redacted>
targets: <redacted>
+ dropTime: <redacted>"
families:
- columnIds:
...
regionalByTable:
region: us-east2
- modificationTime:
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: table_regional_by_table
nextColumnId: 2
...
replacementOf:
time: {}
+ state: DROP
unexposedParentSchemaId: 106
- version: "2"
+ version: "3"
delete all comments for table descriptors [108]
delete role settings for database on #104
update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 2 with 14 MutationType ops pending"
commit transaction #3
begin transaction #4
## PostCommitNonRevertiblePhase stage 2 of 2 with 20 MutationType ops
## PostCommitNonRevertiblePhase stage 1 of 1 with 20 MutationType ops
upsert descriptor #108
...
createAsOfTime:
Expand All @@ -263,15 +157,15 @@ upsert descriptor #108
regionalByTable:
region: us-east2
- modificationTime:
- wallTime: "1640995200000000003"
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: table_regional_by_table
nextColumnId: 2
...
state: DROP
unexposedParentSchemaId: 106
- version: "3"
+ version: "4"
- version: "2"
+ version: "3"
delete descriptor #104
delete descriptor #105
delete descriptor #106
Expand All @@ -280,6 +174,6 @@ write *eventpb.DropDatabase to event log: DROP DATABASE ‹multi_region_test_db
create job #2 (non-cancelable: true): "GC for DROP DATABASE multi_region_test_db CASCADE"
descriptor IDs: [108 104]
update progress of schema change job #1: "all stages completed"
commit transaction #4
commit transaction #3
notified job registry to adopt jobs: [2]
# end PostCommitPhase
106 changes: 24 additions & 82 deletions pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ increment telemetry for sql.schema.drop_table
added synthetic descriptor: name:"table_regional_by_row" id:108 version:2 modification_time:<> parent_id:104 unexposed_parent_schema_id:106 columns:<name:"k" id:1 type:<family: IntFamily width: 64 precision: 0 locale: "" visible_type: 0 oid: 20 time_precision_is_set: false > nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns:<name:"crdb_region" id:2 type:<family: EnumFamily width: 0 precision: 0 locale: "" visible_type: 0 oid: 100105 time_precision_is_set: false udt_metadata: < array_type_oid: 100107 > > nullable:false default_expr:"default_to_database_primary_region(gateway_region())::@100105" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families:<name:"primary" id:0 column_names:"k" column_names:"crdb_region" column_ids:1 column_ids:2 default_column_id:2 > next_family_id:1 primary_index:<name:"table_regional_by_row_pkey" id:1 unique:true version:4 key_column_names:"crdb_region" key_column_names:"k" key_column_directions:ASC key_column_directions:ASC key_column_ids:2 key_column_ids:1 foreign_key:<table:0 index:0 name:"" validity:Validated shared_prefix_len:0 on_delete:NO_ACTION on_update:NO_ACTION match:SIMPLE > interleave:<> partitioning:<num_columns:1 num_implicit_columns:1 list:<name:"us-east1" values:"\006\001@" subpartitioning:<num_columns:0 num_implicit_columns:0 > > list:<name:"us-east2" values:"\006\001\200" subpartitioning:<num_columns:0 num_implicit_columns:0 > > list:<name:"us-east3" values:"\006\001\300" subpartitioning:<num_columns:0 num_implicit_columns:0 > > > type:FORWARD created_explicitly:false encoding_type:1 sharded:<is_sharded:false name:"" shard_buckets:0 > disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:1640995200000000000 constraint_id:1 not_visible:false > next_index_id:2 privileges:<users:<user_proto:"admin" privileges:2 with_grant_option:2 > users:<user_proto:"root" privileges:2 with_grant_option:2 > owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false drop_time:0 replacement_of:<id:0 time:<> > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<wall_time:1640995200000000000 > temporary:false locality_config:<regional_by_row:<> > partition_all_by:true exclude_data_from_backup:false next_constraint_id:2 import_start_wall_time:0
# end StatementPhase
# begin PreCommitPhase
## PreCommitPhase stage 1 of 1 with 4 MutationType ops
## PreCommitPhase stage 1 of 1 with 11 MutationType ops
delete object namespace entry {104 106 table_regional_by_row} -> 108
upsert descriptor #105
type:
arrayTypeId: 107
Expand All @@ -41,6 +42,11 @@ upsert descriptor #105
name: crdb_internal_region
parentId: 104
...
withGrantOption: 2
version: 2
- referencingDescriptorIds:
- - 108
regionConfig:
primaryRegion: us-east1
zoneConfigExtensions: {}
- version: "2"
Expand All @@ -61,8 +67,10 @@ upsert descriptor #107
name: _crdb_internal_region
parentId: 104
...
referencingDescriptorIds:
- 108
withGrantOption: 2
version: 2
- referencingDescriptorIds:
- - 108
- version: "2"
+ version: "3"
upsert descriptor #108
Expand All @@ -81,14 +89,11 @@ upsert descriptor #108
+ statementTag: DROP TABLE
+ targetRanks: <redacted>
+ targets: <redacted>
+ dropTime: <redacted>"
families:
- columnIds:
...
replacementOf:
time: {}
- state: DROP
unexposedParentSchemaId: 106
version: "2"
delete all comments for table descriptors [108]
create job #1 (non-cancelable: true): "DROP TABLE multi_region_test_db.public.table_regional_by_row"
descriptor IDs: [105 107 108]
# end PreCommitPhase
Expand All @@ -98,70 +103,7 @@ notified job registry to adopt jobs: [1]
begin transaction #2
commit transaction #2
begin transaction #3
## PostCommitNonRevertiblePhase stage 1 of 2 with 11 MutationType ops
delete object namespace entry {104 106 table_regional_by_row} -> 108
upsert descriptor #105
...
id: 105
kind: MULTIREGION_ENUM
- modificationTime:
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: crdb_internal_region
parentId: 104
...
withGrantOption: 2
version: 2
- referencingDescriptorIds:
- - 108
regionConfig:
primaryRegion: us-east1
zoneConfigExtensions: {}
- version: "3"
+ version: "4"
upsert descriptor #107
...
id: 107
kind: ALIAS
- modificationTime:
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: _crdb_internal_region
parentId: 104
...
withGrantOption: 2
version: 2
- referencingDescriptorIds:
- - 108
- version: "3"
+ version: "4"
upsert descriptor #108
...
targetRanks: <redacted>
targets: <redacted>
+ dropTime: <redacted>"
families:
- columnIds:
...
localityConfig:
regionalByRow: {}
- modificationTime:
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: table_regional_by_row
nextColumnId: 3
...
replacementOf:
time: {}
+ state: DROP
unexposedParentSchemaId: 106
- version: "2"
+ version: "3"
delete all comments for table descriptors [108]
update progress of schema change job #1: "PostCommitNonRevertiblePhase stage 2 of 2 with 6 MutationType ops pending"
commit transaction #3
begin transaction #4
## PostCommitNonRevertiblePhase stage 2 of 2 with 10 MutationType ops
## PostCommitNonRevertiblePhase stage 1 of 1 with 10 MutationType ops
upsert descriptor #105
type:
arrayTypeId: 107
Expand All @@ -175,15 +117,15 @@ upsert descriptor #105
id: 105
kind: MULTIREGION_ENUM
- modificationTime:
- wallTime: "1640995200000000003"
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: crdb_internal_region
parentId: 104
...
primaryRegion: us-east1
zoneConfigExtensions: {}
- version: "4"
+ version: "5"
- version: "3"
+ version: "4"
upsert descriptor #107
...
family: ArrayFamily
Expand All @@ -195,15 +137,15 @@ upsert descriptor #107
id: 107
kind: ALIAS
- modificationTime:
- wallTime: "1640995200000000003"
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: _crdb_internal_region
parentId: 104
...
withGrantOption: 2
version: 2
- version: "4"
+ version: "5"
- version: "3"
+ version: "4"
upsert descriptor #108
...
createAsOfTime:
Expand All @@ -226,19 +168,19 @@ upsert descriptor #108
localityConfig:
regionalByRow: {}
- modificationTime:
- wallTime: "1640995200000000003"
- wallTime: "1640995200000000001"
+ modificationTime: {}
name: table_regional_by_row
nextColumnId: 3
...
state: DROP
unexposedParentSchemaId: 106
- version: "3"
+ version: "4"
- version: "2"
+ version: "3"
write *eventpb.DropTable to event log: DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_row›
create job #2 (non-cancelable: true): "GC for DROP TABLE multi_region_test_db.public.table_regional_by_row"
descriptor IDs: [108]
update progress of schema change job #1: "all stages completed"
commit transaction #4
commit transaction #3
notified job registry to adopt jobs: [2]
# end PostCommitPhase
Loading

0 comments on commit e70db5e

Please sign in to comment.