mirror of https://github.com/citusdata/citus.git
235 lines
7.9 KiB
Plaintext
235 lines
7.9 KiB
Plaintext
-- Tests related to distributed DDL commands on mx cluster
|
|
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1600000;
|
|
SELECT * FROM mx_ddl_table ORDER BY key;
|
|
key | value
|
|
-----+-------
|
|
1 | 10
|
|
2 | 11
|
|
3 | 21
|
|
4 | 37
|
|
5 | 60
|
|
6 | 100
|
|
10 | 200
|
|
11 | 230
|
|
(8 rows)
|
|
|
|
-- CREATE INDEX
|
|
CREATE INDEX ddl_test_index ON mx_ddl_table(value);
|
|
NOTICE: using one-phase commit for distributed DDL commands
|
|
HINT: You can enable two-phase commit for extra safety with: SET citus.multi_shard_commit_protocol TO '2pc'
|
|
CREATE INDEX CONCURRENTLY ddl_test_concurrent_index ON mx_ddl_table(value);
|
|
-- ADD COLUMN
|
|
ALTER TABLE mx_ddl_table ADD COLUMN version INTEGER;
|
|
-- SET DEFAULT
|
|
ALTER TABLE mx_ddl_table ALTER COLUMN version SET DEFAULT 1;
|
|
SELECT master_modify_multiple_shards('UPDATE mx_ddl_table SET version=0.1 WHERE version IS NULL');
|
|
master_modify_multiple_shards
|
|
-------------------------------
|
|
8
|
|
(1 row)
|
|
|
|
-- SET NOT NULL
|
|
ALTER TABLE mx_ddl_table ALTER COLUMN version SET NOT NULL;
|
|
-- See that the changes are applied on coordinator, worker tables and shards
|
|
\d mx_ddl_table
|
|
Table "public.mx_ddl_table"
|
|
Column | Type | Modifiers
|
|
---------+---------+--------------------
|
|
key | integer | not null
|
|
value | integer |
|
|
version | integer | not null default 1
|
|
Indexes:
|
|
"mx_ddl_table_pkey" PRIMARY KEY, btree (key)
|
|
"ddl_test_concurrent_index" btree (value)
|
|
"ddl_test_index" btree (value)
|
|
|
|
\c - - - :worker_1_port
|
|
\d mx_ddl_table
|
|
Table "public.mx_ddl_table"
|
|
Column | Type | Modifiers
|
|
---------+---------+--------------------
|
|
key | integer | not null
|
|
value | integer |
|
|
version | integer | not null default 1
|
|
Indexes:
|
|
"mx_ddl_table_pkey" PRIMARY KEY, btree (key)
|
|
"ddl_test_concurrent_index" btree (value)
|
|
"ddl_test_index" btree (value)
|
|
|
|
\d mx_ddl_table_1220088
|
|
Table "public.mx_ddl_table_1220088"
|
|
Column | Type | Modifiers
|
|
---------+---------+--------------------
|
|
key | integer | not null
|
|
value | integer |
|
|
version | integer | not null default 1
|
|
Indexes:
|
|
"mx_ddl_table_pkey_1220088" PRIMARY KEY, btree (key)
|
|
"ddl_test_concurrent_index_1220088" btree (value)
|
|
"ddl_test_index_1220088" btree (value)
|
|
|
|
\c - - - :worker_2_port
|
|
\d mx_ddl_table
|
|
Table "public.mx_ddl_table"
|
|
Column | Type | Modifiers
|
|
---------+---------+--------------------
|
|
key | integer | not null
|
|
value | integer |
|
|
version | integer | not null default 1
|
|
Indexes:
|
|
"mx_ddl_table_pkey" PRIMARY KEY, btree (key)
|
|
"ddl_test_concurrent_index" btree (value)
|
|
"ddl_test_index" btree (value)
|
|
|
|
\d mx_ddl_table_1220089
|
|
Table "public.mx_ddl_table_1220089"
|
|
Column | Type | Modifiers
|
|
---------+---------+--------------------
|
|
key | integer | not null
|
|
value | integer |
|
|
version | integer | not null default 1
|
|
Indexes:
|
|
"mx_ddl_table_pkey_1220089" PRIMARY KEY, btree (key)
|
|
"ddl_test_concurrent_index_1220089" btree (value)
|
|
"ddl_test_index_1220089" btree (value)
|
|
|
|
INSERT INTO mx_ddl_table VALUES (37, 78, 2);
|
|
INSERT INTO mx_ddl_table VALUES (38, 78);
|
|
-- Switch to the coordinator
|
|
\c - - - :master_port
|
|
-- SET DATA TYPE
|
|
ALTER TABLE mx_ddl_table ALTER COLUMN version SET DATA TYPE double precision;
|
|
NOTICE: using one-phase commit for distributed DDL commands
|
|
HINT: You can enable two-phase commit for extra safety with: SET citus.multi_shard_commit_protocol TO '2pc'
|
|
INSERT INTO mx_ddl_table VALUES (78, 83, 2.1);
|
|
\c - - - :worker_1_port
|
|
SELECT * FROM mx_ddl_table ORDER BY key;
|
|
key | value | version
|
|
-----+-------+---------
|
|
1 | 10 | 0
|
|
2 | 11 | 0
|
|
3 | 21 | 0
|
|
4 | 37 | 0
|
|
5 | 60 | 0
|
|
6 | 100 | 0
|
|
10 | 200 | 0
|
|
11 | 230 | 0
|
|
37 | 78 | 2
|
|
38 | 78 | 1
|
|
78 | 83 | 2.1
|
|
(11 rows)
|
|
|
|
-- Switch to the coordinator
|
|
\c - - - :master_port
|
|
-- DROP INDEX
|
|
DROP INDEX ddl_test_index;
|
|
NOTICE: using one-phase commit for distributed DDL commands
|
|
HINT: You can enable two-phase commit for extra safety with: SET citus.multi_shard_commit_protocol TO '2pc'
|
|
DROP INDEX CONCURRENTLY ddl_test_concurrent_index;
|
|
-- DROP DEFAULT
|
|
ALTER TABLE mx_ddl_table ALTER COLUMN version DROP DEFAULT;
|
|
-- DROP NOT NULL
|
|
ALTER TABLE mx_ddl_table ALTER COLUMN version DROP NOT NULL;
|
|
-- DROP COLUMN
|
|
ALTER TABLE mx_ddl_table DROP COLUMN version;
|
|
-- See that the changes are applied on coordinator, worker tables and shards
|
|
\d mx_ddl_table
|
|
Table "public.mx_ddl_table"
|
|
Column | Type | Modifiers
|
|
--------+---------+-----------
|
|
key | integer | not null
|
|
value | integer |
|
|
Indexes:
|
|
"mx_ddl_table_pkey" PRIMARY KEY, btree (key)
|
|
|
|
\c - - - :worker_1_port
|
|
\d mx_ddl_table
|
|
Table "public.mx_ddl_table"
|
|
Column | Type | Modifiers
|
|
--------+---------+-----------
|
|
key | integer | not null
|
|
value | integer |
|
|
Indexes:
|
|
"mx_ddl_table_pkey" PRIMARY KEY, btree (key)
|
|
|
|
\d mx_ddl_table_1220088
|
|
Table "public.mx_ddl_table_1220088"
|
|
Column | Type | Modifiers
|
|
--------+---------+-----------
|
|
key | integer | not null
|
|
value | integer |
|
|
Indexes:
|
|
"mx_ddl_table_pkey_1220088" PRIMARY KEY, btree (key)
|
|
|
|
\c - - - :worker_2_port
|
|
\d mx_ddl_table
|
|
Table "public.mx_ddl_table"
|
|
Column | Type | Modifiers
|
|
--------+---------+-----------
|
|
key | integer | not null
|
|
value | integer |
|
|
Indexes:
|
|
"mx_ddl_table_pkey" PRIMARY KEY, btree (key)
|
|
|
|
\d mx_ddl_table_1220089
|
|
Table "public.mx_ddl_table_1220089"
|
|
Column | Type | Modifiers
|
|
--------+---------+-----------
|
|
key | integer | not null
|
|
value | integer |
|
|
Indexes:
|
|
"mx_ddl_table_pkey_1220089" PRIMARY KEY, btree (key)
|
|
|
|
-- Show that DDL commands are done within a two-phase commit transaction
|
|
\c - - - :master_port
|
|
SET client_min_messages TO debug2;
|
|
CREATE INDEX ddl_test_index ON mx_ddl_table(value);
|
|
DEBUG: building index "ddl_test_index" on table "mx_ddl_table"
|
|
NOTICE: using one-phase commit for distributed DDL commands
|
|
HINT: You can enable two-phase commit for extra safety with: SET citus.multi_shard_commit_protocol TO '2pc'
|
|
RESET client_min_messages;
|
|
DROP INDEX ddl_test_index;
|
|
-- show that sequences owned by mx tables result in unique values
|
|
SET citus.shard_replication_factor TO 1;
|
|
SET citus.shard_count TO 4;
|
|
SET citus.replication_model TO streaming;
|
|
CREATE TABLE mx_sequence(key INT, value BIGSERIAL);
|
|
SELECT create_distributed_table('mx_sequence', 'key');
|
|
create_distributed_table
|
|
--------------------------
|
|
|
|
(1 row)
|
|
|
|
\c - - - :worker_1_port
|
|
SELECT groupid FROM pg_dist_local_group;
|
|
groupid
|
|
---------
|
|
12
|
|
(1 row)
|
|
|
|
SELECT * FROM mx_sequence_value_seq;
|
|
sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called
|
|
-----------------------+------------------+------------------+--------------+------------------+------------------+-------------+---------+-----------+-----------
|
|
mx_sequence_value_seq | 3377699720527873 | 3377699720527873 | 1 | 3659174697238529 | 3377699720527873 | 1 | 0 | f | f
|
|
(1 row)
|
|
|
|
\c - - - :worker_2_port
|
|
SELECT groupid FROM pg_dist_local_group;
|
|
groupid
|
|
---------
|
|
14
|
|
(1 row)
|
|
|
|
SELECT * FROM mx_sequence_value_seq;
|
|
sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called
|
|
-----------------------+------------------+------------------+--------------+------------------+------------------+-------------+---------+-----------+-----------
|
|
mx_sequence_value_seq | 3940649673949185 | 3940649673949185 | 1 | 4222124650659841 | 3940649673949185 | 1 | 0 | f | f
|
|
(1 row)
|
|
|
|
\c - - - :master_port
|
|
-- the type of sequences can't be changed
|
|
ALTER TABLE mx_sequence ALTER value TYPE BIGINT;
|
|
NOTICE: using one-phase commit for distributed DDL commands
|
|
HINT: You can enable two-phase commit for extra safety with: SET citus.multi_shard_commit_protocol TO '2pc'
|
|
ALTER TABLE mx_sequence ALTER value TYPE INT;
|