Chris Browne cbbrowne at lists.slony.info
Fri Sep 28 14:15:55 PDT 2007
Update of /home/cvsd/slony1/slony1-engine/src/slon
In directory main.slony.info:/tmp/cvs-serv15801/slon

Modified Files:
      Tag: REL_1_2_STABLE
	remote_worker.c 
Log Message:
Fixed a problem with "EXECUTE SCRIPT" (introduced in remote_worker.c
version 1.124.2.13) where moving the relevant code into a subroutine
at the end led to losing the "BEGIN; SET TRANSACTION ISOLATION LEVEL
SERIALIZABLE;" query that needs to be the first thing run.

Moved the EXECUTE SCRIPT code back into the main loop.

Ran successfully through testddlscript before committing to CVS.

As pointed out by Jeff Frost


Index: remote_worker.c
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slon/remote_worker.c,v
retrieving revision 1.124.2.26
retrieving revision 1.124.2.27
diff -C2 -d -r1.124.2.26 -r1.124.2.27
*** remote_worker.c	27 Sep 2007 14:23:03 -0000	1.124.2.26
--- remote_worker.c	28 Sep 2007 21:15:53 -0000	1.124.2.27
***************
*** 267,272 ****
  static void compress_actionseq(const char *ssy_actionseq, SlonDString * action_subquery);
  
- static void process_ddl_script(SlonWorkMsg_event * event,SlonNode * node,
- 							  PGconn * local_dbconn, char * seqbuf );
  static int check_set_subscriber(int set_id, int node_id,PGconn * local_dbconn);
  
--- 267,270 ----
***************
*** 1271,1275 ****
  			else if (strcmp(event->ev_type, "DDL_SCRIPT") == 0)
  			{
! 				process_ddl_script(event,node,local_dbconn,seqbuf);
  			}
  			else if (strcmp(event->ev_type, "RESET_CONFIG") == 0)
--- 1269,1391 ----
  			else if (strcmp(event->ev_type, "DDL_SCRIPT") == 0)
  			{
! 				int			ddl_setid = (int)strtol(event->ev_data1, NULL, 10);
! 				char	   *ddl_script = event->ev_data2;
! 				int			ddl_only_on_node = (int)strtol(event->ev_data3, NULL, 10);
! 				int num_statements = -1, stmtno;
! 				int node_in_set;
! 				int localNodeId;
! 				PGresult *res;
! 				ExecStatusType rstat;
! 
! 				/**
! 				 * Check to make sure this node is part of the set
! 				 */
! 				slon_log(SLON_INFO, "Checking local node id\n");
! 				localNodeId = db_getLocalNodeId(local_dbconn);
! 				slon_log(SLON_INFO,"Found local node id\n");
! 				node_in_set = check_set_subscriber(ddl_setid,localNodeId,local_dbconn);
! 	
! 				if(!node_in_set) {
! 					/**
! 					 *
! 					 * Node is not part of the set.  
! 					 * Do not forward the DDL to the node,
! 					 * nor should it be included in the log for log-shipping.
! 					 */
! 					slon_log(SLON_INFO,"Not forwarding DDL to node %d for set %d\n",
! 						 node->no_id,ddl_setid);
! 		
! 				}
! 				else 
! 				{
! 					slon_log(SLON_INFO, "prepare for DDL script - set:%d onlyonnode:%d\n", ddl_setid, ddl_only_on_node);
! 					slon_appendquery(&query1,
! 							 "select %s.ddlScript_prepare_int(%d, %d); ",
! 							 rtcfg_namespace,
! 							 ddl_setid, ddl_only_on_node);
! 		
! 					if (query_execute(node, local_dbconn, &query1) < 0) {
! 						slon_log(SLON_ERROR, "remoteWorkerThread_%d: DDL preparation failed - set %d - only on node %d\n",
! 							 node->no_id, ddl_setid, ddl_only_on_node);			
! 						slon_retry();
! 					}
! 		
! 					slon_log(SLON_INFO, "prepared for DDL script\n");
! 					num_statements = scan_for_statements (ddl_script);
! 					slon_log(SLON_CONFIG, "remoteWorkerThread_%d: DDL request with %d statements\n",
! 						 node->no_id, num_statements);
! 					if ((num_statements < 0) || (num_statements >= MAXSTATEMENTS)) {
! 						slon_log(SLON_ERROR, "remoteWorkerThread_%d: DDL had invalid number of statements - %d\n", 
! 							 node->no_id, num_statements);
! 						slon_retry();
! 					}
! 		
! 					for (stmtno=0; stmtno < num_statements;  stmtno++) {
! 						int startpos, endpos;
! 						char *dest;
! 						if (stmtno == 0)
! 							startpos = 0;
! 						else
! 							startpos = STMTS[stmtno-1];
! 			
! 						endpos = STMTS[stmtno];
! 						dest = (char *) malloc (endpos - startpos + 1);
! 						if (dest == 0) {
! 							slon_log(SLON_ERROR, "remoteWorkerThread_%d: malloc() failure in DDL_SCRIPT - could not allocate %d bytes of memory\n", 
! 								 node->no_id, endpos - startpos + 1);
! 							slon_retry();
! 						}
! 						strncpy(dest, ddl_script + startpos, endpos-startpos);
! 						dest[STMTS[stmtno]-startpos] = 0;
! 						slon_mkquery(&query1, "%s", dest);
! 						slon_log(SLON_CONFIG, "remoteWorkerThread_%d: DDL Statement %d: [%s]\n", 
! 							 node->no_id, stmtno, dest);						 
! 						free(dest);
! 			
! 						res = PQexec(local_dbconn, dstring_data(&query1));
! 			
! 						if (PQresultStatus(res) != PGRES_COMMAND_OK && 
! 						    PQresultStatus(res) != PGRES_TUPLES_OK &&
! 						    PQresultStatus(res) != PGRES_EMPTY_QUERY)
! 						{
! 							rstat = PQresultStatus(res);
! 							slon_log(SLON_ERROR, "DDL Statement failed - %s\n", PQresStatus(rstat));
! 							dstring_free(&query1);
! 							slon_retry();
! 						}
! 						rstat = PQresultStatus(res);
! 						slon_log (SLON_CONFIG, "DDL success - %s\n", PQresStatus(rstat));
! 					}
! 					slon_log(SLON_INFO, "completed DDL script - run ddlScript_complete_int()\n");
! 					slon_mkquery(&query1, "select %s.ddlScript_complete_int(%d, %d); ", 
! 						     rtcfg_namespace,
! 						     ddl_setid,
! 						     ddl_only_on_node);
! 
! 					if (query_execute(node, local_dbconn, &query1) < 0) {
! 						slon_log(SLON_ERROR, "remoteWorkerThread_%d: DDL completion failed - set %d - only on node %\n",
! 							 node->no_id, ddl_setid, ddl_only_on_node);			
! 						slon_retry();
! 					}
! 
! 					slon_mkquery(&query1, "", "");
! 		
! 					/* DDL_SCRIPT needs to be turned into a log shipping script */
! 					/* Note that the issue about parsing that mandates breaking 
! 					   up compound statements into
! 					   individually-processed statements does not apply to log
! 					   shipping as psql parses and processes each statement
! 					   individually */
! 		
! 					if (archive_dir)
! 					{
! 						if ((ddl_only_on_node < 1) || (ddl_only_on_node == rtcfg_nodeid))
! 						{
! 							if (archive_append_str(node, ddl_script) < 0)
! 								slon_retry();
! 						}
! 					}
! 				} /*else node a subscriber */
! 
  			}
  			else if (strcmp(event->ev_type, "RESET_CONFIG") == 0)
***************
*** 5984,6119 ****
  
  /**
-  *
-  * Process a ddl_script command.
-  */
- static void
- process_ddl_script(SlonWorkMsg_event * event,SlonNode * node,
- 							  PGconn * local_dbconn,
- 							  char * seqbuf) 
- {
- 	int			ddl_setid = (int)strtol(event->ev_data1, NULL, 10);
- 	char	   *ddl_script = event->ev_data2;
- 	int			ddl_only_on_node = (int)strtol(event->ev_data3, NULL, 10);
- 	int num_statements = -1, stmtno;
- 	int node_in_set;
- 	int localNodeId;
- 	PGresult *res;
- 	ExecStatusType rstat;
- 	SlonDString query1;
- 
- 	
- 
- 	dstring_init(&query1);
- 	/**
- 	 * Check to make sure this node is part of the set
- 	 */
- 	slon_log(SLON_INFO, "Checking local node id\n");
- 	localNodeId = db_getLocalNodeId(local_dbconn);
- 	slon_log(SLON_INFO,"Found local node id\n");
- 	node_in_set = check_set_subscriber(ddl_setid,localNodeId,local_dbconn);
- 	
- 	if(!node_in_set) {
- 		/**
- 		 *
- 		 * Node is not part of the set.  
- 		 * Do not forward teh DDL to the node,
- 		 * nor should it be included in the log for log-shipping.
- 		 */
- 		slon_log(SLON_INFO,"Not forwarding DDL to node %d for set %d\n",
- 				 node->no_id,ddl_setid);
- 		
- 	}
- 	else 
- 	{
- 		slon_appendquery(&query1,
- 						 "select %s.ddlScript_prepare_int(%d, %d); ",
- 						 rtcfg_namespace,
- 						 ddl_setid, ddl_only_on_node);
- 		
- 		if (query_execute(node, local_dbconn, &query1) < 0) {
- 			slon_log(SLON_ERROR, "remoteWorkerThread_%d: DDL preparation failed - set %d - only on node %d\n",
- 					 node->no_id, ddl_setid, ddl_only_on_node);			
- 			slon_retry();
- 		}
- 		
- 		num_statements = scan_for_statements (ddl_script);
- 		slon_log(SLON_CONFIG, "remoteWorkerThread_%d: DDL request with %d statements\n",
- 				 node->no_id, num_statements);
- 		if ((num_statements < 0) || (num_statements >= MAXSTATEMENTS)) {
- 			slon_log(SLON_ERROR, "remoteWorkerThread_%d: DDL had invalid number of statements - %d\n", 
- 					 node->no_id, num_statements);
- 			slon_retry();
- 		}
- 		
- 		for (stmtno=0; stmtno < num_statements;  stmtno++) {
- 			int startpos, endpos;
- 			char *dest;
- 			if (stmtno == 0)
- 				startpos = 0;
- 			else
- 				startpos = STMTS[stmtno-1];
- 			
- 			endpos = STMTS[stmtno];
- 			dest = (char *) malloc (endpos - startpos + 1);
- 			if (dest == 0) {
- 				slon_log(SLON_ERROR, "remoteWorkerThread_%d: malloc() failure in DDL_SCRIPT - could not allocate %d bytes of memory\n", 
- 						 node->no_id, endpos - startpos + 1);
- 				slon_retry();
- 			}
- 			strncpy(dest, ddl_script + startpos, endpos-startpos);
- 			dest[STMTS[stmtno]-startpos] = 0;
- 			slon_mkquery(&query1, "%s", dest);
- 			slon_log(SLON_CONFIG, "remoteWorkerThread_%d: DDL Statement %d: [%s]\n", 
- 					 node->no_id, stmtno, dest);						 
- 			free(dest);
- 			
- 			res = PQexec(local_dbconn, dstring_data(&query1));
- 			
- 			if (PQresultStatus(res) != PGRES_COMMAND_OK && 
- 				PQresultStatus(res) != PGRES_TUPLES_OK &&
- 				PQresultStatus(res) != PGRES_EMPTY_QUERY)
- 				{
- 					rstat = PQresultStatus(res);
- 					slon_log(SLON_ERROR, "DDL Statement failed - %s\n", PQresStatus(rstat));
- 					dstring_free(&query1);
- 					slon_retry();
- 				}
- 			rstat = PQresultStatus(res);
- 			slon_log (SLON_CONFIG, "DDL success - %s\n", PQresStatus(rstat));
- 		}
- 		
- 		slon_mkquery(&query1, "select %s.ddlScript_complete_int(%d, %d); ", 
- 					 rtcfg_namespace,
- 					 ddl_setid,
- 					 ddl_only_on_node);
- 
- 		if (query_execute(node, local_dbconn, &query1) < 0) {
- 			slon_log(SLON_ERROR, "remoteWorkerThread_%d: DDL completion failed - set %d - only on node %\n",
- 					 node->no_id, ddl_setid, ddl_only_on_node);			
- 			slon_retry();
- 		}
- 		
- 		/* DDL_SCRIPT needs to be turned into a log shipping script */
- 		/* Note that the issue about parsing that mandates breaking 
- 		   up compound statements into
- 		   individually-processed statements does not apply to log
- 		   shipping as psql parses and processes each statement
- 		   individually */
- 		
- 		if (archive_dir)
- 			{
- 				if ((ddl_only_on_node < 1) || (ddl_only_on_node == rtcfg_nodeid))
- 					{
- 						if (archive_append_str(node, ddl_script) < 0)
- 							slon_retry();
- 					}
- 			}
- 	}/*else node a subscriber */
- 	
- 	dstring_free(&query1);
- 
- }
- 
- /**
   * Checks to see if the node specified is a member of the set.
   *
--- 6100,6103 ----
***************
*** 6131,6135 ****
    res = PQexec(local_dbconn,dstring_data(&query1));
    if(PQresultStatus(res)!=PGRES_TUPLES_OK) {
!     slon_log(SLON_ERROR,"remoteWorkerThread_%d: DDL preperation can not check set membership"
  	     ,node_id);
  	dstring_free(&query1);
--- 6115,6119 ----
    res = PQexec(local_dbconn,dstring_data(&query1));
    if(PQresultStatus(res)!=PGRES_TUPLES_OK) {
!     slon_log(SLON_ERROR,"remoteWorkerThread_%d: DDL preparation can not check set membership"
  	     ,node_id);
  	dstring_free(&query1);



More information about the Slony1-commit mailing list