Skip to content

Commit

Permalink
schemachanger: support partition zone config
Browse files Browse the repository at this point in the history
This patch adds the functionality to configure
a zone configuration on a partition.

Fixes: cockroachdb#129889

Release note: None
  • Loading branch information
annrpom committed Oct 9, 2024
1 parent 32c48c2 commit 866d217
Show file tree
Hide file tree
Showing 28 changed files with 952 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ statement ok
ALTER partition "us-east-1" of index regional_by_row@regional_by_row_pkey CONFIGURE ZONE USING num_replicas = 10;

statement ok
SET override_multi_region_zone_config = false
SET override_multi_region_zone_config = false;

query TTT
SELECT ZONE_config, index_name, partition_name FROM [SHOW PARTITIONS FROM TABLE regional_by_row]
Expand Down
140 changes: 140 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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 = 7, gc.ttlseconds = 10000;
----
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 = 7, gc.ttlseconds = 10000;
----
Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›;
├── 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 {"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 {"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 = 7, gc.ttlseconds = 10000;
----
Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›;
└── execute 1 system table mutations transaction
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* 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 = 7, gc.ttlseconds = 10000;
----
begin transaction #1
# begin StatementPhase
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
# 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,20 @@
setup
CREATE TABLE t (
id INT PRIMARY KEY,
data INT,
INDEX idx (data) PARTITION BY LIST (data) (
PARTITION p1 VALUES IN (10, 20, 30),
PARTITION p2 VALUES IN (40, 50, 60)
)
) 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 = 7;
ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING gc.ttlseconds = 10000;
ALTER PARTITION p1 OF INDEX t@idx CONFIGURE ZONE USING gc.ttlseconds = 12000;
ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10;
----
Loading

0 comments on commit 866d217

Please sign in to comment.