From 452b6a2212f2499dbcb2579ae6f1761fe99f662d Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Wed, 12 Oct 2022 18:18:51 +0300 Subject: [PATCH] Hint users to call "citus_set_coordinator_host" first (#6425) If an operation requires having coordinator in pg_dist_node and if that is not the case, then we automatically add the coordinator into pg_dist_node if user didn't add any worker nodes yet. However, if user have already added some worker nodes before, we throw an error. With this commit, we improve the error thrown in that case. Closes #6423 based on the discussion made there. (cherry picked from commit 20847515fa27c151c0a13b13c3fc416f5339bcc7) --- src/backend/distributed/operations/worker_node_manager.c | 7 +++++-- src/test/regress/expected/citus_local_tables.out | 8 +++++++- .../expected/isolation_create_citus_local_table.out | 2 +- src/test/regress/sql/citus_local_tables.sql | 6 ++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/backend/distributed/operations/worker_node_manager.c b/src/backend/distributed/operations/worker_node_manager.c index 9bab18c96..0979f52d1 100644 --- a/src/backend/distributed/operations/worker_node_manager.c +++ b/src/backend/distributed/operations/worker_node_manager.c @@ -267,8 +267,11 @@ ErrorIfCoordinatorNotAddedAsWorkerNode() return; } - ereport(ERROR, (errmsg("could not find the coordinator node in " - "metadata as it is not added as a worker"))); + ereport(ERROR, (errmsg("operation is not allowed when coordinator " + "is not added into metadata"), + errhint("Use \"SELECT citus_set_coordinator_host('" + "', '')\" to configure the " + "coordinator hostname and port"))); } diff --git a/src/test/regress/expected/citus_local_tables.out b/src/test/regress/expected/citus_local_tables.out index f2177948c..71ed1eb23 100644 --- a/src/test/regress/expected/citus_local_tables.out +++ b/src/test/regress/expected/citus_local_tables.out @@ -40,7 +40,13 @@ SELECT 1 FROM master_remove_node('localhost', :master_port); CREATE TABLE citus_local_table_1 (a int primary key); -- this should fail as coordinator is removed from pg_dist_node SELECT citus_add_local_table_to_metadata('citus_local_table_1'); -ERROR: could not find the coordinator node in metadata as it is not added as a worker +ERROR: operation is not allowed when coordinator is not added into metadata +-- This should also fail as coordinator is removed from pg_dist_node. +-- +-- This is not a great place to test this but is one of those places that we +-- have workers in metadata but not the coordinator. +SELECT create_distributed_table_concurrently('citus_local_table_1', 'a'); +ERROR: operation is not allowed when coordinator is not added into metadata -- let coordinator have citus local tables again for next tests set client_min_messages to ERROR; SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0); diff --git a/src/test/regress/expected/isolation_create_citus_local_table.out b/src/test/regress/expected/isolation_create_citus_local_table.out index a7c2c8445..b673cc5b3 100644 --- a/src/test/regress/expected/isolation_create_citus_local_table.out +++ b/src/test/regress/expected/isolation_create_citus_local_table.out @@ -239,7 +239,7 @@ master_remove_node step s2-create-citus-local-table-1: SELECT citus_add_local_table_to_metadata('citus_local_table_1'); step s1-commit: COMMIT; step s2-create-citus-local-table-1: <... completed> -ERROR: could not find the coordinator node in metadata as it is not added as a worker +ERROR: operation is not allowed when coordinator is not added into metadata step s2-commit: COMMIT; master_remove_node --------------------------------------------------------------------- diff --git a/src/test/regress/sql/citus_local_tables.sql b/src/test/regress/sql/citus_local_tables.sql index 8505734e5..00bd0bc7b 100644 --- a/src/test/regress/sql/citus_local_tables.sql +++ b/src/test/regress/sql/citus_local_tables.sql @@ -35,6 +35,12 @@ CREATE TABLE citus_local_table_1 (a int primary key); -- this should fail as coordinator is removed from pg_dist_node SELECT citus_add_local_table_to_metadata('citus_local_table_1'); +-- This should also fail as coordinator is removed from pg_dist_node. +-- +-- This is not a great place to test this but is one of those places that we +-- have workers in metadata but not the coordinator. +SELECT create_distributed_table_concurrently('citus_local_table_1', 'a'); + -- let coordinator have citus local tables again for next tests set client_min_messages to ERROR; SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0);