declare
p_sub_set alias for $1;
p_sub_receiver alias for $2;
v_tab_row record;
begin
-- ----
-- Grab the central configuration lock
-- ----
lock table sl_config_lock;
-- ----
-- Check that this is called on the receiver node
-- ----
if p_sub_receiver != getLocalNodeId('_schemadoc') then
raise exception 'Slony-I: unsubscribeSet() must be called on receiver';
end if;
-- ----
-- Check that this does not break any chains
-- ----
if exists (select true from sl_subscribe
where sub_set = p_sub_set
and sub_provider = p_sub_receiver)
then
raise exception 'Slony-I: Cannot unsubscribe set % while being provider',
p_sub_set;
end if;
-- ----
-- Remove the replication triggers.
-- ----
for v_tab_row in select tab_id from sl_table
where tab_set = p_sub_set
order by tab_id
loop
perform alterTableDropTriggers(v_tab_row.tab_id);
end loop;
-- ----
-- Remove the setsync status. This will also cause the
-- worker thread to ignore the set and stop replicating
-- right now.
-- ----
delete from sl_setsync
where ssy_setid = p_sub_set;
-- ----
-- Remove all sl_table and sl_sequence entries for this set.
-- Should we ever subscribe again, the initial data
-- copy process will create new ones.
-- ----
delete from sl_table
where tab_set = p_sub_set;
delete from sl_sequence
where seq_set = p_sub_set;
-- ----
-- Call the internal procedure to drop the subscription
-- ----
perform unsubscribeSet_int(p_sub_set, p_sub_receiver);
-- Rewrite sl_listen table
perform RebuildListenEntries();
-- ----
-- Create the UNSUBSCRIBE_SET event
-- ----
return createEvent('_schemadoc', 'UNSUBSCRIBE_SET',
p_sub_set::text, p_sub_receiver::text);
end; |