Jan Wieck wieck at lists.slony.info
Tue Jun 5 15:22:09 PDT 2007
Update of /home/cvsd/slony1/slony1-engine/src/slonik
In directory main.slony.info:/tmp/cvs-serv6954/src/slonik

Modified Files:
	dbutil.c slonik.c slonik.h 
Log Message:
Fix EXECUTE SCRIPT so that it records the ev_seqno for WAIT FOR EVENT
and make sure all DDL is executed in session_replication_role "local"
on the origin as well as all subscribers. This will cause the slony
triggers to ignore all DML statements while user triggers follow the
regular configuration options for ENABLE [REPLICA/ALWAYS] or DISABLE.

TODO: Put the correct session_replication_role setting into archive
logs as well.

Jan


Index: slonik.h
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slonik/slonik.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** slonik.h	18 Apr 2007 15:03:51 -0000	1.30
--- slonik.h	5 Jun 2007 22:22:07 -0000	1.31
***************
*** 579,593 ****
  int			db_disconnect(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
  
! int db_exec_command(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
  				SlonDString * query);
! int db_exec_evcommand(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
! 				  SlonDString * query);
! PGresult *db_exec_select(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
! 			   SlonDString * query);
! int db_get_version(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
! int db_check_namespace(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
! 				   char *clustername);
! int db_check_requirements(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
! 					  char *clustername);
  int			db_get_nodeid(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
  int			db_begin_xact(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
--- 579,597 ----
  int			db_disconnect(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
  
! int			db_exec_command(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
  				SlonDString * query);
! int			db_exec_evcommand(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
! 				SlonDString * query);
! int			db_exec_evcommand_p(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
! 				SlonDString * query, int nParams, const Oid *paramTypes, 
! 				const char *const *paramValues, const int *paramLengths, 
! 				const int *paramFormats, int resultFormat);
! PGresult   *db_exec_select(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
! 				SlonDString * query);
! int			db_get_version(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
! int			db_check_namespace(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
! 				char *clustername);
! int			db_check_requirements(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
! 				char *clustername);
  int			db_get_nodeid(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
  int			db_begin_xact(SlonikStmt * stmt, SlonikAdmInfo * adminfo);

Index: slonik.c
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slonik/slonik.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -C2 -d -r1.77 -r1.78
*** slonik.c	31 May 2007 16:46:18 -0000	1.77
--- slonik.c	5 Jun 2007 22:22:07 -0000	1.78
***************
*** 3665,3669 ****
  	SlonDString script;
  	int			rc;
! 	int num_statements = -1, stmtno;
  	char		buf[4096];
  	char		rex1[256];
--- 3665,3669 ----
  	SlonDString script;
  	int			rc;
! 	int			num_statements = -1, stmtno;
  	char		buf[4096];
  	char		rex1[256];
***************
*** 3671,3676 ****
  	char		rex3[256];
  	char		rex4[256];
- 	PGresult *res;
- 	ExecStatusType rstat;
  
  #define PARMCOUNT 1  
--- 3671,3674 ----
***************
*** 3745,3761 ****
  		free(dest);
  
! 		res = PQexec(adminfo1->dbconn, dstring_data(&query));
! 
! 		if (PQresultStatus(res) != PGRES_COMMAND_OK && 
! 		    PQresultStatus(res) != PGRES_TUPLES_OK &&
! 		    PQresultStatus(res) != PGRES_EMPTY_QUERY)
  		{
- 			rstat = PQresultStatus(res);
- 			printf("DDL Statement failed - %s\n", PQresStatus(rstat));
  			dstring_free(&query);
  			return -1;
  		}
- 		/* rstat = PQresultStatus(res); */
- 		/* printf ("Success - %s\n", PQresStatus(rstat)); */
  	}
  	
--- 3743,3751 ----
  		free(dest);
  
! 		if (db_exec_command((SlonikStmt *)stmt, adminfo1, &query) < 0)
  		{
  			dstring_free(&query);
  			return -1;
  		}
  	}
  	
***************
*** 3771,3788 ****
  	params[PARMCOUNT-1] = dstring_data(&script);
  
! 	res = PQexecParams(adminfo1->dbconn, dstring_data(&query), PARMCOUNT,
! 			   NULL, params, paramlens, paramfmts, 0);
! 	
! 	if (PQresultStatus(res) != PGRES_COMMAND_OK && 
! 	    PQresultStatus(res) != PGRES_TUPLES_OK &&
! 	    PQresultStatus(res) != PGRES_EMPTY_QUERY)
  	{
- 		rstat = PQresultStatus(res);
- 		printf("Event submission for DDL failed - %s\n", PQresStatus(rstat));
  		dstring_free(&query);
  		return -1;
- 	} else {
- 		rstat = PQresultStatus(res);
- 		printf ("DDL on origin - %s\n", PQresStatus(rstat));
  	}
  	
--- 3761,3769 ----
  	params[PARMCOUNT-1] = dstring_data(&script);
  
! 	if (db_exec_evcommand_p((SlonikStmt *)stmt, adminfo1, &query,
! 				PARMCOUNT, NULL, params, paramlens, paramfmts, 0) < 0)
  	{
  		dstring_free(&query);
  		return -1;
  	}
  	

Index: dbutil.c
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slonik/dbutil.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** dbutil.c	18 Apr 2007 15:03:51 -0000	1.13
--- dbutil.c	5 Jun 2007 22:22:07 -0000	1.14
***************
*** 140,144 ****
  
  	dstring_init(&query);
! 	slon_mkquery(&query,"SET datestyle to 'ISO'");
  
  	adminfo->dbconn = dbconn;
--- 140,145 ----
  
  	dstring_init(&query);
! 	slon_mkquery(&query,"SET datestyle TO 'ISO'; "
! 						"SET session_replication_role TO local; ");
  
  	adminfo->dbconn = dbconn;
***************
*** 257,260 ****
--- 258,310 ----
  
  /* ----------
+  * db_exec_evcommand_p
+  *
+  *	Execute a stored procedure returning an event sequence and remember
+  *	that in the admin info for later wait events. Differs from
+  *	db_exec_evcommand by using PQexecParams().
+  * ----------
+  */
+ int
+ db_exec_evcommand_p(SlonikStmt * stmt, SlonikAdmInfo * adminfo, 
+ 		SlonDString * query, int nParams, const Oid *paramTypes,
+ 		const char *const *paramValues, const int *paramLengths,
+ 		const int *paramFormats, int resultFormat)
+ {
+ 	PGresult   *res;
+ 
+ 	db_notice_stmt = stmt;
+ 
+ 	if (db_begin_xact(stmt, adminfo) < 0)
+ 		return -1;
+ 
+ 	res = PQexecParams(adminfo->dbconn, dstring_data(query),
+ 			nParams, paramTypes, paramValues, paramLengths,
+ 			paramFormats, resultFormat);
+ 	if (PQresultStatus(res) != PGRES_TUPLES_OK)
+ 	{
+ 		fprintf(stderr, "%s:%d: %s %s - %s",
+ 				stmt->stmt_filename, stmt->stmt_lno,
+ 				PQresStatus(PQresultStatus(res)),
+ 				dstring_data(query), PQresultErrorMessage(res));
+ 		PQclear(res);
+ 		return -1;
+ 	}
+ 	if (PQntuples(res) != 1)
+ 	{
+ 		fprintf(stderr, "%s:%d: %s - did not return 1 row",
+ 				stmt->stmt_filename, stmt->stmt_lno,
+ 				dstring_data(query));
+ 		PQclear(res);
+ 		return -1;
+ 	}
+ 
+ 	slon_scanint64(PQgetvalue(res, 0, 0), &(adminfo->last_event));
+ 	PQclear(res);
+ 
+ 	return 0;
+ }
+ 
+ 
+ /* ----------
   * db_exec_select
   *



More information about the Slony1-commit mailing list