prefailover(p_is_candidate integer, p_failed_node boolean)

Slony-I 2.2.10 Documentation
Prev | Fast Backward | Chapter 8. Schema schemadoc | Fast Forward | Next

# 8.81. prefailover(p_is_candidate integer, p_failed_node boolean)

Function Properties

Language: PLPGSQL

Return Type: integer

Prepare for a failover. This function is called on all candidate nodes. It blanks the paths to the failed node and then restart of all node daemons.

    declare
    	v_row				record;
    	v_row2				record;
    	v_n					int4;
    begin
    	-- ----
    	-- Grab the central configuration lock
    	-- ----
    	lock table sl_config_lock;

    	-- ----
    	-- All consistency checks first

    	if p_is_candidate then
    	   -- ----
    	   -- Check all sets originating on the failed node
    	   -- ----
    	   for v_row in select set_id
    			from sl_set
    			where set_origin = p_failed_node
    		loop
    				-- ----
    				-- Check that the backup node is subscribed to all sets
    				-- that originate on the failed node
    				-- ----
    				select into v_row2 sub_forward, sub_active
    					   from sl_subscribe
    					   where sub_set = v_row.set_id
    					and sub_receiver = getLocalNodeId('_schemadoc');
    				if not found then
    				   raise exception 'Slony-I: cannot failover - node % is not subscribed to set %',
    					getLocalNodeId('_schemadoc'), v_row.set_id;
    				end if;

    				-- ----
    				-- Check that the subscription is active
    				-- ----
    				if not v_row2.sub_active then
    				   raise exception 'Slony-I: cannot failover - subscription for set % is not active',
    					v_row.set_id;
    				end if;

    				-- ----
    				-- If there are other subscribers, the backup node needs to
    				-- be a forwarder too.
    				-- ----
    				select into v_n count(*)
    					   from sl_subscribe
    					   where sub_set = v_row.set_id
    					   and sub_receiver <> getLocalNodeId('_schemadoc');
    				if v_n > 0 and not v_row2.sub_forward then
    				raise exception 'Slony-I: cannot failover - node % is not a forwarder of set %',
    					 getLocalNodeId('_schemadoc'), v_row.set_id;
    				end if;
    			end loop;
    	end if;

    	-- ----
    	-- Terminate all connections of the failed node the hard way
    	-- ----
    	perform terminateNodeConnections(p_failed_node);

    	update sl_path set pa_conninfo='<event pending>' WHERE
    	   		  pa_server=p_failed_node;
    	notify "_schemadoc_Restart";
    	-- ----
    	-- That is it - so far.
    	-- ----
    	return p_failed_node;
    end;

Prev | Home | Next
moveset_int(p_wait_seqno integer, p_new_origin integer, p_old_origin integer, p_set_id bigint) | Up | preparetableforcopy(p_tab_id integer)