Merge pull request #4409 from citusdata/issue4237

Prevent empty placement creation in the coordinator
pull/4449/head
Naisila Puka 2020-12-25 12:43:42 +03:00 committed by GitHub
commit b9cd91ef08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 0 deletions

View File

@ -411,6 +411,14 @@ CreateAppendDistributedShardPlacements(Oid relationId, int64 shardId,
{
int workerNodeIndex = attemptNumber % workerNodeCount;
WorkerNode *workerNode = (WorkerNode *) list_nth(workerNodeList, workerNodeIndex);
if (NodeIsCoordinator(workerNode))
{
ereport(NOTICE, (errmsg(
"Creating placements for the append partitioned tables on the coordinator is not supported, skipping coordinator ...")));
continue;
}
uint32 nodeGroupId = workerNode->groupId;
char *nodeName = workerNode->workerName;
uint32 nodePort = workerNode->workerPort;

View File

@ -510,6 +510,36 @@ NOTICE: executing the command locally: SELECT count(*) AS count FROM (coordinat
(1 row)
ROLLBACK;
-- issue #4237: preventing empty placement creation on coordinator
CREATE TABLE test_append_table(a int);
SELECT create_distributed_table('test_append_table', 'a', 'append');
create_distributed_table
---------------------------------------------------------------------
(1 row)
-- this will fail since it will try to create an empty placement in the
-- coordinator as well
SET citus.shard_replication_factor TO 3;
SELECT master_create_empty_shard('test_append_table');
NOTICE: Creating placements for the append partitioned tables on the coordinator is not supported, skipping coordinator ...
ERROR: could only create 2 of 3 of required shard replicas
-- this will create an empty shard with replicas in the two worker nodes
SET citus.shard_replication_factor TO 2;
SELECT 1 FROM master_create_empty_shard('test_append_table');
?column?
---------------------------------------------------------------------
1
(1 row)
-- verify groupid is not 0 for each placement
SELECT COUNT(*) FROM pg_dist_placement p, pg_dist_shard s WHERE p.shardid = s.shardid AND s.logicalrelid = 'test_append_table'::regclass AND p.groupid > 0;
count
---------------------------------------------------------------------
2
(1 row)
SET citus.shard_replication_factor TO 1;
\set VERBOSITY terse
DROP TABLE ref_table;
NOTICE: executing the command locally: DROP TABLE IF EXISTS coordinator_shouldhaveshards.ref_table_xxxxx CASCADE
@ -518,6 +548,7 @@ DROP TABLE test;
DROP TABLE dist_table;
DROP TABLE ref;
NOTICE: executing the command locally: DROP TABLE IF EXISTS coordinator_shouldhaveshards.ref_xxxxx CASCADE
DROP TABLE test_append_table;
DROP SCHEMA coordinator_shouldhaveshards CASCADE;
NOTICE: drop cascades to table local
SELECT 1 FROM master_set_node_property('localhost', :master_port, 'shouldhaveshards', false);

View File

@ -214,6 +214,20 @@ INSERT INTO ref_table SELECT *, * FROM generate_series(1, 100);
SELECT COUNT(*) FROM test JOIN ref_table USING(x);
ROLLBACK;
-- issue #4237: preventing empty placement creation on coordinator
CREATE TABLE test_append_table(a int);
SELECT create_distributed_table('test_append_table', 'a', 'append');
-- this will fail since it will try to create an empty placement in the
-- coordinator as well
SET citus.shard_replication_factor TO 3;
SELECT master_create_empty_shard('test_append_table');
-- this will create an empty shard with replicas in the two worker nodes
SET citus.shard_replication_factor TO 2;
SELECT 1 FROM master_create_empty_shard('test_append_table');
-- verify groupid is not 0 for each placement
SELECT COUNT(*) FROM pg_dist_placement p, pg_dist_shard s WHERE p.shardid = s.shardid AND s.logicalrelid = 'test_append_table'::regclass AND p.groupid > 0;
SET citus.shard_replication_factor TO 1;
\set VERBOSITY terse
DROP TABLE ref_table;
@ -221,6 +235,7 @@ DELETE FROM test;
DROP TABLE test;
DROP TABLE dist_table;
DROP TABLE ref;
DROP TABLE test_append_table;
DROP SCHEMA coordinator_shouldhaveshards CASCADE;