1.68. moveset( integer, integer )

関数特性

言語: PLPGSQL

戻り値: bigint

moveSet(set_id, new_origin) セット set_id に対するオリジンがノード new_origin に移動させられるように要求する MOVE_SET 事象の生成。

declare
	p_set_id			alias for $1;
	p_new_origin			alias for $2;
	v_local_node_id			int4;
	v_set_row			record;
	v_sub_row			record;
	v_sync_seqno			int8;
	v_lv_row			record;
begin
	-- ----
	-- 中枢構成にロックの取得
	-- ----
	lock table sl_config_lock;

	-- ----
	-- セットにロックが掛けられ、このロックはかなり以前に
	-- 掛けられたかの検査
	-- ----
	v_local_node_id := getLocalNodeId('_schemadoc');
	select * into v_set_row from sl_set
			where set_id = p_set_id
			for update;
	if not found then
		raise exception 'Slony-I: set % not found', p_set_id;
	end if;
	if v_set_row.set_origin <> v_local_node_id then
		raise exception 'Slony-I: set % does not originate on local node',
				p_set_id;
	end if;
	if v_set_row.set_locked isnull then
		raise exception 'Slony-I: set % is not locked', p_set_id;
	end if;
	if v_set_row.set_locked > getMinXid() then
		raise exception 'Slony-I: cannot move set % yet, transactions < % are still in progress',
				p_set_id, v_set_row.set_locked;
	end if;

	-- ----
	-- セットのロックの解除
	-- ----
	perform unlockSet(p_set_id);

	-- ----
	-- new_origin はセットの有効な購読ノードかの検査
	-- ----
	select * into v_sub_row from sl_subscribe
			where sub_set = p_set_id
			and sub_receiver = p_new_origin;
	if not found then
		raise exception 'Slony-I: set % is not subscribed by node %',
				p_set_id, p_new_origin;
	end if;
	if not v_sub_row.sub_active then
		raise exception 'Slony-I: subsctiption of node % for set % is inactive',
				p_new_origin, p_set_id;
	end if;

	-- ----
	-- 全ての再構成
	-- ----
	perform moveSet_int(p_set_id, v_local_node_id,
			p_new_origin);

	perform RebuildListenEntries();

	-- ----
	-- この時点でセット内の全てのテーブルにアクセス排他ロックを保留します。
	-- しかし、セットを新規オリジンノードに移動し、よって
	-- 行っている createEvent() はシーケンスを記録しません。
	-- ----
	v_sync_seqno := createEvent('_schemadoc', 'SYNC');
	insert into sl_seqlog 
			(seql_seqid, seql_origin, seql_ev_seqno, seql_last_value)
			select seq_id, v_local_node_id, v_sync_seqno, seq_last_value
			from sl_seqlastvalue
			where seq_set = p_set_id;
					
	-- ----
	-- 最終的に実際の事象を生成します。
	-- ----
	return createEvent('_schemadoc', 'MOVE_SET', 
			p_set_id, v_local_node_id, p_new_origin);
end;