Skip to content

Commit

Permalink
schemachanger: add support for discarding subzones
Browse files Browse the repository at this point in the history
This patch adds support for discarding a subzone config in the
DSC.

Fixes: #133158
Epic: none

Release note: None
  • Loading branch information
annrpom committed Nov 20, 2024
1 parent 739f490 commit 09535d3
Show file tree
Hide file tree
Showing 46 changed files with 1,157 additions and 97 deletions.
28 changes: 28 additions & 0 deletions pkg/ccl/schemachangerccl/backup_base_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions pkg/ccl/schemachangerccl/ccl_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/ccl/schemachangerccl/testdata/decomp/multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ ElementState:
Status: PUBLIC
- PartitionZoneConfig:
indexId: 1
oldIdxRef: -1
partitionName: us-east1
seqNum: 0
subzone:
Expand Down Expand Up @@ -1392,6 +1393,7 @@ ElementState:
Status: PUBLIC
- PartitionZoneConfig:
indexId: 1
oldIdxRef: -1
partitionName: us-east2
seqNum: 0
subzone:
Expand Down Expand Up @@ -1429,6 +1431,7 @@ ElementState:
Status: PUBLIC
- PartitionZoneConfig:
indexId: 1
oldIdxRef: -1
partitionName: us-east3
seqNum: 0
subzone:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
setup
CREATE TABLE t (
id INT PRIMARY KEY,
data STRING
) PARTITION BY LIST (id) (
PARTITION p1 VALUES IN (1, 2, 3),
PARTITION p2 VALUES IN (4, 5, 6)
);
----

test
ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11;
ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12;
ALTER PARTITION p2 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10;
ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE DISCARD;
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* setup */
CREATE TABLE t (
id INT PRIMARY KEY,
data STRING
) PARTITION BY LIST (id) (
PARTITION p1 VALUES IN (1, 2, 3),
PARTITION p2 VALUES IN (4, 5, 6)
);
----
...
+object {100 101 t} -> 104

/* test */
ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11;
ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12;
ALTER PARTITION p2 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10;
ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE DISCARD;
----
begin transaction #1
# begin StatementPhase
checking for feature: CONFIGURE ZONE
write *eventpb.SetZoneConfig to event log:
config:
options:
- num_replicas = 11
target: PARTITION p1 OF INDEX defaultdb.public.t@t_pkey
resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›
tag: CONFIGURE ZONE
user: root
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
checking for feature: CONFIGURE ZONE
write *eventpb.SetZoneConfig to event log:
config:
options:
- num_replicas = 12
target: PARTITION p1 OF INDEX defaultdb.public.t@t_pkey
resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›
tag: CONFIGURE ZONE
user: root
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
checking for feature: CONFIGURE ZONE
write *eventpb.SetZoneConfig to event log:
config:
options:
- num_replicas = 10
target: PARTITION p2 OF INDEX defaultdb.public.t@t_pkey
resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p2› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹10›
tag: CONFIGURE ZONE
user: root
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
checking for feature: CONFIGURE ZONE
write *eventpb.RemoveZoneConfig to event log:
config:
target: PARTITION p1 OF INDEX defaultdb.public.t@t_pkey
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE DISCARD
tag: CONFIGURE ZONE
user: root
## StatementPhase stage 1 of 1 with 2 MutationType ops
# end StatementPhase
# begin PreCommitPhase
## PreCommitPhase stage 1 of 2 with 1 MutationType op
undo all catalog changes within txn #1
persist all catalog changes to storage
## PreCommitPhase stage 2 of 2 with 1 MutationType op
upsert zone config for #104
persist all catalog changes to storage
# end PreCommitPhase
commit transaction #1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* setup */
CREATE TABLE t (
id INT PRIMARY KEY,
data STRING
) PARTITION BY LIST (id) (
PARTITION p1 VALUES IN (1, 2, 3),
PARTITION p2 VALUES IN (4, 5, 6)
);

/* test */
EXPLAIN (DDL) ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11;
----
Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›;
├── StatementPhase
│ └── Stage 1 of 1 in StatementPhase
│ ├── 1 element transitioning toward PUBLIC
│ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"}
│ └── 1 Mutation operation
│ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104}
└── PreCommitPhase
├── Stage 1 of 2 in PreCommitPhase
│ ├── 1 element transitioning toward PUBLIC
│ │ └── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"}
│ └── 1 Mutation operation
│ └── UndoAllInTxnImmediateMutationOpSideEffects
└── Stage 2 of 2 in PreCommitPhase
├── 1 element transitioning toward PUBLIC
│ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"}
└── 1 Mutation operation
└── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* setup */
CREATE TABLE t (
id INT PRIMARY KEY,
data STRING
) PARTITION BY LIST (id) (
PARTITION p1 VALUES IN (1, 2, 3),
PARTITION p2 VALUES IN (4, 5, 6)
);

/* test */
EXPLAIN (DDL, SHAPE) ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11;
----
Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›;
└── execute 1 system table mutations transaction
Loading

0 comments on commit 09535d3

Please sign in to comment.