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

Modified Files:
	cleanup_thread.c 
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: cleanup_thread.c
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slon/cleanup_thread.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** cleanup_thread.c	20 Apr 2007 20:53:18 -0000	1.37
--- cleanup_thread.c	27 Jun 2007 15:51:36 -0000	1.38
***************
*** 78,83 ****
  	int			vac_enable = SLON_VACUUM_FREQUENCY;
  	char	   *vacuum_action;
  
! 	slon_log(SLON_DEBUG1, "cleanupThread: thread starts\n");
  
  	/*
--- 78,84 ----
  	int			vac_enable = SLON_VACUUM_FREQUENCY;
  	char	   *vacuum_action;
+ 	int ntuples;
  
! 	slon_log(SLON_CONFIG, "cleanupThread: thread starts\n");
  
  	/*
***************
*** 89,93 ****
  		vac_bias = rand() % (SLON_CLEANUP_SLEEP * 166);
  	}
! 	slon_log(SLON_DEBUG4, "cleanupThread: bias = %d\n", vac_bias);
  
  	/*
--- 90,94 ----
  		vac_bias = rand() % (SLON_CLEANUP_SLEEP * 166);
  	}
! 	slon_log(SLON_CONFIG, "cleanupThread: bias = %d\n", vac_bias);
  
  	/*
***************
*** 139,143 ****
  		PQclear(res);
  		gettimeofday(&tv_end, NULL);
! 		slon_log(SLON_DEBUG1,
  				 "cleanupThread: %8.3f seconds for cleanupEvent()\n",
  				 TIMEVAL_DIFF(&tv_start, &tv_end));
--- 140,144 ----
  		PQclear(res);
  		gettimeofday(&tv_end, NULL);
! 		slon_log(SLON_INFO,
  				 "cleanupThread: %8.3f seconds for cleanupEvent()\n",
  				 TIMEVAL_DIFF(&tv_start, &tv_end));
***************
*** 219,223 ****
  		PQclear(res);
  		gettimeofday(&tv_end, NULL);
! 		slon_log(SLON_DEBUG1,
  				 "cleanupThread: %8.3f seconds for delete logs\n",
  				 TIMEVAL_DIFF(&tv_start, &tv_end));
--- 220,224 ----
  		PQclear(res);
  		gettimeofday(&tv_end, NULL);
! 		slon_log(SLON_INFO,
  				 "cleanupThread: %8.3f seconds for delete logs\n",
  				 TIMEVAL_DIFF(&tv_start, &tv_end));
***************
*** 233,274 ****
  		{
  			unsigned long latest_xid;
- 			int a_vac = 0;
- 
- 			vac_count = 0;
- 
- 			dstring_init(&query3);
  
- 			/* 
- 			 * if we are running a version >= 8.1, check to see 
- 			 * if autovacuum is enabled, if so we should only run
- 			 * analyze on the tables in table_list[], otherwise it
- 			 * is ok to vacuum analyze
- 			 */
- 
- 			if (conn->pg_version >=80100)
- 			{
- 				dstring_reset(&query3);
- 				slon_mkquery(&query3, "show autovacuum");
- 				res = PQexec(dbconn, dstring_data(&query3));
- 				if (PQresultStatus(res)  != PGRES_TUPLES_OK)
- 				{
- 					slon_log(SLON_ERROR,
-                                                          "cleanupThread: \"%s\" - %s",
-                                                    dstring_data(&query3), PQresultErrorMessage(res));
- 
-                                         /*
-                                          * slon_retry(); break;
-                                          */
-                                 }
- 				else if (strncmp(PQgetvalue(res, 0, 0), "on", 2) == 0)
- 				{
- 					/*
- 					 * autovacuum is on
- 					 */
- 					a_vac=1;
- 				}
-                                 PQclear(res);
- 				dstring_reset(&query3);
- 			}
  			latest_xid = get_earliest_xid(dbconn);
  			vacuum_action = "";
--- 234,238 ----
***************
*** 276,280 ****
  			{
  				
! 				slon_log(SLON_DEBUG4,
  					"cleanupThread: xid %d still active - analyze instead\n",
  					earliest_xid);
--- 240,244 ----
  			{
  				
! 				slon_log(SLON_INFO,
  					"cleanupThread: xid %d still active - analyze instead\n",
  					earliest_xid);
***************
*** 282,286 ****
  			else
  			{
! 				if ((vac_enable == vac_frequency) && (a_vac==0))
  				{
  					vacuum_action = "vacuum ";
--- 246,250 ----
  			else
  			{
! 				if (vac_enable == vac_frequency)
  				{
  					vacuum_action = "vacuum ";
***************
*** 294,360 ****
  			 */
  			gettimeofday(&tv_start, NULL);
- 			for (t = 0; table_list[t] != NULL ; t++)
- 			{
  
! 				sprintf(tstring, table_list[t], rtcfg_namespace);
! 				if (a_vac==1)
! 				{
! 					slon_mkquery(&query3,"select (case when pga.enabled ISNULL THEN true ELSE pga.enabled END) "
! 						"from \"pg_catalog\".pg_namespace PGN, \"pg_catalog\".pg_class PGC LEFT OUTER JOIN "
! 						"\"pg_catalog\".pg_autovacuum pga ON (PGC.oid = pga.vacrelid) where PGC.relnamespace = PGN.oid "
! 						"and %s.slon_quote_input('%s')=%s.slon_quote_brute(PGN.nspname) || '.' || %s.slon_quote_brute(PGC.relname);",
! 					 	rtcfg_namespace,tstring, rtcfg_namespace, rtcfg_namespace);
  
! 					res = PQexec(dbconn, dstring_data(&query3));
! 					if (PQresultStatus(res) != PGRES_TUPLES_OK)  /* query error */
! 					{
! 						slon_log(SLON_ERROR,
! 							 "cleanupThread: \"%s\" - %s",
! 							   dstring_data(&query3), PQresultErrorMessage(res));
! 						/*
! 						 * slon_retry(); break;
! 						 */
! 					}
! 					else	/* no errors */
! 					{
! 						if (PQntuples(res) == 1)	/* we want 1 and only 1 row, otherwise skip */
! 						{
! 							if (strncmp(PQgetvalue(res, 0, 0), "f", 1) == 0) 
! 							{
! 								/* 
! 								 * pg_avac is NOT enabled for this table
! 								 * so this means we need to handel it internaly
! 								 */
! 								if (vac_enable == vac_frequency)
! 								{
! 									vacuum_action = "vacuum ";
! 								}
! 							}
! 							else
! 							{
! 								vacuum_action = "";
! 							}
! 						}
! 					}
! 					PQclear(res);
! 				}
! 				dstring_reset(&query3);
  
! 				slon_mkquery(&query3,"%s analyze %s;",vacuum_action, tstring);
! 				res = PQexec(dbconn, dstring_data(&query3));
  				if (PQresultStatus(res) != PGRES_COMMAND_OK)  /* query error */
                                  {
                   	                slon_log(SLON_ERROR,
  	                                        "cleanupThread: \"%s\" - %s",
!                                                 dstring_data(&query3), PQresultErrorMessage(res));
                                                  /*
                                                   * slon_retry(); break;
                                                   */                  
                                  }
! 				PQclear(res);
  				dstring_reset(&query3);
  			}
  			gettimeofday(&tv_end, NULL);
! 			slon_log(SLON_DEBUG2,
  					 "cleanupThread: %8.3f seconds for vacuuming\n",
  					 TIMEVAL_DIFF(&tv_start, &tv_end));
--- 258,305 ----
  			 */
  			gettimeofday(&tv_start, NULL);
  
! 			slon_mkquery(&query2, "select nspname, relname from %s.TablesToVacuum();", rtcfg_namespace);
! 			res = PQexec(dbconn, dstring_data(&query2));
  
! 			/* for each table...  and we should set up the
! 			 * query to return not only the table name,
! 			 * but also a boolean to support what's in the
! 			 * SELECT below; that'll nicely simplify this
! 			 * process... */
! 			
! 			if (PQresultStatus(res) != PGRES_TUPLES_OK)  /* query error */
! 			{
! 				slon_log(SLON_ERROR,
! 					 "cleanupThread: \"%s\" - %s",
! 					 dstring_data(&query2), PQresultErrorMessage(res));
! 			}
! 			ntuples = PQntuples(res);
! 			slon_log(SLON_DEBUG1, "cleanupThread: number of tables to clean: %d\n", ntuples);
  
! 			for (t = 0; t < ntuples ; t++)
! 			{
! 				char *tab_nspname = PQgetvalue(res, t, 0);
! 				char *tab_relname = PQgetvalue(res, t, 1);
! 
! 				slon_log (SLON_DEBUG1, "cleanupThread: %s analyze \"%s\".%s;\n",
! 					      vacuum_action, tab_nspname, tab_relname);
! 				dstring_init(&query3);
! 				slon_mkquery (&query3, "%s analyze \"%s\".%s;",
! 					      vacuum_action, tab_nspname, tab_relname);
! 				res2 = PQexec(dbconn, dstring_data(&query3));
  				if (PQresultStatus(res) != PGRES_COMMAND_OK)  /* query error */
                                  {
                   	                slon_log(SLON_ERROR,
  	                                        "cleanupThread: \"%s\" - %s",
!                                                 dstring_data(&query3), PQresultErrorMessage(res2));
                                                  /*
                                                   * slon_retry(); break;
                                                   */                  
                                  }
! 				PQclear(res2);
  				dstring_reset(&query3);
  			}
  			gettimeofday(&tv_end, NULL);
! 			slon_log(SLON_INFO,
  					 "cleanupThread: %8.3f seconds for vacuuming\n",
  					 TIMEVAL_DIFF(&tv_start, &tv_end));
***************
*** 416,420 ****
  	}
  	xid = strtoll(PQgetvalue(res, 0, 0), NULL, 10);
! 	slon_log(SLON_DEBUG3, "cleanupThread: minxid: %d\n", xid);
  	PQclear(res);
  	dstring_free(&query1);
--- 361,365 ----
  	}
  	xid = strtoll(PQgetvalue(res, 0, 0), NULL, 10);
! 	slon_log(SLON_DEBUG1, "cleanupThread: minxid: %d\n", xid);
  	PQclear(res);
  	dstring_free(&query1);



More information about the Slony1-commit mailing list