mirror of https://github.com/citusdata/citus.git
135 lines
4.2 KiB
Plaintext
135 lines
4.2 KiB
Plaintext
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1220000;
|
|
ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 1220000;
|
|
-- Tests functions related to cluster membership
|
|
-- add the nodes to the cluster
|
|
SELECT master_add_node('localhost', :worker_1_port);
|
|
master_add_node
|
|
-------------------------------
|
|
(1,1,localhost,57637,default)
|
|
(1 row)
|
|
|
|
SELECT master_add_node('localhost', :worker_2_port);
|
|
master_add_node
|
|
-------------------------------
|
|
(2,2,localhost,57638,default)
|
|
(1 row)
|
|
|
|
-- get the active nodes
|
|
SELECT master_get_active_worker_nodes();
|
|
master_get_active_worker_nodes
|
|
--------------------------------
|
|
(localhost,57638)
|
|
(localhost,57637)
|
|
(2 rows)
|
|
|
|
-- try to add the node again when it is activated
|
|
SELECT master_add_node('localhost', :worker_1_port);
|
|
master_add_node
|
|
-------------------------------
|
|
(1,1,localhost,57637,default)
|
|
(1 row)
|
|
|
|
-- get the active nodes
|
|
SELECT master_get_active_worker_nodes();
|
|
master_get_active_worker_nodes
|
|
--------------------------------
|
|
(localhost,57638)
|
|
(localhost,57637)
|
|
(2 rows)
|
|
|
|
-- try to remove a node (with no placements)
|
|
SELECT master_remove_node('localhost', :worker_2_port);
|
|
master_remove_node
|
|
--------------------
|
|
|
|
(1 row)
|
|
|
|
-- verify that the node has been deleted
|
|
SELECT master_get_active_worker_nodes();
|
|
master_get_active_worker_nodes
|
|
--------------------------------
|
|
(localhost,57637)
|
|
(1 row)
|
|
|
|
-- add some shard placements to the cluster
|
|
SELECT master_add_node('localhost', :worker_2_port);
|
|
master_add_node
|
|
-------------------------------
|
|
(3,3,localhost,57638,default)
|
|
(1 row)
|
|
|
|
CREATE TABLE cluster_management_test (col_1 text, col_2 int);
|
|
SELECT master_create_distributed_table('cluster_management_test', 'col_1', 'hash');
|
|
master_create_distributed_table
|
|
---------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT master_create_worker_shards('cluster_management_test', 16, 1);
|
|
master_create_worker_shards
|
|
-----------------------------
|
|
|
|
(1 row)
|
|
|
|
-- see that there are some active placements in the candidate node
|
|
SELECT shardid, shardstate, nodename, nodeport FROM pg_dist_shard_placement WHERE nodeport=:worker_2_port;
|
|
shardid | shardstate | nodename | nodeport
|
|
---------+------------+-----------+----------
|
|
1220001 | 1 | localhost | 57638
|
|
1220003 | 1 | localhost | 57638
|
|
1220005 | 1 | localhost | 57638
|
|
1220007 | 1 | localhost | 57638
|
|
1220009 | 1 | localhost | 57638
|
|
1220011 | 1 | localhost | 57638
|
|
1220013 | 1 | localhost | 57638
|
|
1220015 | 1 | localhost | 57638
|
|
(8 rows)
|
|
|
|
-- try to remove a node with active placements and see that node removal is failed
|
|
SELECT master_remove_node('localhost', :worker_2_port);
|
|
ERROR: you cannot remove a node which has active shard placements
|
|
SELECT master_get_active_worker_nodes();
|
|
master_get_active_worker_nodes
|
|
--------------------------------
|
|
(localhost,57638)
|
|
(localhost,57637)
|
|
(2 rows)
|
|
|
|
-- mark all placements in the candidate node as inactive
|
|
UPDATE pg_dist_shard_placement SET shardstate=3 WHERE nodeport=:worker_2_port;
|
|
SELECT shardid, shardstate, nodename, nodeport FROM pg_dist_shard_placement WHERE nodeport=:worker_2_port;
|
|
shardid | shardstate | nodename | nodeport
|
|
---------+------------+-----------+----------
|
|
1220001 | 3 | localhost | 57638
|
|
1220003 | 3 | localhost | 57638
|
|
1220005 | 3 | localhost | 57638
|
|
1220007 | 3 | localhost | 57638
|
|
1220009 | 3 | localhost | 57638
|
|
1220011 | 3 | localhost | 57638
|
|
1220013 | 3 | localhost | 57638
|
|
1220015 | 3 | localhost | 57638
|
|
(8 rows)
|
|
|
|
-- try to remove a node with only inactive placements and see that node is removed
|
|
SELECT master_remove_node('localhost', :worker_2_port);
|
|
master_remove_node
|
|
--------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT master_get_active_worker_nodes();
|
|
master_get_active_worker_nodes
|
|
--------------------------------
|
|
(localhost,57637)
|
|
(1 row)
|
|
|
|
-- clean-up
|
|
SELECT master_add_node('localhost', :worker_2_port);
|
|
master_add_node
|
|
-------------------------------
|
|
(4,4,localhost,57638,default)
|
|
(1 row)
|
|
|
|
UPDATE pg_dist_shard_placement SET shardstate=1 WHERE nodeport=:worker_2_port;
|
|
DROP TABLE cluster_management_test;
|