1.82. setmovesequence( integer, integer )

関数特性

言語: PLPGSQL

戻り値: bigint

declare
	p_seq_id                alias for $1;
	p_new_set_id		alias for $2;
	v_old_set_id		int4;
	v_origin		int4;
begin
	-- ----
	-- 中枢構成にロックを取得
	-- ----
	lock table sl_config_lock;

	-- ----
	-- シーケンスの現在セットの獲得
	-- ----
	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: sequence %d not found', p_seq_id;
	end if;
	
	-- ----
	-- 双方のセットが存在し、ここで発生したかの検査
	-- ----
	if p_new_set_id = v_old_set_id then
		raise exception 'Slony-I: 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: set % not found', p_new_set_id;
	end if;
	if v_origin != getLocalNodeId('_schemadoc') then
		raise exception 'Slony-I: 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;

	-- ----
	-- 双方のセットがノードの同じセットにより購読されるのかの検査
	-- ----
	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;

	-- ----
	-- シーケンスが所属するセットの変更
	-- ----
	perform setMoveSequence_int(p_seq_id, p_new_set_id);
	return  createEvent('_schemadoc', 'SET_MOVE_SEQUENCE', 
			p_seq_id, p_new_set_id);
end;