Nuno Santos nuno.santos
Mon Jul 18 13:55:56 PDT 2005
Hello.

I'm still struggling to add a new table to a set dynamically. I think I
figured out how to do it, but I found a strange behaviour that I would
like to understand.

I'm creating a table using a stored procedure. This is a simplified
version of how it looks like:

CREATE OR REPLACE function _cluster.createTable (text, text) RETURNS
void as $$
declare
	p_table         	alias for $1;
	p_creation_script	alias for $2;
	v_row				record;	
begin
    perform _cluster.ddlscript(1, p_creation_script, 0);
    perform _cluster.storeset(2, 'Temporary set');
    perform _cluster.setaddtable(2, 42, p_table, p_table || '_pkey',
'new table');

    for v_row in
        select * from _cluster.sl_subscribe
		where sub_set=1
    loop
        perform _cluster.subscribeset(
            v_tmp_set_id,
            v_row.sub_provider,
            v_row.sub_receiver,
            v_row.sub_forward);
    end loop;

    perform _cluster.mergeset(1, 2);
    return;
end;

This fails with the same problem I mentioned before. As I was told that
I should wait for the events to propagate to other replicas before
calling mergeset, I tried to make a small pause inside the stored
procedure before calling mergeset. So something like:


    loop
        perform _cluster.subscribeset(
            v_tmp_set_id,
            v_row.sub_provider,
            v_row.sub_receiver,
            v_row.sub_forward);
    end loop;

    perform sleep(10);
    perform _cluster.mergeset(1, 2);
    return;
end;

sleep is another stored procedure that I created. This doesn't work
either, failing for the same reason as before.

I then tried to execute mergeset in a separate call and this time it worked.

This is good enough for my purposes, but I would like to know what's
going on. I would guess that the stored procedure is executed inside a
single transaction and that somehow the events are not propagated until
that transaction is closed. Am I right?

And another related question, how can I ensure atomicity between the two
calls (the first to create the new table and temporary set, the second
to merge the sets)? I want to make sure that the list of subscribers is
not changed between the two calls.

Thank you,
Nuno Santos



More information about the Slony1-general mailing list