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 committed Sep 1, 2022
1 parent c3f8252 commit 2ada0c2
Show file tree
Hide file tree
Showing 221 changed files with 8,773 additions and 3,586 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,45 @@ begin transaction #1
checking for feature: DROP DATABASE
increment telemetry for sql.schema.drop_database
## StatementPhase stage 1 of 1 with 5 MutationType ops
added synthetic descriptor: name:"multi_region_test_db" id:104 modification_time:<> version:2 privileges:<users:<user_proto:"admin" privileges:2 with_grant_option:2 > users:<user_proto:"public" privileges:2048 with_grant_option:0 > users:<user_proto:"root" privileges:2 with_grant_option:2 > owner_proto:"root" version:2 > schemas:<key:"public" value:<id:106 > > state:DROP offline_reason:"" region_config:<survival_goal:REGION_FAILURE primary_region:"us-east1" region_enum_id:105 placement:DEFAULT secondary_region:"" >
added synthetic descriptor: name:"crdb_internal_region" id:105 version:3 modification_time:<> privileges:<users:<user_proto:"admin" privileges:2 with_grant_option:2 > users:<user_proto:"public" privileges:512 with_grant_option:0 > users:<user_proto:"root" privileges:2 with_grant_option:2 > owner_proto:"root" version:2 > parent_id:104 parent_schema_id:106 array_type_id:107 state:DROP offline_reason:"" kind:MULTIREGION_ENUM referencing_descriptor_ids:108 enum_members:<physical_representation:"@" logical_representation:"us-east1" capability:ALL direction:NONE > enum_members:<physical_representation:"\200" logical_representation:"us-east2" capability:ALL direction:NONE > enum_members:<physical_representation:"\300" logical_representation:"us-east3" capability:ALL direction:NONE > region_config:<primary_region:"us-east1" zone_config_extensions:<> secondary_region:"" >
added synthetic descriptor: name:"public" id:106 state:DROP offline_reason:"" modification_time:<> version:2 parent_id:104 privileges:<users:<user_proto:"admin" privileges:2 with_grant_option:2 > users:<user_proto:"public" privileges:516 with_grant_option:0 > users:<user_proto:"root" privileges:2 with_grant_option:2 > owner_proto:"admin" version:2 >
added synthetic descriptor: name:"_crdb_internal_region" id:107 version:2 modification_time:<> privileges:<users:<user_proto:"admin" privileges:2 with_grant_option:2 > users:<user_proto:"public" privileges:512 with_grant_option:0 > users:<user_proto:"root" privileges:2 with_grant_option:2 > owner_proto:"root" version:2 > parent_id:104 parent_schema_id:106 array_type_id:0 state:DROP offline_reason:"" kind:ALIAS alias:<family: ArrayFamily width: 0 precision: 0 locale: "" visible_type: 0 oid: 100107 array_contents: < family: EnumFamily width: 0 precision: 0 locale: "" visible_type: 0 oid: 100105 time_precision_is_set: false udt_metadata: < array_type_oid: 100107 > > time_precision_is_set: false >
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
add synthetic descriptor #104:
...
public:
id: 106
+ state: DROP
version: "1"
add synthetic descriptor #106:
...
withGrantOption: 2
version: 2
+ state: DROP
version: "1"
add synthetic descriptor #105:
...
primaryRegion: us-east1
zoneConfigExtensions: {}
+ state: DROP
version: "2"
add synthetic descriptor #107:
...
withGrantOption: 2
version: 2
+ state: DROP
version: "1"
add synthetic descriptor #108:
...
replacementOf:
time: {}
+ state: DROP
unexposedParentSchemaId: 106
version: "1"
# 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 @@ -42,12 +73,17 @@ upsert descriptor #104
+ targetRanks: <redacted>
+ targets: <redacted>
id: 104
modificationTime: {}
- modificationTime:
- wallTime: "1640995200000000000"
+ modificationTime: {}
name: multi_region_test_db
privileges:
...
public:
id: 106
- state: DROP
version: "2"
- version: "1"
+ state: DROP
+ version: "2"
upsert descriptor #105
type:
arrayTypeId: 107
Expand All @@ -65,11 +101,20 @@ upsert descriptor #105
+ targets: <redacted>
enumMembers:
- logicalRepresentation: us-east1
...
id: 105
kind: MULTIREGION_ENUM
- modificationTime:
- wallTime: "1640995200000000000"
+ modificationTime: {}
name: crdb_internal_region
parentId: 104
...
primaryRegion: us-east1
zoneConfigExtensions: {}
- state: DROP
version: "3"
- version: "2"
+ state: DROP
+ version: "3"
upsert descriptor #106
schema:
+ declarativeSchemaChangerState:
Expand All @@ -85,12 +130,17 @@ upsert descriptor #106
+ targetRanks: <redacted>
+ targets: <redacted>
id: 106
modificationTime: {}
- modificationTime:
- wallTime: "1640995200000000000"
+ modificationTime: {}
name: public
parentId: 104
...
withGrantOption: 2
version: 2
- state: DROP
version: "2"
- version: "1"
+ state: DROP
+ version: "2"
upsert descriptor #107
...
family: ArrayFamily
Expand All @@ -109,11 +159,17 @@ upsert descriptor #107
+ targets: <redacted>
id: 107
kind: ALIAS
- modificationTime:
- wallTime: "1640995200000000000"
+ modificationTime: {}
name: _crdb_internal_region
parentId: 104
...
withGrantOption: 2
version: 2
- state: DROP
version: "2"
- version: "1"
+ state: DROP
+ version: "2"
upsert descriptor #108
...
createAsOfTime:
Expand All @@ -130,101 +186,14 @@ upsert descriptor #108
+ statementTag: DROP DATABASE
+ targetRanks: <redacted>
+ targets: <redacted>
families:
- columnIds:
...
replacementOf:
time: {}
- state: DROP
unexposedParentSchemaId: 106
version: "2"
create job #1 (non-cancelable: true): "DROP DATABASE multi_region_test_db CASCADE"
descriptor IDs: [104 105 106 107 108]
# end PreCommitPhase
commit transaction #1
notified job registry to adopt jobs: [1]
# begin PostCommitPhase
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"
- wallTime: "1640995200000000000"
+ modificationTime: {}
name: table_regional_by_table
nextColumnId: 2
Expand All @@ -233,14 +202,20 @@ upsert descriptor #108
time: {}
+ state: DROP
unexposedParentSchemaId: 106
- version: "2"
+ version: "3"
- version: "1"
+ version: "2"
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
create job #1 (non-cancelable: true): "DROP DATABASE multi_region_test_db CASCADE"
descriptor IDs: [104 105 106 107 108]
# end PreCommitPhase
commit transaction #1
notified job registry to adopt jobs: [1]
# begin PostCommitPhase
begin transaction #2
commit transaction #2
begin transaction #3
## PostCommitNonRevertiblePhase stage 1 of 1 with 20 MutationType ops
upsert descriptor #108
...
createAsOfTime:
Expand All @@ -263,15 +238,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 +255,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
Loading

0 comments on commit 2ada0c2

Please sign in to comment.