関数特性
言語: PLPGSQL
戻り値: bigint
セットが一緒に併合されるように要求する MERGE_SET 事象の生成。 双方のセットが必ず存在し、同一のノードで発生しなければなりません。それらはノードの同一のセットにより購読される必要があります。declare
p_set_id alias for $1;
p_add_id alias for $2;
v_origin int4;
begin
-- ----
-- 中枢構成にロックの取得
-- ----
lock table sl_config_lock;
-- ----
-- 2 つのセットが存在し、ここで発生する事の検査
-- ----
if p_set_id = p_add_id then
raise exception 'Slony-I: merged set ids cannot be identical';
end if;
select set_origin into v_origin from sl_set
where set_id = p_set_id;
if not found then
raise exception 'Slony-I: set % not found', p_set_id;
end if;
if v_origin != getLocalNodeId('_schemadoc') then
raise exception 'Slony-I: set % does not originate on local node',
p_set_id;
end if;
select set_origin into v_origin from sl_set
where set_id = p_add_id;
if not found then
raise exception 'Slony-I: set % not found', p_add_id;
end if;
if v_origin != getLocalNodeId('_schemadoc') then
raise exception 'Slony-I: set % does not originate on local node',
p_add_id;
end if;
-- ----
-- 2 つのセットがノードの同じセットで購読される事の検査
-- ----
if exists (select true from sl_subscribe SUB1
where SUB1.sub_set = p_set_id
and SUB1.sub_receiver not in (select SUB2.sub_receiver
from sl_subscribe SUB2
where SUB2.sub_set = p_add_id))
then
raise exception 'Slony-I: subscriber lists of set % and % are different',
p_set_id, p_add_id;
end if;
if exists (select true from sl_subscribe SUB1
where SUB1.sub_set = p_add_id
and SUB1.sub_receiver not in (select SUB2.sub_receiver
from sl_subscribe SUB2
where SUB2.sub_set = p_set_id))
then
raise exception 'Slony-I: subscriber lists of set % and % are different',
p_add_id, p_set_id;
end if;
-- ----
-- SYNC の作成、セットの併合、MERGE_SET 事象の作成
-- ----
perform createEvent('_schemadoc', 'SYNC', NULL);
perform mergeSet_int(p_set_id, p_add_id);
return createEvent('_schemadoc', 'MERGE_SET',
p_set_id, p_add_id);
end;