1.84. setmovetable( integer, integer )

関数特性

言語: PLPGSQL

戻り値: bigint

SET_MOVE_TABLE 事象を処理します。テーブルは受信セットに移動されます。

declare
	p_tab_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 tab_set into v_old_set_id from sl_table
			where tab_id = p_tab_id;
	if not found then
		raise exception 'Slony-I: table %d not found', p_tab_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 createEvent('_schemadoc', 'SYNC', NULL);
	perform setMoveTable_int(p_tab_id, p_new_set_id);
	return  createEvent('_schemadoc', 'SET_MOVE_TABLE', 
			p_tab_id, p_new_set_id);
end;