1.51. enablenode_int( integer )

関数特性

言語: PLPGSQL

戻り値: integer

no_id - ノード識別子番号 ノード no_id に対し ENABLE_NODE 事象を処理する内部関数

declare
	p_no_id			alias for $1;
	v_local_node_id		int4;
	v_node_row		record;
	v_sub_row		record;
begin
	-- ----
	-- 中枢構成にロックを取得
	-- ----
	lock table sl_config_lock;

	-- ----
	-- ノードが活動していない事の検査
	-- ----
	select * into v_node_row
			from sl_node
			where no_id = p_no_id
			for update;
	if not found then 
		raise exception 'Slony-I: node % not found', p_no_id;
	end if;
	if v_node_row.no_active then
		return p_no_id;
	end if;

	-- ----
	-- ノードを活性化し、それ用に sl_confirm ステータス行を生成
	-- ----
	update sl_node
			set no_active = 't'
			where no_id = p_no_id;
	insert into sl_confirm
			(con_origin, con_received, con_seqno)
			select no_id, p_no_id, 0 from sl_node
				where no_id != p_no_id
				and no_active;
	insert into sl_confirm
			(con_origin, con_received, con_seqno)
			select p_no_id, no_id, 0 from sl_node
				where no_id != p_no_id
				and no_active;

	-- ----
	-- ここに発生し、そしてちょうど今動作したノードで購読された
	-- 全てのセットに対し ENABLE_SUBSCRIPTION 事象を生成
	-- ----
	v_local_node_id := getLocalNodeId('_schemadoc');
	for v_sub_row in select SUB.sub_set, SUB.sub_provider from
			sl_set S,
			sl_subscribe SUB
			where S.set_origin = v_local_node_id
			and S.set_id = SUB.sub_set
			and SUB.sub_receiver = p_no_id
			for update of S
	loop
		perform enableSubscription (v_sub_row.sub_set,
				v_sub_row.sub_provider, p_no_id);
	end loop;

	return p_no_id;
end;