Wed Nov 10 18:16:00 PST 2004
- Previous message: [Slony1-commit] By cbbrowne: Add comments
- Next message: [Slony1-commit] By cbbrowne: Add in some notes on implementation strategy, as well as
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Log Message:
-----------
Add in "draft" version of RebuildListenEntries() that generates
sl_listen entries automatically whenever sl_path and sl_subscribe
change
Modified Files:
--------------
slony1-engine/src/backend:
slony1_funcs.sql (r1.35 -> r1.36)
-------------- next part --------------
Index: slony1_funcs.sql
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.sql,v
retrieving revision 1.35
retrieving revision 1.36
diff -Lsrc/backend/slony1_funcs.sql -Lsrc/backend/slony1_funcs.sql -u -w -r1.35 -r1.36
--- src/backend/slony1_funcs.sql
+++ src/backend/slony1_funcs.sql
@@ -705,6 +705,9 @@
set no_active = false
where no_id = p_no_id;
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
return p_no_id;
end;
' language plpgsql;
@@ -798,6 +801,9 @@
perform @NAMESPACE at .terminateNodeConnections(
''_ at CLUSTERNAME@_Node_'' || p_failed_node);
+-- Note that the following code should all become obsolete in the wake
+-- of the availability of RebuildListenEntries()...
+
-- ----
-- Let every node that listens for something on the failed node
-- listen for that on the backup node instead.
@@ -910,6 +916,9 @@
end if;
end loop;
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
-- ----
-- Make sure the node daemon will restart
-- ----
@@ -1042,6 +1051,9 @@
where set_id = p_set_id;
end if;
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
-- ----
-- If we are a subscriber of the set ourself, change our
-- setsync status to reflect the new set origin.
@@ -1206,6 +1218,9 @@
(p_pa_server, p_pa_client, p_pa_conninfo, p_pa_connretry);
end if;
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
return 0;
end;
' language plpgsql;
@@ -1263,6 +1278,10 @@
-- Now drop the path and create the event
-- ----
perform @NAMESPACE at .dropPath_int(p_pa_server, p_pa_client);
+
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
return @NAMESPACE at .createEvent (''_ at CLUSTERNAME@'', ''DROP_PATH'',
p_pa_server, p_pa_client);
end;
@@ -1302,8 +1321,14 @@
and pa_client = p_pa_client;
if found then
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
return 1;
else
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
return 0;
end if;
end;
@@ -1938,6 +1963,9 @@
where sub_set = p_set_id
and sub_receiver = p_new_origin;
+ -- Regenerate sl_listen since we revised the subscriptions
+ perform @NAMESPACE at .RebuildListenEntries();
+
-- ----
-- If we are the new or old origin, we have to
-- put all the tables into altered state again.
@@ -2044,6 +2072,9 @@
delete from @NAMESPACE at .sl_set
where set_id = p_set_id;
+ -- Regenerate sl_listen since we revised the subscriptions
+ perform @NAMESPACE at .RebuildListenEntries();
+
return p_set_id;
end;
' language plpgsql;
@@ -3710,6 +3741,9 @@
p_sub_provider, p_sub_receiver);
end if;
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
return p_sub_set;
end;
' language plpgsql;
@@ -3789,6 +3823,9 @@
-- ----
perform @NAMESPACE at .unsubscribeSet_int(p_sub_set, p_sub_receiver);
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
-- ----
-- Create the UNSUBSCRIBE_SET event
-- ----
@@ -3829,6 +3866,9 @@
where sub_set = p_sub_set
and sub_receiver = p_sub_receiver;
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
return p_sub_set;
end;
' language plpgsql;
@@ -3897,6 +3937,9 @@
false, true);
end if;
+ -- Rewrite sl_listen table
+ perform @NAMESPACE at .RebuildListenEntries();
+
return p_sub_set;
end;
' language plpgsql;
@@ -4436,6 +4479,63 @@
the creation of the serial column. The return an attkind according to
that.';
+
+-- ----------------------------------------------------------------------
+-- FUNCTION RebuildListenEntries (provider, receiver)
+--
+-- Revises sl_listen rules based on contents of sl_path and
+-- sl_subscribe
+-- ----------------------------------------------------------------------
+create or replace function @NAMESPACE at .RebuildListenEntries()
+returns int
+as '
+declare
+ v_row record;
+ v_row2 record;
+ v_row3 record;
+ v_origin int4;
+ v_receiver int4;
+ v_done boolean;
+
+begin
+ -- 0. Drop out listens
+ delete from @NAMESPACE at .sl_listen;
+
+ -- 1. Add listens pointed out by subscriptions - sl_listen
+ select @NAMESPACE at .storelisten(sub_provider, sub_provider, sub_receiver)
+ from @NAMESPACE at .sl_subscribe;
+
+ -- 2. Add direct listens pointed out in sl_path
+ select @NAMESPACE at .storelisten(pa_server, pa_server, pa_client)
+ from @NAMESPACE at .sl_path path
+ where not exists (select true from @NAMESPACE at .sl_listen listen
+ where path.pa_server = listen.li_origin and
+ path.pa_client = listen.li_reciever);
+
+ -- 3. Iterate 'til we can't iterate no more...
+ -- Add in indirect listens based on what's in sl_listen and sl_path
+ v_done := ''f'';
+ while not v_done loop
+ select @NAMESPACE at .storelisten(li_origin,pa_server,pa_client)
+ from @NAMESPACE at .sl_path path, @NAMESPACE at .sl_listen listen
+ where
+ li_reciever = pa_server
+ and not exists (select true from @NAMESPACE at .sl_listen listen2
+ where listen2.li_origin = listen.origin and
+ listen2.li_reciever = path.pa_client);
+
+
+ end loop;
+end;
+' language plpgsql;
+
+comment on function @NAMESPACE at .RebuildListenEntries() is
+'RebuildListenEntries(p_provider, p_receiver)
+
+Invoked by various subscription and path modifying functions, this
+rewrites the sl_listen entries, adding in all the ones required to
+allow communications between nodes in the Slony-I cluster.';
+
-- ----------------------------------------------------------------------
-- FUNCTION tableHasSerialKey (tab_fqname)
--
- Previous message: [Slony1-commit] By cbbrowne: Add comments
- Next message: [Slony1-commit] By cbbrowne: Add in some notes on implementation strategy, as well as
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Slony1-commit mailing list