enablenode_int(integer)

6.60. enablenode_int(integer)

Function Properties

Language: PLPGSQL

Return Type: integer

no_id - Node ID # Internal function to process the ENABLE_NODE event for node no_id

declare
	p_no_id			alias for $1;
	v_local_node_id	int4;
	v_node_row		record;
	v_sub_row		record;
begin
	-- ----
	-- Grab the central configuration lock
	-- ----
	lock table sl_config_lock;

	-- ----
	-- Check that the node is inactive
	-- ----
	select * into v_node_row
			from sl_node
			where no_id = p_no_id
			for update;
	if not found then 
		raise exception 'Slony-I: node % not found', p_no_id;
	end if;
	if v_node_row.no_active then
		return p_no_id;
	end if;

	-- ----
	-- Activate the node and generate sl_confirm status rows for it.
	-- ----
	update sl_node
			set no_active = 't'
			where no_id = p_no_id;
	insert into sl_confirm
			(con_origin, con_received, con_seqno)
			select no_id, p_no_id, 0 from sl_node
				where no_id != p_no_id
				and no_active;
	insert into sl_confirm
			(con_origin, con_received, con_seqno)
			select p_no_id, no_id, 0 from sl_node
				where no_id != p_no_id
				and no_active;

	-- ----
	-- Generate ENABLE_SUBSCRIPTION events for all sets that
	-- origin here and are subscribed by the just enabled node.
	-- ----
	v_local_node_id := getLocalNodeId('_schemadoc');
	for v_sub_row in select SUB.sub_set, SUB.sub_provider from
			sl_set S,
			sl_subscribe SUB
			where S.set_origin = v_local_node_id
			and S.set_id = SUB.sub_set
			and SUB.sub_receiver = p_no_id
			for update of S
	loop
		perform enableSubscription (v_sub_row.sub_set,
				v_sub_row.sub_provider, p_no_id);
	end loop;

	return p_no_id;
end;