Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/backend/distributed/metadata/node_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down
98 changes: 98 additions & 0 deletions src/test/regress/expected/check_activate_secondary_node.out
Original file line number Diff line number Diff line change
@@ -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)

1 change: 1 addition & 0 deletions src/test/regress/multi_follower_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions src/test/regress/sql/check_activate_secondary_node.sql
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test adds a secondary node and activates it but doesn't clean up. Consider adding cleanup at the end to avoid polluting state for any future tests that might be added after this one in the schedule:
May be:
-- cleanup
SELECT citus_remove_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);
Loading