1.63.  enablesubscription_int( integer, integer, integer )

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

Fonction interne pour activer l'abonnement du nœud sub_receiver pour configurer sub_set via le nœud sub_provider. slon fait une grosse partie du travail ; tout ce que nous avons besoin de faire ici est de nous rappeler que cela est survenu. La fonction met à jour sl_subscribe, indiquant que l'abonnement est devenu actif.

declare
        p_sub_set                       alias for $1;
        p_sub_provider          alias for $2;
        p_sub_receiver          alias for $3;
        v_n                                     int4;
begin
        -- ----
        -- Grab the central configuration lock
        -- ----
        lock table sl_config_lock;

        -- ----
        -- The real work is done in the replication engine. All
        -- we have to do here is remembering that it happened.
        -- ----

        -- ----
        -- Well, not only ... we might be missing an important event here
        -- ----
        if not exists (select true from sl_path
                        where pa_server = p_sub_provider
                        and pa_client = p_sub_receiver)
        then
                insert into sl_path
                                (pa_server, pa_client, pa_conninfo, pa_connretry)
                                values 
                                (p_sub_provider, p_sub_receiver, 
                                '<event pending>', 10);
        end if;

        update sl_subscribe
                        set sub_active = 't'
                        where sub_set = p_sub_set
                        and sub_receiver = p_sub_receiver;
        get diagnostics v_n = row_count;
        if v_n = 0 then
                insert into sl_subscribe
                                (sub_set, sub_provider, sub_receiver,
                                sub_forward, sub_active)
                                values
                                (p_sub_set, p_sub_provider, p_sub_receiver,
                                false, true);
        end if;

        -- Rewrite sl_listen table
        perform RebuildListenEntries();

        return p_sub_set;
end;