CVS User Account cvsuser
Fri Nov 19 23:47:18 PST 2004
Log Message:
-----------
Comments for sl_setsync, revisions to generate_sync_event(), new table maintenance function, add_missing_table_field(), textual and comment changes

Modified Files:
--------------
    slony1-engine/src/backend:
        slony1_base.sql (r1.22 -> r1.23)
        slony1_funcs.c (r1.26 -> r1.27)
        slony1_funcs.sql (r1.42 -> r1.43)

-------------- next part --------------
Index: slony1_base.sql
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_base.sql,v
retrieving revision 1.22
retrieving revision 1.23
diff -Lsrc/backend/slony1_base.sql -Lsrc/backend/slony1_base.sql -u -w -r1.22 -r1.23
--- src/backend/slony1_base.sql
+++ src/backend/slony1_base.sql
@@ -76,15 +76,14 @@
 		FOREIGN KEY (ssy_origin)
 		REFERENCES @NAMESPACE at .sl_node (no_id)
 );
-comment on table @NAMESPACE at .sl_setsync is 'Not documented yet';
-
+comment on table  @NAMESPACE at .sl_setsync is 'SYNC information';
 comment on column @NAMESPACE at .sl_setsync.ssy_setid is 'ID number of the replication set';
 comment on column @NAMESPACE at .sl_setsync.ssy_origin is 'ID number of the node';
 comment on column @NAMESPACE at .sl_setsync.ssy_seqno is 'Slony-I sequence number';
 comment on column @NAMESPACE at .sl_setsync.ssy_minxid is 'Earliest XID in provider system affected by SYNC';
 comment on column @NAMESPACE at .sl_setsync.ssy_maxxid is 'Latest XID in provider system affected by SYNC';
-comment on column @NAMESPACE at .sl_setsync.ssy_xip is 'Contains the list of XIDs in the SYNC in the order they should be applied';
-comment on column @NAMESPACE at .sl_setsync.ssy_action_list is 'The only time this field is used is during the subscription process. At the time a subscriber copies over data from the origin (not from another subscriber), it actually sees all tables in a state somewhere between two SYNC events. Therefore this list contains all action sequences that are visible, and therefore their operation already included in the data copied, at the time the initial data copy is done, so that those actions can be filtered out during the first SYNC after subscribing. ';
+comment on column @NAMESPACE at .sl_setsync.ssy_xip is 'Contains the list of XIDs in progress at SYNC time';
+comment on column @NAMESPACE at .sl_setsync.ssy_action_list is 'action list used during the subscription process. At the time a subscriber copies over data from the origin, it sees all tables in a state somewhere between two SYNC events. Therefore this list must contains all XIDs that are visible at that time, whose operations have therefore already been included in the data copied at the time the initial data copy is done.  Those actions may therefore be filtered out of the first SYNC done after subscribing.';
 
 
 -- ----------------------------------------------------------------------
Index: slony1_funcs.sql
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.sql,v
retrieving revision 1.42
retrieving revision 1.43
diff -Lsrc/backend/slony1_funcs.sql -Lsrc/backend/slony1_funcs.sql -u -w -r1.42 -r1.43
--- src/backend/slony1_funcs.sql
+++ src/backend/slony1_funcs.sql
@@ -4646,26 +4646,28 @@
 
 
 -- ----------------------------------------------------------------------
--- FUNCTION generate_sync_event ()
+-- FUNCTION generate_sync_event (interval)
 --
---	This code will be run from inside the logtrigger() function,
---      and will create SYNC events every once in a while...
+--	This code can be used to create SYNC events every once in a while
+--      even if the 'master' slon daemon is down
 -- ----------------------------------------------------------------------
-create or replace function @NAMESPACE at .generate_sync_event()
+create or replace function @NAMESPACE at .generate_sync_event(interval)
 returns int4
 as '
 declare
-	v_leventtime		timestamptz;
+	p_interval     alias for $1;
+	v_node_row     record;
 
 BEGIN
-	-- When was the last SYNC on this node?
-        select ev_timestamp into v_leventtime from @NAMESPACE at .sl_event 
-          where ev_type = ''SYNC'' and ev_origin = @NAMESPACE at .getLocalNodeId()
-          order by ev_origin, ev_seqno desc limit 1;
-
-	-- If there has been no SYNC in the last 30 seconds, then push one
-	if ev_timestamp + ''30 s''::interval < now() then
-		select @NAMESPACE at .createEvent(''@NAMESPACE@'', ''SYNC'', NULL);
+	select 1 into v_node_row from @NAMESPACE at .sl_event 
+       	  where ev_type = ''SYNC'' and ev_origin = @NAMESPACE at .getLocalNodeId(''@NAMESPACE@'')
+          and ev_timestamp > now() - p_interval limit 1;
+	if not found then
+		-- If there has been no SYNC in the last interval, then push one
+		perform @NAMESPACE at .createEvent(''@NAMESPACE@'', ''SYNC'', NULL);
+		return 1;
+	else
+		return 0;
 	end if;
 END' language plpgsql;
 
@@ -4710,22 +4712,43 @@
 DECLARE
 	v_row  record;
 BEGIN
-   select 1 into v_row 
-     from pg_namespace n, pg_class c, pg_attribute a
-     where
-        n.nspname = ''@NAMESPACE@'' and
-        c.relnamespace = n.oid and
-        c.relname = ''sl_node'' and
-        a.attrelid = c.oid and
-        a.attname = ''no_spool'';
-   if not found then
-	raise notice ''Upgrade sl_node - add field no_spool'';
+   if add_missing_table_field(@NAMESPACE@, ''sl_node'', ''no_spool'', ''boolean'') then
 	alter table @NAMESPACE at .sl_node
-            add column no_spool boolean default ''f'';
+            alter column no_spool set default = ''f'';
         update @NAMESPACE at .sl_node set no_spool = ''f'';
         return ''t'';
    end if;
+   return ''t'';
+END;' language plpgsql;
+
+comment on function @NAMESPACE at .upgrade_sl_node() is
+  'Schema changes required to upgrade to version 1.1';
+
+create or replace function @NAMESPACE at .add_missing_table_field (text, text, text, text) 
+returns bool as '
+DECLARE
+  p_namespace alias for $1;
+  p_table     alias for $2;
+  p_field     alias for $3;
+  p_type      alias for $4;
+  v_row       record;
+  v_query     text;
+BEGIN
+  select 1 into v_row from pg_namespace n, pg_class c, pg_attribute a
+   where n.nspname = p_namespace and
+         c.relname = n.oid and
+         c.relname = p_table and
+         a.attrelid = c.oid and
+         a.attname = p_field;
+  if not found then
+    raise notice ''Upgrade table %.% - add field %'', p_namespace, p_table, p_field;
+    v_query := ''alter table "'' || p_namespace || ''".'' || p_table || ' add column '';
+    v_query := v_query || p_field || '' type '' || p_type || '';'';
+    execute v_query;
+    return ''t'';
+  else
    return ''f'';
+  end if;
 END;' language plpgsql;
 
 -- ----------------------------------------------------------------------
Index: slony1_funcs.c
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -Lsrc/backend/slony1_funcs.c -Lsrc/backend/slony1_funcs.c -u -w -r1.26 -r1.27


More information about the Slony1-commit mailing list