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

# 8.134. unsubscribeset(p_force integer, p_sub_receiver integer, p_sub_set boolean)

Function Properties

Language: PLPGSQL

Return Type: bigint

unsubscribeSet (sub_set, sub_receiver,force) 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
    	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 p_force=false and 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;

    	if exists (select true from sl_subscribe
    			where sub_set = p_sub_set
    				and sub_provider = p_sub_receiver)
    	then
    		--delete the receivers of this provider.
    		--unsubscribeSet_int() will generate the event
    		--when it runs on the receiver.
    		delete from sl_subscribe
    			   where sub_set=p_sub_set
    			   and sub_provider=p_sub_receiver;
    	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;

Prev | Home | Next
unsubscribe_abandoned_sets(p_failed_node integer) | Up | unsubscribeset_int(p_sub_receiver integer, p_sub_set integer)