mirror of https://github.com/citusdata/citus.git
Record if any partitioned Citus tables during upgrade (#5555)
With Citus 11, the default behavior is to sync the metadata. However, partitioned tables created pre-Citus 11 might have index names that are not compatiable with metadata syncing. See https://github.com/citusdata/citus/issues/4962 for the details. With this commit, we record the existence of partitioned tables such that we can fix it later if any exists.pull/5578/head^2
parent
c43b6613d0
commit
d33650d1c1
|
@ -30,3 +30,17 @@ BEGIN
|
||||||
END IF;
|
END IF;
|
||||||
END;
|
END;
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
|
-- Here we keep track of partitioned tables that exists before Citus 11
|
||||||
|
-- where we need to call fix_all_partition_shard_index_names() before
|
||||||
|
-- metadata is synced. Note that after citus-11, we automatically
|
||||||
|
-- adjust the indexes so we only need to fix existing indexes
|
||||||
|
DO LANGUAGE plpgsql
|
||||||
|
$$
|
||||||
|
DECLARE
|
||||||
|
partitioned_table_exists bool :=false;
|
||||||
|
BEGIN
|
||||||
|
SELECT count(*) > 0 INTO partitioned_table_exists FROM pg_dist_partition p JOIN pg_class c ON p.logicalrelid = c.oid WHERE c.relkind = 'p';
|
||||||
|
UPDATE pg_dist_node_metadata SET metadata=jsonb_set(metadata, '{partitioned_citus_table_exists_pre_11}', to_jsonb(partitioned_table_exists), true);
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
|
@ -955,8 +955,35 @@ ERROR: cstore_fdw tables are deprecated as of Citus 11.0
|
||||||
HINT: Install Citus 10.2 and convert your cstore_fdw tables to the columnar access method before upgrading further
|
HINT: Install Citus 10.2 and convert your cstore_fdw tables to the columnar access method before upgrading further
|
||||||
CONTEXT: PL/pgSQL function inline_code_block line XX at RAISE
|
CONTEXT: PL/pgSQL function inline_code_block line XX at RAISE
|
||||||
DELETE FROM pg_dist_shard WHERE shardid = 1;
|
DELETE FROM pg_dist_shard WHERE shardid = 1;
|
||||||
|
-- partitioned table count is tracked on Citus 11 upgrade
|
||||||
|
CREATE TABLE e_transactions(order_id varchar(255) NULL, transaction_id int) PARTITION BY LIST(transaction_id);
|
||||||
|
CREATE TABLE orders_2020_07_01
|
||||||
|
PARTITION OF e_transactions FOR VALUES IN (1,2,3);
|
||||||
|
INSERT INTO pg_dist_partition VALUES ('e_transactions'::regclass,'h', NULL, 7, 's');
|
||||||
|
SELECT
|
||||||
|
(metadata->>'partitioned_citus_table_exists_pre_11')::boolean as partitioned_citus_table_exists_pre_11,
|
||||||
|
(metadata->>'partitioned_citus_table_exists_pre_11') IS NULL as is_null
|
||||||
|
FROM
|
||||||
|
pg_dist_node_metadata;
|
||||||
|
partitioned_citus_table_exists_pre_11 | is_null
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
| t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- Test downgrade to 10.2-4 from 11.0-1
|
-- Test downgrade to 10.2-4 from 11.0-1
|
||||||
ALTER EXTENSION citus UPDATE TO '11.0-1';
|
ALTER EXTENSION citus UPDATE TO '11.0-1';
|
||||||
|
SELECT
|
||||||
|
(metadata->>'partitioned_citus_table_exists_pre_11')::boolean as partitioned_citus_table_exists_pre_11,
|
||||||
|
(metadata->>'partitioned_citus_table_exists_pre_11') IS NULL as is_null
|
||||||
|
FROM
|
||||||
|
pg_dist_node_metadata;
|
||||||
|
partitioned_citus_table_exists_pre_11 | is_null
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
t | f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
DELETE FROM pg_dist_partition WHERE logicalrelid = 'e_transactions'::regclass;
|
||||||
|
DROP TABLE e_transactions;
|
||||||
ALTER EXTENSION citus UPDATE TO '10.2-4';
|
ALTER EXTENSION citus UPDATE TO '10.2-4';
|
||||||
-- Should be empty result since upgrade+downgrade should be a no-op
|
-- Should be empty result since upgrade+downgrade should be a no-op
|
||||||
SELECT * FROM multi_extension.print_extension_changes();
|
SELECT * FROM multi_extension.print_extension_changes();
|
||||||
|
|
|
@ -420,8 +420,30 @@ INSERT INTO pg_dist_shard (logicalrelid, shardid, shardstorage) VALUES ('pg_dist
|
||||||
ALTER EXTENSION citus UPDATE TO '11.0-1';
|
ALTER EXTENSION citus UPDATE TO '11.0-1';
|
||||||
DELETE FROM pg_dist_shard WHERE shardid = 1;
|
DELETE FROM pg_dist_shard WHERE shardid = 1;
|
||||||
|
|
||||||
|
-- partitioned table count is tracked on Citus 11 upgrade
|
||||||
|
CREATE TABLE e_transactions(order_id varchar(255) NULL, transaction_id int) PARTITION BY LIST(transaction_id);
|
||||||
|
CREATE TABLE orders_2020_07_01
|
||||||
|
PARTITION OF e_transactions FOR VALUES IN (1,2,3);
|
||||||
|
INSERT INTO pg_dist_partition VALUES ('e_transactions'::regclass,'h', NULL, 7, 's');
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
(metadata->>'partitioned_citus_table_exists_pre_11')::boolean as partitioned_citus_table_exists_pre_11,
|
||||||
|
(metadata->>'partitioned_citus_table_exists_pre_11') IS NULL as is_null
|
||||||
|
FROM
|
||||||
|
pg_dist_node_metadata;
|
||||||
|
|
||||||
-- Test downgrade to 10.2-4 from 11.0-1
|
-- Test downgrade to 10.2-4 from 11.0-1
|
||||||
ALTER EXTENSION citus UPDATE TO '11.0-1';
|
ALTER EXTENSION citus UPDATE TO '11.0-1';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
(metadata->>'partitioned_citus_table_exists_pre_11')::boolean as partitioned_citus_table_exists_pre_11,
|
||||||
|
(metadata->>'partitioned_citus_table_exists_pre_11') IS NULL as is_null
|
||||||
|
FROM
|
||||||
|
pg_dist_node_metadata;
|
||||||
|
|
||||||
|
DELETE FROM pg_dist_partition WHERE logicalrelid = 'e_transactions'::regclass;
|
||||||
|
DROP TABLE e_transactions;
|
||||||
|
|
||||||
ALTER EXTENSION citus UPDATE TO '10.2-4';
|
ALTER EXTENSION citus UPDATE TO '10.2-4';
|
||||||
-- Should be empty result since upgrade+downgrade should be a no-op
|
-- Should be empty result since upgrade+downgrade should be a no-op
|
||||||
SELECT * FROM multi_extension.print_extension_changes();
|
SELECT * FROM multi_extension.print_extension_changes();
|
||||||
|
|
Loading…
Reference in New Issue