From 0dee4f8418dc0bddf186949115b5ecb765b2c263 Mon Sep 17 00:00:00 2001 From: Brian Cloutier Date: Thu, 10 Aug 2017 15:34:41 +0300 Subject: [PATCH] Metadata sync syncs all nodes, not just primaries --- .../distributed/metadata/metadata_sync.c | 6 +++- .../regress/expected/multi_metadata_sync.out | 34 ++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index a8662471a..3d2f85d7d 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -29,6 +29,7 @@ #include "catalog/pg_type.h" #include "distributed/citus_ruleutils.h" #include "distributed/distribution_column.h" +#include "distributed/listutils.h" #include "distributed/master_metadata_utility.h" #include "distributed/master_protocol.h" #include "distributed/metadata_cache.h" @@ -226,11 +227,14 @@ MetadataCreateCommands(void) List *metadataSnapshotCommandList = NIL; List *distributedTableList = DistributedTableList(); List *propagatedTableList = NIL; - List *workerNodeList = ActivePrimaryNodeList(); + List *workerNodeList = ReadWorkerNodes(); ListCell *distributedTableCell = NULL; char *nodeListInsertCommand = NULL; bool includeSequenceDefaults = true; + /* make sure we have deterministic output for our tests */ + SortList(workerNodeList, CompareWorkerNodes); + /* generate insert command for pg_dist_node table */ nodeListInsertCommand = NodeListInsertCommand(workerNodeList); metadataSnapshotCommandList = lappend(metadataSnapshotCommandList, diff --git a/src/test/regress/expected/multi_metadata_sync.out b/src/test/regress/expected/multi_metadata_sync.out index 7377c8824..bc745d078 100644 --- a/src/test/regress/expected/multi_metadata_sync.out +++ b/src/test/regress/expected/multi_metadata_sync.out @@ -31,7 +31,7 @@ SELECT unnest(master_metadata_snapshot()); ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- SELECT worker_drop_distributed_table(logicalrelid) FROM pg_dist_partition TRUNCATE pg_dist_node - INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default') + INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default') (3 rows) -- Create a test table with constraints and SERIAL @@ -57,7 +57,7 @@ SELECT unnest(master_metadata_snapshot()); -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- SELECT worker_drop_distributed_table(logicalrelid) FROM pg_dist_partition TRUNCATE pg_dist_node - INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default') + INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default') SELECT worker_apply_sequence_command ('CREATE SEQUENCE IF NOT EXISTS mx_test_table_col_3_seq INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 NO CYCLE') ALTER SEQUENCE public.mx_test_table_col_3_seq OWNER TO postgres CREATE TABLE public.mx_test_table (col_1 integer, col_2 text NOT NULL, col_3 bigint DEFAULT nextval('public.mx_test_table_col_3_seq'::regclass) NOT NULL) @@ -78,7 +78,7 @@ SELECT unnest(master_metadata_snapshot()); -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- SELECT worker_drop_distributed_table(logicalrelid) FROM pg_dist_partition TRUNCATE pg_dist_node - INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default') + INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default') SELECT worker_apply_sequence_command ('CREATE SEQUENCE IF NOT EXISTS mx_test_table_col_3_seq INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 NO CYCLE') ALTER SEQUENCE public.mx_test_table_col_3_seq OWNER TO postgres CREATE TABLE public.mx_test_table (col_1 integer, col_2 text NOT NULL, col_3 bigint DEFAULT nextval('public.mx_test_table_col_3_seq'::regclass) NOT NULL) @@ -101,7 +101,7 @@ SELECT unnest(master_metadata_snapshot()); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ SELECT worker_drop_distributed_table(logicalrelid) FROM pg_dist_partition TRUNCATE pg_dist_node - INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default') + INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default') CREATE SCHEMA IF NOT EXISTS mx_testing_schema AUTHORIZATION postgres SELECT worker_apply_sequence_command ('CREATE SEQUENCE IF NOT EXISTS mx_testing_schema.mx_test_table_col_3_seq INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 NO CYCLE') ALTER SEQUENCE mx_testing_schema.mx_test_table_col_3_seq OWNER TO postgres @@ -130,7 +130,7 @@ SELECT unnest(master_metadata_snapshot()); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ SELECT worker_drop_distributed_table(logicalrelid) FROM pg_dist_partition TRUNCATE pg_dist_node - INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default') + INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default') CREATE SCHEMA IF NOT EXISTS mx_testing_schema AUTHORIZATION postgres SELECT worker_apply_sequence_command ('CREATE SEQUENCE IF NOT EXISTS mx_testing_schema.mx_test_table_col_3_seq INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 NO CYCLE') ALTER SEQUENCE mx_testing_schema.mx_test_table_col_3_seq OWNER TO postgres @@ -152,7 +152,7 @@ SELECT unnest(master_metadata_snapshot()); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ SELECT worker_drop_distributed_table(logicalrelid) FROM pg_dist_partition TRUNCATE pg_dist_node - INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default') + INSERT INTO pg_dist_node (nodeid, groupid, nodename, nodeport, noderack, hasmetadata, isactive, noderole, nodecluster) VALUES (1, 1, 'localhost', 57637, 'default', FALSE, TRUE, 'primary'::noderole, 'default'),(2, 2, 'localhost', 57638, 'default', FALSE, TRUE, 'primary'::noderole, 'default') CREATE SCHEMA IF NOT EXISTS mx_testing_schema AUTHORIZATION postgres SELECT worker_apply_sequence_command ('CREATE SEQUENCE IF NOT EXISTS mx_testing_schema.mx_test_table_col_3_seq INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 NO CYCLE') ALTER SEQUENCE mx_testing_schema.mx_test_table_col_3_seq OWNER TO postgres @@ -229,11 +229,12 @@ SELECT * FROM pg_dist_local_group; (1 row) SELECT * FROM pg_dist_node ORDER BY nodeid; - nodeid | groupid | nodename | nodeport | noderack | hasmetadata | isactive | noderole | nodecluster ---------+---------+-----------+----------+----------+-------------+----------+----------+------------- - 1 | 1 | localhost | 57637 | default | t | t | primary | default - 2 | 2 | localhost | 57638 | default | f | t | primary | default -(2 rows) + nodeid | groupid | nodename | nodeport | noderack | hasmetadata | isactive | noderole | nodecluster +--------+---------+-----------+----------+----------+-------------+----------+-----------+------------- + 1 | 1 | localhost | 57637 | default | t | t | primary | default + 2 | 2 | localhost | 57638 | default | f | t | primary | default + 4 | 1 | localhost | 8888 | default | f | t | secondary | default +(3 rows) SELECT * FROM pg_dist_partition ORDER BY logicalrelid; logicalrelid | partmethod | partkey | colocationid | repmodel @@ -366,11 +367,12 @@ SELECT * FROM pg_dist_local_group; (1 row) SELECT * FROM pg_dist_node ORDER BY nodeid; - nodeid | groupid | nodename | nodeport | noderack | hasmetadata | isactive | noderole | nodecluster ---------+---------+-----------+----------+----------+-------------+----------+----------+------------- - 1 | 1 | localhost | 57637 | default | t | t | primary | default - 2 | 2 | localhost | 57638 | default | f | t | primary | default -(2 rows) + nodeid | groupid | nodename | nodeport | noderack | hasmetadata | isactive | noderole | nodecluster +--------+---------+-----------+----------+----------+-------------+----------+-----------+------------- + 1 | 1 | localhost | 57637 | default | t | t | primary | default + 2 | 2 | localhost | 57638 | default | f | t | primary | default + 4 | 1 | localhost | 8888 | default | f | t | secondary | default +(3 rows) SELECT * FROM pg_dist_partition ORDER BY logicalrelid; logicalrelid | partmethod | partkey | colocationid | repmodel