Jan Wieck wieck at lists.slony.info
Thu May 31 10:44:05 PDT 2007
Update of /home/cvsd/slony1/slony1-engine/src/backend
In directory main.slony.info:/tmp/cvs-serv3012/src/backend

Modified Files:
	slony1_funcs.sql 
Log Message:
Still need alterTableRestore() for the upgrade from 1.2.x to 2.0.
upgradeSchema() will restore the system catalog to a consistent
state and define+configure the new versions of the log and deny_access
triggers. 

Jan


Index: slony1_funcs.sql
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/backend/slony1_funcs.sql,v
retrieving revision 1.109
retrieving revision 1.110
diff -C2 -d -r1.109 -r1.110
*** slony1_funcs.sql	31 May 2007 16:46:18 -0000	1.109
--- slony1_funcs.sql	31 May 2007 17:44:02 -0000	1.110
***************
*** 3955,3958 ****
--- 3955,4075 ----
  
  -- ----------------------------------------------------------------------
+ -- FUNCTION alterTableRestore (tab_id)
+ -- ----------------------------------------------------------------------
+ create or replace function @NAMESPACE at .alterTableRestore (int4)
+ returns int4
+ as '
+ declare
+ 	p_tab_id			alias for $1;
+ 	v_no_id				int4;
+ 	v_tab_row			record;
+ 	v_tab_fqname		text;
+ 	v_n					int4;
+ begin
+ 	-- ----
+ 	-- Grab the central configuration lock
+ 	-- ----
+ 	lock table @NAMESPACE at .sl_config_lock;
+ 
+ 	-- ----
+ 	-- Get our local node ID
+ 	-- ----
+ 	v_no_id := @NAMESPACE at .getLocalNodeId(''_ at CLUSTERNAME@'');
+ 
+ 	-- ----
+ 	-- Get the sl_table row and the current tables origin. Check
+ 	-- that the table currently IS in altered state.
+ 	-- ----
+ 	select T.tab_reloid, T.tab_set, T.tab_altered,
+ 			S.set_origin, PGX.indexrelid,
+ 			@NAMESPACE at .slon_quote_brute(PGN.nspname) || ''.'' ||
+ 			@NAMESPACE at .slon_quote_brute(PGC.relname) as tab_fqname
+ 			into v_tab_row
+ 			from @NAMESPACE at .sl_table T, @NAMESPACE at .sl_set S,
+ 				"pg_catalog".pg_class PGC, "pg_catalog".pg_namespace PGN,
+ 				"pg_catalog".pg_index PGX, "pg_catalog".pg_class PGXC
+ 			where T.tab_id = p_tab_id
+ 				and T.tab_set = S.set_id
+ 				and T.tab_reloid = PGC.oid
+ 				and PGC.relnamespace = PGN.oid
+ 				and PGX.indrelid = T.tab_reloid
+ 				and PGX.indexrelid = PGXC.oid
+ 				and PGXC.relname = T.tab_idxname
+ 				for update;
+ 	if not found then
+ 		raise exception ''Slony-I: alterTableRestore(): Table with id % not found'', p_tab_id;
+ 	end if;
+ 	v_tab_fqname = v_tab_row.tab_fqname;
+ 	if not v_tab_row.tab_altered then
+ 		raise exception ''Slony-I: alterTableRestore(): Table % is not in altered state'',
+ 				v_tab_fqname;
+ 	end if;
+ 
+ 	execute ''lock table '' || v_tab_fqname || '' in access exclusive mode'';
+ 
+ 	-- ----
+ 	-- Procedures are different on origin and subscriber
+ 	-- ----
+ 	if v_no_id = v_tab_row.set_origin then
+ 		-- ----
+ 		-- On the Origin we just drop the trigger we originally added
+ 		-- ----
+ 		execute ''drop trigger "_ at CLUSTERNAME@_logtrigger_'' || 
+ 				p_tab_id || ''" on '' || v_tab_fqname;
+ 	else
+ 		-- ----
+ 		-- On the subscriber drop the denyAccess trigger
+ 		-- ----
+ 		execute ''drop trigger "_ at CLUSTERNAME@_denyaccess_'' || 
+ 				p_tab_id || ''" on '' || v_tab_fqname;
+ 				
+ 		-- ----
+ 		-- Restore all original triggers
+ 		-- ----
+ 		update "pg_catalog".pg_trigger
+ 				set tgrelid = v_tab_row.tab_reloid
+ 				where tgrelid = v_tab_row.indexrelid;
+ 		get diagnostics v_n = row_count;
+ 		if v_n > 0 then
+ 			update "pg_catalog".pg_class
+ 					set reltriggers = reltriggers + v_n
+ 					where oid = v_tab_row.tab_reloid;
+ 		end if;
+ 
+ 		-- ----
+ 		-- Restore all original rewrite rules
+ 		-- ----
+ 		update "pg_catalog".pg_rewrite
+ 				set ev_class = v_tab_row.tab_reloid
+ 				where ev_class = v_tab_row.indexrelid;
+ 		get diagnostics v_n = row_count;
+ 		if v_n > 0 then
+ 			update "pg_catalog".pg_class
+ 					set relhasrules = true
+ 					where oid = v_tab_row.tab_reloid;
+ 		end if;
+ 
+ 	end if;
+ 
+ 	-- ----
+ 	-- Mark the table not altered in our configuration
+ 	-- ----
+ 	update @NAMESPACE at .sl_table
+ 			set tab_altered = false where tab_id = p_tab_id;
+ 
+ 	return p_tab_id;
+ end;
+ ' language plpgsql;
+ comment on function @NAMESPACE at .alterTableRestore (int4) is
+ 'alterTableRestore (tab_id)
+ 
+ Restores table tab_id from being replicated.
+ 
+ On the origin, this simply involves dropping the "logtrigger" trigger.
+ 
+ On subscriber nodes, this involves dropping the "denyaccess" trigger,
+ and restoring user triggers and rules.';
+ 
+ -- ----------------------------------------------------------------------
  -- FUNCTION subscribeSet (sub_set, sub_provider, sub_receiver, sub_forward)
  -- ----------------------------------------------------------------------
***************
*** 5274,5278 ****
  
  declare
!         p_old   alias for $1;
  begin
  	-- ----
--- 5391,5396 ----
  
  declare
!         p_old   	alias for $1;
! 		v_tab_row	record;
  begin
  	-- ----
***************
*** 5285,5292 ****
  
  	if p_old IN (''1.2.0'', ''1.2.1'', ''1.2.2'', ''1.2.3'', ''1.2.4'', ''1.2.5'', ''1.2.6'', ''1.2.7'', ''1.2.8'', ''1.2.9'', ''1.2.10'') then
  
  		execute ''drop function @NAMESPACE at .alterTableForReplication(int4)'';
- 		execute ''drop function @NAMESPACE at .alterTableRestore(int4)'';
  		execute ''drop function @NAMESPACE at .pre74()'';
  	end if;
  
--- 5403,5426 ----
  
  	if p_old IN (''1.2.0'', ''1.2.1'', ''1.2.2'', ''1.2.3'', ''1.2.4'', ''1.2.5'', ''1.2.6'', ''1.2.7'', ''1.2.8'', ''1.2.9'', ''1.2.10'') then
+ 		-- ---- 
+ 		-- Upgrading from a pre-2.0 ... repair the system catalog
+ 		-- ----
+ 		for v_tab_row in select * from @NAMESPACE at .sl_table loop
+ 			perform @NAMESPACE at .alterTableRestore(v_tab_row.tab_id);
+ 		end loop;
  
+ 		-- ----
+ 		-- drop obsolete functions
+ 		-- ----
  		execute ''drop function @NAMESPACE at .alterTableForReplication(int4)'';
  		execute ''drop function @NAMESPACE at .pre74()'';
+ 
+ 		-- ----
+ 		-- and create the new versions of the log and deny access triggers.
+ 		-- ----
+ 		for v_tab_row in select * from @NAMESPACE at .sl_table loop
+ 			perform @NAMESPACE at .alterTableAddTriggers(v_tab_row.tab_id);
+ 			perform @NAMESPACE at .alterTableConfigureTriggers(v_tab_row.tab_id);
+ 		end loop;
  	end if;
  



More information about the Slony1-commit mailing list