declare
p_sub_set alias for $1;
p_sub_provider alias for $2;
p_sub_receiver alias for $3;
p_sub_forward alias for $4;
p_omit_copy alias for $5;
v_set_origin int4;
v_ev_seqno int8;
v_rec record;
begin
-- ----
-- Grab the central configuration lock
-- ----
lock table sl_config_lock;
raise notice 'subscribe set: omit_copy=%', p_omit_copy;
-- ----
-- Check that this is called on the provider node
-- ----
if p_sub_provider != getLocalNodeId('_schemadoc') then
raise exception 'Slony-I: subscribeSet() must be called on provider';
end if;
--
-- Check that the receiver exists
--
if not exists (select no_id from sl_node where no_id=
p_sub_receiver) then
raise exception 'Slony-I: subscribeSet() the receiver does not exist receiver id:%' , p_sub_receiver;
end if;
-- ----
-- Check that the origin and provider of the set are remote
-- ----
select set_origin into v_set_origin
from sl_set
where set_id = p_sub_set;
if not found then
raise exception 'Slony-I: subscribeSet(): set % not found', p_sub_set;
end if;
if v_set_origin = p_sub_receiver then
raise exception
'Slony-I: subscribeSet(): set origin and receiver cannot be identical';
end if;
if p_sub_receiver = p_sub_provider then
raise exception
'Slony-I: subscribeSet(): set provider and receiver cannot be identical';
end if;
-- ---
-- Verify that the provider is either the origin or an active subscriber
-- Bug report #1362
-- ---
if v_set_origin <> p_sub_provider then
if not exists (select 1 from sl_subscribe
where sub_set = p_sub_set and
sub_receiver = p_sub_provider and
sub_forward and sub_active) then
raise exception 'Slony-I: subscribeSet(): provider % is not an active forwarding node for replication set %', p_sub_provider, p_sub_set;
end if;
end if;
-- ----
-- Create the SUBSCRIBE_SET event
-- ----
v_ev_seqno := createEvent('_schemadoc', 'SUBSCRIBE_SET',
p_sub_set::text, p_sub_provider::text, p_sub_receiver::text,
case p_sub_forward when true then 't' else 'f' end,
case p_omit_copy when true then 't' else 'f' end
);
-- ----
-- Call the internal procedure to store the subscription
-- ----
perform subscribeSet_int(p_sub_set, p_sub_provider,
p_sub_receiver, p_sub_forward, p_omit_copy);
return v_ev_seqno;
end; |