Bug 220 - parameters to reshape subscription are passed in the wrong order
Summary: parameters to reshape subscription are passed in the wrong order
Status: RESOLVED FIXED
Alias: None
Product: Slony-I
Classification: Unclassified
Component: slonik (show other bugs)
Version: 2.0
Hardware: PC Linux
: low enhancement
Assignee: Steve Singer
URL:
Depends on:
Blocks:
 
Reported: 2011-06-09 06:20 UTC by Steve Singer
Modified: 2011-06-10 05:14 UTC (History)
1 user (show)

See Also:


Attachments
proposed fix (952 bytes, patch)
2011-06-09 06:24 UTC, Steve Singer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Singer 2011-06-09 06:20:07 UTC
Bug report from Glyn Still
--
Hi Guys,

Just had an issue with subscribe set in 2.0.6.  From what I can see somehow slonik is passing parameters 
to reshapesubscription in the wrong order, instead of (sub_set, sub_provider, sub_receiver) it seems to be 
sending (sub_provider, sub_set, sub_receiver).  In turn that made slonik hang on me and borked my subscriptions. 

Here's what I submitted to slonik:

    SUBSCRIBE SET ( ID = 1000, PROVIDER = 4, RECEIVER = 5, FORWARD = YES );

Here's the error message I get from slonik:

    Way5b:/pgsql/slony# slonik reshape.scr
    reshape.scr:17: ATTEMPT:  SUBSCRIBE SET
    reshape.scr:18: NOTICE:  subscribe set: omit_copy=f
    reshape.scr:18: NOTICE:  subscribe set: omit_copy=f
    CONTEXT:  SQL statement "SELECT  "_main_replication".subscribeSet_int( $1 ,  $2 ,  $3 ,  $4 ,  $5 )"
    PL/pgSQL function "subscribeset" line 77 at PERFORM
    reshape.scr:18: PGRES_FATAL_ERROR select "_main_replication".reshapeSubscription(4,1000,5); - ERROR:  insert or update on table "sl_subscribe" violates foreign key constraint "sl_subscribe-sl_path-ref"
    DETAIL:  Key (sub_provider,sub_receiver)=(1000,5) is not present in table "sl_path".
    CONTEXT:  SQL statement "update "_main_replication".sl_subscribe set sub_provider= $1  WHERE sub_set= $2  AND sub_receiver= $3 "
    PL/pgSQL function "reshapesubscription" line 11 at SQL statement
    error reshaping subscriber

And here's what my reshapesubscription looks like:

    CREATE OR REPLACE FUNCTION _main_replication.reshapesubscription(integer, integer, integer)
      RETURNS integer AS
    $BODY$
    declare
        p_sub_set            alias for $1;
        p_sub_provider        alias for $2;
        p_sub_receiver        alias for $3;
    begin
        -- ----
        -- Grab the central configuration lock
        -- ----
        lock table "_main_replication".sl_config_lock;
    
        update "_main_replication".sl_subscribe set sub_provider=p_sub_provider
               WHERE sub_set=p_sub_set AND sub_receiver=p_sub_receiver;
        if found then
           perform "_main_replication".RebuildListenEntries();
           notify "_main_replication_Restart";
        end if;
        return 0;
    end
    $BODY$
    LANGUAGE plpgsql VOLATILE;

Looking in the slonik.c starting on on line 3541 I can see the following:

                slon_mkquery(&query,
                                         "select \"_%s\".reshapeSubscription(%d,%d,%d);",
                                         stmt->hdr.script->clustername,
                                         stmt->sub_provider,stmt->sub_setid,
                                         stmt->sub_receiver);

Unless I'm going crazy (It is now 4am), that pretty much looks the wrong way around to me?

Thanks
Glyn
Comment 1 Steve Singer 2011-06-09 06:24:25 UTC
Created attachment 106 [details]
proposed fix

Proposed fix.
Will need to be applied against both master and REL_2_0_STABLE
Comment 2 Christopher Browne 2011-06-09 08:27:55 UTC
+1 from me