From e85b835065725545985153ff31b997aad0ba838f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanefi=20=C3=96nald=C4=B1?= Date: Mon, 20 Apr 2020 13:03:06 +0300 Subject: [PATCH] Skip dependency setup on coordinator node --- src/backend/distributed/metadata/node_metadata.c | 7 +++++-- src/test/regress/expected/local_shard_copy.out | 12 ------------ .../replicate_reference_tables_to_coordinator.out | 12 ++++++++++++ .../replicate_reference_tables_to_coordinator.sql | 6 ++++++ 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/backend/distributed/metadata/node_metadata.c b/src/backend/distributed/metadata/node_metadata.c index e946b7c39..bea601e5a 100644 --- a/src/backend/distributed/metadata/node_metadata.c +++ b/src/backend/distributed/metadata/node_metadata.c @@ -380,6 +380,9 @@ master_set_node_property(PG_FUNCTION_ARGS) * - All dependencies (e.g., types, schemas) * - Reference tables, because they are needed to handle queries efficiently. * - Distributed functions + * + * Note that we do not create the distributed dependencies on the coordinator + * since all the dependencies should be present in the coordinator already. */ static void SetUpDistributedTableDependencies(WorkerNode *newWorkerNode) @@ -388,13 +391,13 @@ SetUpDistributedTableDependencies(WorkerNode *newWorkerNode) { EnsureNoModificationsHaveBeenDone(); - if (ShouldPropagate()) + if (ShouldPropagate() && !NodeIsCoordinator(newWorkerNode)) { PropagateNodeWideObjects(newWorkerNode); ReplicateAllDependenciesToNode(newWorkerNode->workerName, newWorkerNode->workerPort); } - else + else if (!NodeIsCoordinator(newWorkerNode)) { ereport(WARNING, (errmsg("citus.enable_object_propagation is off, not " "creating distributed objects on worker"), diff --git a/src/test/regress/expected/local_shard_copy.out b/src/test/regress/expected/local_shard_copy.out index 06963f237..94edf18bc 100644 --- a/src/test/regress/expected/local_shard_copy.out +++ b/src/test/regress/expected/local_shard_copy.out @@ -4,18 +4,6 @@ SET client_min_messages TO DEBUG; SET citus.next_shard_id TO 1570000; SET citus.replicate_reference_tables_on_activate TO off; SELECT * FROM master_add_node('localhost', :master_port, groupid := 0); -DEBUG: schema "public" already exists, skipping -DETAIL: from localhost:xxxxx -DEBUG: extension "plpgsql" already exists, skipping -DETAIL: from localhost:xxxxx -DEBUG: schema "citus_mx_test_schema" already exists, skipping -DETAIL: from localhost:xxxxx -DEBUG: schema "citus_mx_test_schema_join_1" already exists, skipping -DETAIL: from localhost:xxxxx -DEBUG: schema "citus_mx_test_schema_join_2" already exists, skipping -DETAIL: from localhost:xxxxx -DEBUG: schema "citus_mx_schema_for_xacts" already exists, skipping -DETAIL: from localhost:xxxxx master_add_node --------------------------------------------------------------------- 32 diff --git a/src/test/regress/expected/replicate_reference_tables_to_coordinator.out b/src/test/regress/expected/replicate_reference_tables_to_coordinator.out index 2b2229a1b..f8596eb52 100644 --- a/src/test/regress/expected/replicate_reference_tables_to_coordinator.out +++ b/src/test/regress/expected/replicate_reference_tables_to_coordinator.out @@ -427,6 +427,18 @@ ROLLBACK; -- see https://github.com/citusdata/citus/issues/3279 ALTER TABLE squares DROP COLUMN b; NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (8000000, 'replicate_ref_to_coordinator', 'ALTER TABLE squares DROP COLUMN b;') +-- verify that we replicate the reference tables that are distributed before +-- adding the coordinator as a worker. +SELECT master_remove_node('localhost', :master_port); + master_remove_node +--------------------------------------------------------------------- + +(1 row) + +-- add the coordinator as a worker node and verify that the reference tables are replicated +SELECT master_add_node('localhost', :master_port, groupid => 0) AS master_nodeid \gset +NOTICE: Replicating reference table "squares" to the node localhost:xxxxx +NOTICE: Replicating reference table "numbers" to the node localhost:xxxxx -- clean-up SET client_min_messages TO ERROR; DROP SCHEMA replicate_ref_to_coordinator CASCADE; diff --git a/src/test/regress/sql/replicate_reference_tables_to_coordinator.sql b/src/test/regress/sql/replicate_reference_tables_to_coordinator.sql index cf78531a8..420c24226 100644 --- a/src/test/regress/sql/replicate_reference_tables_to_coordinator.sql +++ b/src/test/regress/sql/replicate_reference_tables_to_coordinator.sql @@ -250,6 +250,12 @@ ROLLBACK; -- see https://github.com/citusdata/citus/issues/3279 ALTER TABLE squares DROP COLUMN b; +-- verify that we replicate the reference tables that are distributed before +-- adding the coordinator as a worker. +SELECT master_remove_node('localhost', :master_port); + +-- add the coordinator as a worker node and verify that the reference tables are replicated +SELECT master_add_node('localhost', :master_port, groupid => 0) AS master_nodeid \gset -- clean-up SET client_min_messages TO ERROR;