setmovesequence(integer, integer)

Slony-I 2.0.4 Documentation
Prev | Fast Backward | Chapter 1. Schema schemadoc | Fast Forward | Next

# 1.103. setmovesequence(integer, integer)

Function Properties

Language: PLPGSQL

Return Type: bigint

setMoveSequence(p_seq_id, p_new_set_id) - This generates the SET_MOVE_SEQUENCE event, after validation, notably that both sets exist, are distinct, and have exactly the same subscription lists

    declare
    	p_seq_id			alias for $1;
    	p_new_set_id		alias for $2;
    	v_old_set_id		int4;
    	v_origin			int4;
    begin
    	-- ----
    	-- Grab the central configuration lock
    	-- ----
    	lock table sl_config_lock;

    	-- ----
    	-- Get the sequences current set
    	-- ----
    	select seq_set into v_old_set_id from sl_sequence
    			where seq_id = p_seq_id;
    	if not found then
    		raise exception 'Slony-I: setMoveSequence(): sequence %d not found', p_seq_id;
    	end if;

    	-- ----
    	-- Check that both sets exist and originate here
    	-- ----
    	if p_new_set_id = v_old_set_id then
    		raise exception 'Slony-I: setMoveSequence(): set ids cannot be identical';
    	end if;
    	select set_origin into v_origin from sl_set
    			where set_id = p_new_set_id;
    	if not found then
    		raise exception 'Slony-I: setMoveSequence(): set % not found', p_new_set_id;
    	end if;
    	if v_origin != getLocalNodeId('_schemadoc') then
    		raise exception 'Slony-I: setMoveSequence(): set % does not originate on local node',
    				p_new_set_id;
    	end if;

    	select set_origin into v_origin from sl_set
    			where set_id = v_old_set_id;
    	if not found then
    		raise exception 'Slony-I: set % not found', v_old_set_id;
    	end if;
    	if v_origin != getLocalNodeId('_schemadoc') then
    		raise exception 'Slony-I: set % does not originate on local node',
    				v_old_set_id;
    	end if;

    	-- ----
    	-- Check that both sets are subscribed by the same set of nodes
    	-- ----
    	if exists (select true from sl_subscribe SUB1
    				where SUB1.sub_set = p_new_set_id
    				and SUB1.sub_receiver not in (select SUB2.sub_receiver
    						from sl_subscribe SUB2
    						where SUB2.sub_set = v_old_set_id))
    	then
    		raise exception 'Slony-I: subscriber lists of set % and % are different',
    				p_new_set_id, v_old_set_id;
    	end if;

    	if exists (select true from sl_subscribe SUB1
    				where SUB1.sub_set = v_old_set_id
    				and SUB1.sub_receiver not in (select SUB2.sub_receiver
    						from sl_subscribe SUB2
    						where SUB2.sub_set = p_new_set_id))
    	then
    		raise exception 'Slony-I: subscriber lists of set % and % are different',
    				v_old_set_id, p_new_set_id;
    	end if;

    	-- ----
    	-- Change the set the sequence belongs to
    	-- ----
    	perform setMoveSequence_int(p_seq_id, p_new_set_id);
    	return  createEvent('_schemadoc', 'SET_MOVE_SEQUENCE',
    			p_seq_id::text, p_new_set_id::text);
    end;

Prev | Home | Next
setdroptable_int(integer) | Up | setmovesequence_int(integer, integer)