1.130.  unsubscribeset( integer, integer )

Propriétés de la fonction
Langage: PLPGSQL
Type du code retour: bigint

Désabonne le nœud sub_receiver de l'ensemble sub_set. Cette fonction est appelée sur le nœud abonné. Elle vérifie que cela ne casse pas les chaînes (c'est-à-dire où sub_receiver est un fournisseur pour d'autres nœuds), puis restaure les tables, supprime les clés spécifiques de Slony, supprime les entrées de table pour l'ensemble, supprime l'abonnement et génère un événement UNSUBSCRIBE_SET pour publier la suppression du nœud.

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;

        -- ----
        -- Restore all tables original triggers and rules and remove
        -- our replication stuff.
        -- ----
        for v_tab_row in select tab_id from sl_table
                        where tab_set = p_sub_set
                        order by tab_id
        loop
                perform alterTableRestore(v_tab_row.tab_id);
                perform tableDropKey(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, p_sub_receiver);
end;