-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent downgrades when there is a single-shard table in the cluster (#…
…6908) Also add a few tests for Citus/PG upgrade/downgrade scenarios.
- Loading branch information
1 parent
893ed41
commit e7abde7
Showing
9 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
21 changes: 20 additions & 1 deletion
21
src/backend/distributed/sql/downgrades/citus--12.0-1--11.3-1.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,21 @@ | ||
-- citus--12.0-1--11.3-1 | ||
-- this is an empty downgrade path since citus--11.3-1--12.0-1.sql is empty for now | ||
|
||
-- Throw an error if user has any distributed tables without a shard key. | ||
DO $$ | ||
BEGIN | ||
IF EXISTS ( | ||
SELECT 1 FROM pg_dist_partition | ||
WHERE repmodel != 't' AND partmethod = 'n' AND colocationid != 0) | ||
THEN | ||
RAISE EXCEPTION 'cannot downgrade Citus because there are ' | ||
'distributed tables without a shard key.' | ||
USING HINT = 'You can find the distributed tables without a shard ' | ||
'key in the cluster by using the following query: ' | ||
'"SELECT * FROM citus_tables WHERE distribution_column ' | ||
'= ''<none>'' AND colocation_id > 0".', | ||
DETAIL = 'To downgrade Citus to an older version, you should ' | ||
'first convert those tables to Postgres tables by ' | ||
'executing SELECT undistribute_table("%s").'; | ||
END IF; | ||
END; | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/regress/expected/upgrade_single_shard_table_after.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- check that we properly retained the single-shard table | ||
SELECT 1 FROM pg_dist_partition | ||
WHERE logicalrelid = 'citus_schema.null_shard_key'::regclass AND | ||
partmethod = 'n' AND repmodel = 's' AND colocationid != 0; | ||
?column? | ||
--------------------------------------------------------------------- | ||
1 | ||
(1 row) | ||
|
||
BEGIN; | ||
INSERT INTO citus_schema.null_shard_key (name) VALUES ('c'); | ||
SELECT * FROM citus_schema.null_shard_key ORDER BY id; | ||
id | name | ||
--------------------------------------------------------------------- | ||
1 | a | ||
2 | b | ||
| c | ||
(3 rows) | ||
|
||
ROLLBACK; | ||
-- Check that we can create a distributed table with a single-shard | ||
-- after upgrade. | ||
CREATE TABLE citus_schema.null_shard_key_after_upgrade (id bigserial, name text); | ||
SELECT create_distributed_table('citus_schema.null_shard_key_after_upgrade', null); | ||
create_distributed_table | ||
--------------------------------------------------------------------- | ||
|
||
(1 row) | ||
|
||
INSERT INTO citus_schema.null_shard_key_after_upgrade (name) VALUES ('c'); | ||
SELECT * FROM citus_schema.null_shard_key_after_upgrade ORDER BY id; | ||
id | name | ||
--------------------------------------------------------------------- | ||
1 | c | ||
(1 row) | ||
|
||
DROP TABLE citus_schema.null_shard_key_after_upgrade; |
8 changes: 8 additions & 0 deletions
8
src/test/regress/expected/upgrade_single_shard_table_before.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE null_shard_key (id int, name text); | ||
SELECT create_distributed_table('null_shard_key', null); | ||
create_distributed_table | ||
--------------------------------------------------------------------- | ||
|
||
(1 row) | ||
|
||
INSERT INTO null_shard_key (id, name) VALUES (1, 'a'), (2, 'b'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- check that we properly retained the single-shard table | ||
SELECT 1 FROM pg_dist_partition | ||
WHERE logicalrelid = 'citus_schema.null_shard_key'::regclass AND | ||
partmethod = 'n' AND repmodel = 's' AND colocationid != 0; | ||
|
||
BEGIN; | ||
INSERT INTO citus_schema.null_shard_key (name) VALUES ('c'); | ||
SELECT * FROM citus_schema.null_shard_key ORDER BY id; | ||
ROLLBACK; | ||
|
||
-- Check that we can create a distributed table with a single-shard | ||
-- after upgrade. | ||
CREATE TABLE citus_schema.null_shard_key_after_upgrade (id bigserial, name text); | ||
SELECT create_distributed_table('citus_schema.null_shard_key_after_upgrade', null); | ||
INSERT INTO citus_schema.null_shard_key_after_upgrade (name) VALUES ('c'); | ||
SELECT * FROM citus_schema.null_shard_key_after_upgrade ORDER BY id; | ||
|
||
DROP TABLE citus_schema.null_shard_key_after_upgrade; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE TABLE null_shard_key (id int, name text); | ||
SELECT create_distributed_table('null_shard_key', null); | ||
INSERT INTO null_shard_key (id, name) VALUES (1, 'a'), (2, 'b'); |