1.82. rebuildlistenentries( )

Function Properties

Language: PLPGSQL

Return Type: integer

RebuildListenEntries() Invoked by various subscription and path modifying functions, this rewrites the sl_listen entries, adding in all the ones required to allow communications between nodes in the Slony-I cluster.

declare
	v_receiver record ;
	v_provider record ;
	v_origin record ;
	v_reachable int4[] ;
begin
	-- First remove the entire configuration
	delete from sl_listen;

	-- Loop over every possible pair of receiver and provider
	for v_receiver in select no_id from sl_node loop
		for v_provider in select pa_server as no_id from sl_path where pa_client = v_receiver.no_id loop

			-- Find all nodes that v_provider.no_id can receiver events from without using v_receiver.no_id			
			for v_origin in select * from ReachableFromNode(v_provider.no_id, array[v_receiver.no_id]) as r(no_id) loop

				-- If v_receiver.no_id subscribes a set from v_provider.no_id, events have to travel the same
				-- path as the data. Ignore possible sl_listen that would break that rule.
				perform 1 from sl_subscribe
					join sl_set on sl_set.set_id = sl_subscribe.sub_set
		 			where
						sub_receiver = v_receiver.no_id and
						sub_provider != v_provider.no_id and
						set_origin = v_origin.no_id ;
				if not found then
					insert into sl_listen (li_receiver, li_provider, li_origin)
						values (v_receiver.no_id, v_provider.no_id, v_origin.no_id) ;
				end if ;


			end loop ;

		end loop ;
	end loop ;

	return null ;
end ;