Christopher B. Browne's Home Page
cbbrowne@acm.org

8.128. unsubscribeset(integer, integer)

Function Properties

PLPGSQLbigint
unsubscribeSet (sub_set, sub_receiver) Unsubscribe node sub_receiver from subscription set sub_set. This is invoked on the receiver node. It verifies that this does not break any chains (e.g. - where sub_receiver is a provider for another node), then restores tables, drops Slony-specific keys, drops table entries for the set, drops the subscription, and generates an UNSUBSCRIBE_SET node to publish that the node is being dropped.
    declare
    	p_sub_set			alias for $1;
    	p_sub_receiver		alias for $2;
    	v_tab_row			record;
    begin
    	-- ----
    	-- Grab the central configuration lock
    	-- ----
    	lock table sl_config_lock;
    
    	-- ----
    	-- Check that this is called on the receiver node
    	-- ----
    	if p_sub_receiver != getLocalNodeId('_schemadoc') then
    		raise exception 'Slony-I: unsubscribeSet() must be called on receiver';
    	end if;
    
    	-- ----
    	-- Check that this does not break any chains
    	-- ----
    	if exists (select true from sl_subscribe
    			where sub_set = p_sub_set
    				and sub_provider = p_sub_receiver)
    	then
    		raise exception 'Slony-I: Cannot unsubscribe set % while being provider',
    				p_sub_set;
    	end if;
    
    	-- ----
    	-- Remove the replication triggers.
    	-- ----
    	for v_tab_row in select tab_id from sl_table
    			where tab_set = p_sub_set
    			order by tab_id
    	loop
    		perform alterTableDropTriggers(v_tab_row.tab_id);
    	end loop;
    
    	-- ----
    	-- Remove the setsync status. This will also cause the
    	-- worker thread to ignore the set and stop replicating
    	-- right now.
    	-- ----
    	delete from sl_setsync
    			where ssy_setid = p_sub_set;
    
    	-- ----
    	-- Remove all sl_table and sl_sequence entries for this set.
    	-- Should we ever subscribe again, the initial data
    	-- copy process will create new ones.
    	-- ----
    	delete from sl_table
    			where tab_set = p_sub_set;
    	delete from sl_sequence
    			where seq_set = p_sub_set;
    
    	-- ----
    	-- Call the internal procedure to drop the subscription
    	-- ----
    	perform unsubscribeSet_int(p_sub_set, p_sub_receiver);
    
    	-- Rewrite sl_listen table
    	perform RebuildListenEntries();
    
    	-- ----
    	-- Create the UNSUBSCRIBE_SET event
    	-- ----
    	return  createEvent('_schemadoc', 'UNSUBSCRIBE_SET', 
    			p_sub_set::text, p_sub_receiver::text);
    end;

Google
Contact me at cbbrowne@acm.org