1.114. updatereloid( integer, integer )

関数特性

言語: PLPGSQL

戻り値: integer

updateReloid(set_id, only_on_node) それぞれの完全修飾名(FQN)に基づいた sl_table と sl_seqeunce におけるそれぞれのテーブル識別子(reloid)を更新します。

declare
        p_set_id                alias for $1;
        p_only_on_node          alias for $2;
        v_no_id                 int4;
        v_set_origin            int4;
begin
        -- ----
        -- 中枢構成のロックを取得
        -- ----
        lock table sl_config_lock;

        -- ----
        -- 私たちがセットオリジンか、もしくは現在のセットの
        -- 購読ノードかの検査
        -- ----
        v_no_id := getLocalNodeId('_schemadoc');
        select set_origin into v_set_origin
                        from sl_set
                        where set_id = p_set_id
                        for update;
        if not found then
                raise exception 'Slony-I: set % not found', p_set_id;
        end if;
        if v_set_origin <> v_no_id
                and not exists (select 1 from sl_subscribe
                        where sub_set = p_set_id
                        and sub_receiver = v_no_id)
        then
                return 0;
        end if;

        -- ----
        -- たった 1 つのノード上での実行が要求されれば
        -- 私たちがそのノードであるかを検査
        -- ----
        if p_only_on_node > 0 and p_only_on_node <> v_no_id then
                return 0;
        end if;
        update sl_table set
                tab_reloid = PGC.oid
                from pg_catalog.pg_class PGC, pg_catalog.pg_namespace PGN
                where slon_quote_brute(sl_table.tab_relname) = slon_quote_brute(PGC.relname)
                        and PGC.relnamespace = PGN.oid
			and slon_quote_brute(PGN.nspname) = slon_quote_brute(sl_table.tab_nspname);

        update sl_sequence set
                seq_reloid = PGC.oid
                from pg_catalog.pg_class PGC, pg_catalog.pg_namespace PGN
                where slon_quote_brute(sl_sequence.seq_relname) = slon_quote_brute(PGC.relname)
                	and PGC.relnamespace = PGN.oid
			and slon_quote_brute(PGN.nspname) = slon_quote_brute(sl_sequence.seq_nspname);

        return  createEvent('_schemadoc', 'RESET_CONFIG',
                        p_set_id, p_only_on_node);
end;