diff --git a/src/backend/distributed/metadata/node_metadata.c b/src/backend/distributed/metadata/node_metadata.c index 6174027a4fb..ee4ae0b9128 100644 --- a/src/backend/distributed/metadata/node_metadata.c +++ b/src/backend/distributed/metadata/node_metadata.c @@ -830,6 +830,12 @@ citus_activate_node(PG_FUNCTION_ARGS) if (NodeIsSecondary(workerNode)) { EnsureTransactionalMetadataSyncMode(); + + SetWorkerColumn(workerNode, Anum_pg_dist_node_isactive, BoolGetDatum(true)); + + TransactionModifiedNodeMetadata = true; + + PG_RETURN_INT32(workerNode->nodeId); } /* diff --git a/src/test/regress/expected/check_activate_secondary_node.out b/src/test/regress/expected/check_activate_secondary_node.out new file mode 100644 index 00000000000..7849e3adc8c --- /dev/null +++ b/src/test/regress/expected/check_activate_secondary_node.out @@ -0,0 +1,98 @@ +\c - - - :master_port +-- prepare testing +SELECT citus_set_coordinator_host('localhost', :master_port); + citus_set_coordinator_host +--------------------------------------------------------------------- + +(1 row) + +SET citus.metadata_sync_mode TO 'transactional'; +-- add inactive secondary node +SELECT 1 FROM citus_add_secondary_node('localhost', :follower_worker_2_port, 'localhost', :worker_2_port); + ?column? +--------------------------------------------------------------------- + 1 +(1 row) + +SELECT 1 FROM citus_disable_node('localhost', :follower_worker_2_port); + ?column? +--------------------------------------------------------------------- + 1 +(1 row) + +-- check inactive node +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND NOT isactive; + count +--------------------------------------------------------------------- + 1 +(1 row) + +SELECT start_metadata_sync_to_all_nodes(); + start_metadata_sync_to_all_nodes +--------------------------------------------------------------------- + t +(1 row) + +-- error because the node does not exist +SELECT 1 FROM citus_activate_node('localhost', 7777); +ERROR: node at "localhost:xxxxx" does not exist +\c - - - :worker_2_port +-- check inactive node on worker +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND NOT isactive; + count +--------------------------------------------------------------------- + 1 +(1 row) + +\c - - - :master_port +-- main test: activate secondary node +SELECT 1 FROM citus_activate_node('localhost', :follower_worker_2_port); + ?column? +--------------------------------------------------------------------- + 1 +(1 row) + +-- check is active node +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND isactive; + count +--------------------------------------------------------------------- + 1 +(1 row) + +\c - - - :worker_2_port +-- check is active node +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND isactive; + count +--------------------------------------------------------------------- + 1 +(1 row) + +\c - - - :worker_1_port +-- check active node +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND isactive; + count +--------------------------------------------------------------------- + 1 +(1 row) + +\c - - - :master_port +SET citus.metadata_sync_mode TO 'nontransactional'; +-- error this operation cannot be completed in nontransactional metadata sync mode +-- if the GUC citus.metadata_sync_mode set to 'nontransactional' +SELECT 1 FROM citus_activate_node('localhost', :follower_worker_2_port); +ERROR: this operation cannot be completed in nontransactional metadata sync mode +HINT: SET citus.metadata_sync_mode to 'transactional' +-- remove checked nodes +SET citus.metadata_sync_mode TO 'transactional'; +SELECT citus_remove_node('localhost', :follower_worker_2_port); + citus_remove_node +--------------------------------------------------------------------- + +(1 row) + +SELECT citus_remove_node('localhost', :master_port); + citus_remove_node +--------------------------------------------------------------------- + +(1 row) + diff --git a/src/test/regress/multi_follower_schedule b/src/test/regress/multi_follower_schedule index 3b7ea622524..92ac689a5cc 100644 --- a/src/test/regress/multi_follower_schedule +++ b/src/test/regress/multi_follower_schedule @@ -4,6 +4,7 @@ test: multi_follower_select_statements test: multi_follower_dml test: multi_follower_configure_followers test: multi_add_node_from_backup_sync_replica +test: check_activate_secondary_node # test that no tests leaked intermediate results. This should always be last test: ensure_no_intermediate_data_leak diff --git a/src/test/regress/sql/check_activate_secondary_node.sql b/src/test/regress/sql/check_activate_secondary_node.sql new file mode 100644 index 00000000000..93062c09aaf --- /dev/null +++ b/src/test/regress/sql/check_activate_secondary_node.sql @@ -0,0 +1,52 @@ +\c - - - :master_port + +-- prepare testing +SELECT citus_set_coordinator_host('localhost', :master_port); + +SET citus.metadata_sync_mode TO 'transactional'; + +-- add inactive secondary node +SELECT 1 FROM citus_add_secondary_node('localhost', :follower_worker_2_port, 'localhost', :worker_2_port); +SELECT 1 FROM citus_disable_node('localhost', :follower_worker_2_port); + +-- check inactive node +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND NOT isactive; +SELECT start_metadata_sync_to_all_nodes(); + +-- error because the node does not exist +SELECT 1 FROM citus_activate_node('localhost', 7777); + + +\c - - - :worker_2_port +-- check inactive node on worker +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND NOT isactive; + +\c - - - :master_port + +-- main test: activate secondary node +SELECT 1 FROM citus_activate_node('localhost', :follower_worker_2_port); + + +-- check is active node +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND isactive; + +\c - - - :worker_2_port +-- check is active node +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND isactive; + +\c - - - :worker_1_port +-- check active node +SELECT count(*) FROM pg_dist_node WHERE nodeport=:follower_worker_2_port AND nodename='localhost' AND isactive; + +\c - - - :master_port +SET citus.metadata_sync_mode TO 'nontransactional'; + +-- error this operation cannot be completed in nontransactional metadata sync mode +-- if the GUC citus.metadata_sync_mode set to 'nontransactional' +SELECT 1 FROM citus_activate_node('localhost', :follower_worker_2_port); + + +-- remove checked nodes +SET citus.metadata_sync_mode TO 'transactional'; +SELECT citus_remove_node('localhost', :follower_worker_2_port); +SELECT citus_remove_node('localhost', :master_port);