Chris Browne cbbrowne at lists.slony.info
Wed Jun 27 08:51:38 PDT 2007
Update of /home/cvsd/slony1/slony1-engine/src/backend
In directory main.slony.info:/tmp/cvs-serv9117/src/backend

Modified Files:
	slony1_base.sql slony1_funcs.sql 
Log Message:
Major revision to cleanup thread:

- Use pair of SPs to calculate the list of tables to be vacuumed
- All logic for checking the list against autovac "lives" in SPs
- Result: significant simplification to C code in cleanup thread


Index: slony1_base.sql
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/backend/slony1_base.sql,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** slony1_base.sql	18 Apr 2007 15:03:51 -0000	1.33
--- slony1_base.sql	27 Jun 2007 15:51:35 -0000	1.34
***************
*** 563,566 ****
--- 563,570 ----
  ';
  
+ create type @NAMESPACE at .vactables as (nspname name, relname name);
+ 
+ comment on type @NAMESPACE at .vactables is 'used as return type for SRF function TablesToVacuum';
+ 
  -- ----------------------------------------------------------------------
  -- Last but not least grant USAGE to the replication schema objects.

Index: slony1_funcs.sql
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/backend/slony1_funcs.sql,v
retrieving revision 1.112
retrieving revision 1.113
diff -C2 -d -r1.112 -r1.113
*** slony1_funcs.sql	7 Jun 2007 22:40:23 -0000	1.112
--- slony1_funcs.sql	27 Jun 2007 15:51:35 -0000	1.113
***************
*** 1444,1455 ****
  	lock table @NAMESPACE at .sl_config_lock;
  
- 	-- ----
- 	-- This is us ... time for suicide! Restore all tables to
- 	-- their original status.
- 	-- ----
- 	for v_tab_row in select * from @NAMESPACE at .sl_table loop
- 		perform @NAMESPACE at .alterTableDropTriggers(v_tab_row.tab_id);
- 	end loop;
- 
  	raise notice ''Slony-I: Please drop schema "_ at CLUSTERNAME@"'';
  	return 0;
--- 1444,1447 ----
***************
*** 5440,5443 ****
--- 5432,5441 ----
  			perform @NAMESPACE at .alterTableConfigureTriggers(v_tab_row.tab_id);
  		end loop;
+ 
+ 		-- ----
+ 		-- create new type - vactables - used by TablesToVacuum()
+ 		-- ----
+ 		execute ''create type @NAMESPACE at .vactables as (nspname name, relname name);'';
+ 
  	end if;
  
***************
*** 5616,5619 ****
--- 5614,5622 ----
  'Reenable index maintenance and reindex the table';
  
+ -- ----------------------------------------------------------------------
+ -- FUNCTION make_function_strict(function, parms)
+ --
+ --	Make function be STRICT
+ -- ----------------------------------------------------------------------
  create or replace function @NAMESPACE at .make_function_strict (text, text) returns void as
  '
***************
*** 5631,5632 ****
--- 5634,5745 ----
  comment on function @NAMESPACE at .make_function_strict (text, text) is
  'Equivalent to 8.1+ ALTER FUNCTION ... STRICT';
+ 
+ 
+ 
+ -- ----------------------------------------------------------------------
+ -- FUNCTION AutoVacExcludesTable (nspname, tabname)
+ --
+ --	Returns 't' if the table needs to be vacuumed by Slony-I
+ --      Returns 'f' if autovac handles the table, so Slony-I should not
+ -- ----------------------------------------------------------------------
+ create or replace function @NAMESPACE at .AutoVacExcludesTable (name, name) returns boolean as
+ $$
+ declare
+ 	i_nspname alias for $1;
+ 	i_tblname alias for $2;
+ 	c_table oid;
+ 	c_namespace oid;
+ 	c_enabled boolean;
+ 	v_dummy int4;
+ begin
+ 	select 1 into v_dummy from "pg_catalog".pg_settings where name = 'autovacuum' and setting = 'on';
+ 	if not found then
+ 		return 't'::boolean;       -- If autovac is turned off, then we gotta vacuum
+ 	end if;
+ 	
+ 	select into c_namespace oid from "pg_catalog".pg_namespace where nspname = i_nspname;
+ 	if not found then
+ 		raise exception 'Slony-I: namespace % does not exist', i_nspname;
+ 	end if;
+ 	select into c_table oid from "pg_catalog".pg_class where relname = i_tblname and relnamespace = c_namespace;
+ 	if not found then
+ 		raise exception 'Slony-I: table % does not exist in namespace %/%', tblname, c_namespace, i_nspname;
+ 	end if;
+ 	
+ 	-- So, the table is legit; try to look it up for autovacuum policy
+ 	select enabled into c_enabled from "pg_catalog".pg_autovacuum where vacrelid = c_table;
+ 
+ 	if not found then
+ 		return 'f'::boolean;   -- Autovac is turned on, and this table has no overriding handling
+ 	end if;
+ 
+ 	if c_enabled then
+ 		return 'f'::boolean;   -- Autovac is expressly turned on for this table
+ 	end if;
+ 
+ 	return 't'::boolean;
+ end;$$ language plpgsql;
+ 
+ comment on function @NAMESPACE at .AutoVacExcludesTable (name, name) is 
+ 'returns false if autovacuum handles vacuuming of the table; returns true if Slony-I should manage it';
+ 
+ 
+ -- ----------------------------------------------------------------------
+ -- FUNCTION TablesToVacuum()
+ --
+ --	Make function be STRICT
+ -- ----------------------------------------------------------------------
+ create or replace function @NAMESPACE at .TablesToVacuum () returns setof @NAMESPACE at .vactables as 
+ '
+ declare
+ 	prec @NAMESPACE at .vactables%rowtype;
+ begin
+ 	prec.nspname := ''_ at CLUSTERNAME@'';
+ 	prec.relname := ''sl_event'';
+ 	if @NAMESPACE at .AutoVacExcludesTable(prec.nspname, prec.relname) then
+ 		return next prec;
+ 	end if;
+ 	prec.nspname := ''_ at CLUSTERNAME@'';
+ 	prec.relname := ''sl_confirm'';
+ 	if @NAMESPACE at .AutoVacExcludesTable(prec.nspname, prec.relname) then
+ 		return next prec;
+ 	end if;
+ 	prec.nspname := ''_ at CLUSTERNAME@'';
+ 	prec.relname := ''sl_setsync'';
+ 	if @NAMESPACE at .AutoVacExcludesTable(prec.nspname, prec.relname) then
+ 		return next prec;
+ 	end if;
+ 	prec.nspname := ''_ at CLUSTERNAME@'';
+ 	prec.relname := ''sl_log_1'';
+ 	if @NAMESPACE at .AutoVacExcludesTable(prec.nspname, prec.relname) then
+ 		return next prec;
+ 	end if;
+ 	prec.nspname := ''_ at CLUSTERNAME@'';
+ 	prec.relname := ''sl_log_2'';
+ 	if @NAMESPACE at .AutoVacExcludesTable(prec.nspname, prec.relname) then
+ 		return next prec;
+ 	end if;
+ 	prec.nspname := ''_ at CLUSTERNAME@'';
+ 	prec.relname := ''sl_seqlog'';
+ 	if @NAMESPACE at .AutoVacExcludesTable(prec.nspname, prec.relname) then
+ 		return next prec;
+ 	end if;
+ 	prec.nspname := ''pg_catalog'';
+ 	prec.relname := ''pg_listener'';
+ 	if @NAMESPACE at .AutoVacExcludesTable(prec.nspname, prec.relname) then
+ 		return next prec;
+ 	end if;
+ 	prec.nspname := ''pg_catalog'';
+ 	prec.relname := ''pg_statistic'';
+ 	if @NAMESPACE at .AutoVacExcludesTable(prec.nspname, prec.relname) then
+ 		return next prec;
+ 	end if;
+ 
+    return;
+ end
+ ' language plpgsql;
+ 
+ comment on function @NAMESPACE at .TablesToVacuum () is 
+ 'Return a list of tables that require frequent vacuuming.  We use this
+ function so that we do not hardcode this into C code.';
+ 



More information about the Slony1-commit mailing list