setdroptable_int(p_tab_id integer)

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

# 8.105. setdroptable_int(p_tab_id integer)

Function Properties

Language: PLPGSQL

Return Type: integer

setDropTable_int (tab_id) This function processes the SET_DROP_TABLE event on remote nodes, dropping a table from replication if the remote node is subscribing to its replication set.

    declare
    	v_set_id		int4;
    	v_local_node_id		int4;
    	v_set_origin		int4;
    	v_sub_provider		int4;
    	v_tab_reloid		oid;
    begin
    	-- ----
    	-- Grab the central configuration lock
    	-- ----
    	lock table sl_config_lock;

        -- ----
    	-- Determine the set_id
        -- ----
    	select tab_set into v_set_id from sl_table where tab_id = p_tab_id;

    	-- ----
    	-- Ensure table exists
    	-- ----
    	if not found then
    		return 0;
    	end if;

    	-- ----
    	-- For sets with a remote origin, check that we are subscribed
    	-- to that set. Otherwise we ignore the table because it might
    	-- not even exist in our database.
    	-- ----
    	v_local_node_id := getLocalNodeId('_schemadoc');
    	select set_origin into v_set_origin
    			from sl_set
    			where set_id = v_set_id;
    	if not found then
    		raise exception 'Slony-I: setDropTable_int(): set % not found',
    				v_set_id;
    	end if;
    	if v_set_origin != v_local_node_id then
    		select sub_provider into v_sub_provider
    				from sl_subscribe
    				where sub_set = v_set_id
    				and sub_receiver = getLocalNodeId('_schemadoc');
    		if not found then
    			return 0;
    		end if;
    	end if;

    	-- ----
    	-- Drop the table from sl_table and drop trigger from it.
    	-- ----
    	perform alterTableDropTriggers(p_tab_id);
    	delete from sl_table where tab_id = p_tab_id;
    	return p_tab_id;
    end;

Prev | Home | Next
setdroptable(p_tab_id integer) | Up | setmovesequence(p_new_set_id integer, p_seq_id integer)