Chris Browne cbbrowne at lists.slony.info
Wed Jan 2 11:00:29 PST 2008
Update of /home/cvsd/slony1/slony1-engine/src/slon
In directory main.slony.info:/tmp/cvs-serv29551/src/slon

Modified Files:
	cleanup_thread.c confoptions.c confoptions.h slon.h 
Log Message:
Apply changes to cleanup thread:

- by default, use TRUNCATE rather than DELETE to trim sl_log_? tables

- moved substantially all logic for trimming of old data out of the
  C code, and into cleanupThread() stored function

  The stored function now can be used to request cleanup, so that we
  might force it to happen at an unexpected time, such as manually,
  for testing, as part of a test script.

- added parameters to slon to support this:

  interval - cleanup_interval (default '10 minutes')

     This controls how quickly old events are trimmed out.  It used to
     be a hard-coded value.

     Old events are trimmed out once the confirmations are aged by
     (cleanup_interval).

     This then controls when the data in sl_log_1/sl_log_2 can be dropped.

     Data in *those* tables is deleted when it is older than the
     earliest XID still captured in sl_event.

  boolean - cleanup_deletelogs (default 'false')

     This controls whether or not we DELETE data from sl_log_1/sl_log_2

     By default, we now NEVER delete data from the log tables; we
     instead use TRUNCATE.


Index: slon.h
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slon/slon.h,v
retrieving revision 1.65
retrieving revision 1.66
diff -C2 -d -r1.65 -r1.66
*** slon.h	19 Oct 2007 18:38:35 -0000	1.65
--- slon.h	2 Jan 2008 19:00:27 -0000	1.66
***************
*** 473,476 ****
--- 473,478 ----
  
  extern int	vac_frequency;
+ extern char *cleanup_interval;
+ extern bool cleanup_deletelogs;
  
  /* ----------

Index: confoptions.c
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slon/confoptions.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** confoptions.c	30 Jul 2007 22:34:33 -0000	1.25
--- confoptions.c	2 Jan 2008 19:00:27 -0000	1.26
***************
*** 721,724 ****
--- 721,735 ----
  	},
  
+ 	{
+ 		{
+ 			(const char *)"cleanup_deletelogs",
+ 			gettext_noop("Should the cleanup thread DELETE sl_log_? entries or not"),
+ 			gettext_noop("Should the cleanup thread DELETE sl_log_? entries or not"),
+ 			SLON_C_BOOL
+ 		},
+ 		&cleanup_deletelogs,
+ 		false
+ 	},
+ 
  	{{0}}
  };
***************
*** 860,863 ****
--- 871,886 ----
  	},
  #endif
+ 	{
+ 		{
+ 			(const char *)"cleanup_interval",
+ 			gettext_noop("A PostgreSQL value compatible with ::interval "
+ 						 "which indicates what aging interval should be used "
+ 						 "for deleting old events, and hence for purging sl_log_* tables."),
+ 			NULL,
+ 			SLON_C_STRING
+ 		},
+ 		&cleanup_interval,
+ 		"10 minutes"
+ 	},
  	{{0}}
  };

Index: cleanup_thread.c
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slon/cleanup_thread.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** cleanup_thread.c	19 Oct 2007 18:38:35 -0000	1.40
--- cleanup_thread.c	2 Jan 2008 19:00:27 -0000	1.41
***************
*** 31,34 ****
--- 31,37 ----
   */
  int			vac_frequency = SLON_VACUUM_FREQUENCY;
+ char *cleanup_interval;
+ bool cleanup_deletelogs;
+ 
  static int	vac_bias = 0;
  static unsigned long earliest_xid = 0;
***************
*** 46,52 ****
  {
  	SlonConn   *conn;
! 	SlonDString query1;
  	SlonDString query2;
! 	SlonDString query3;
  
  	PGconn	   *dbconn;
--- 49,55 ----
  {
  	SlonConn   *conn;
! 	SlonDString query_baseclean;
  	SlonDString query2;
! 	SlonDString query_pertbl;
  
  	PGconn	   *dbconn;
***************
*** 55,60 ****
  	struct timeval tv_start;
  	struct timeval tv_end;
! 	int			n,
! 				t;
  	int			vac_count = 0;
  	int			vac_enable = SLON_VACUUM_FREQUENCY;
--- 58,62 ----
  	struct timeval tv_start;
  	struct timeval tv_end;
! 	int			t;
  	int			vac_count = 0;
  	int			vac_enable = SLON_VACUUM_FREQUENCY;
***************
*** 92,97 ****
  	 * Build the query string for calling the cleanupEvent() stored procedure
  	 */
! 	dstring_init(&query1);
! 	slon_mkquery(&query1, "select %s.cleanupEvent(); ", rtcfg_namespace);
  	dstring_init(&query2);
  
--- 94,103 ----
  	 * Build the query string for calling the cleanupEvent() stored procedure
  	 */
! 	dstring_init(&query_baseclean);
! 	slon_mkquery(&query_baseclean, "select %s.cleanupEvent('%s'::interval, '%s'::boolean); ", 
! 		     rtcfg_namespace, 
! 		     cleanup_interval,
! 		     cleanup_deletelogs ? "true" : "false"
! 		);
  	dstring_init(&query2);
  
***************
*** 110,119 ****
  		 */
  		gettimeofday(&tv_start, NULL);
! 		res = PQexec(dbconn, dstring_data(&query1));
  		if (PQresultStatus(res) != PGRES_TUPLES_OK)
  		{
  			slon_log(SLON_FATAL,
  					 "cleanupThread: \"%s\" - %s",
! 					 dstring_data(&query1), PQresultErrorMessage(res));
  			PQclear(res);
  			slon_retry();
--- 116,125 ----
  		 */
  		gettimeofday(&tv_start, NULL);
! 		res = PQexec(dbconn, dstring_data(&query_baseclean));
  		if (PQresultStatus(res) != PGRES_TUPLES_OK)
  		{
  			slon_log(SLON_FATAL,
  					 "cleanupThread: \"%s\" - %s",
! 					 dstring_data(&query_baseclean), PQresultErrorMessage(res));
  			PQclear(res);
  			slon_retry();
***************
*** 126,210 ****
  				 TIMEVAL_DIFF(&tv_start, &tv_end));
  
- 		/*
- 		 * Clean up the logs and eventually finish switching logs
- 		 */
- 		gettimeofday(&tv_start, NULL);
  		slon_mkquery(&query2,
! 					 "select ev_origin, ev_seqno, "
! 					 "  \"public\".txid_snapshot_xmin(ev_snapshot) "
! 					 "from %s.sl_event "
! 					 "where (ev_origin, ev_seqno) in "
! 					 "    (select ev_origin, min(ev_seqno) "
! 					 "     from %s.sl_event "
! 					 "     where ev_type = 'SYNC' "
! 					 "     group by ev_origin); ",
! 					 rtcfg_namespace, rtcfg_namespace);
! 		res = PQexec(dbconn, dstring_data(&query2));
! 		if (PQresultStatus(res) != PGRES_TUPLES_OK)
! 		{
! 			slon_log(SLON_FATAL,
! 					 "cleanupThread: \"%s\" - %s",
! 					 dstring_data(&query2), PQresultErrorMessage(res));
! 			PQclear(res);
! 			slon_retry();
! 			break;
! 		}
! 		n = PQntuples(res);
! 		for (t = 0; t < n; t++)
  		{
! 			slon_mkquery(&query2,
! 						 "delete from %s.sl_log_1 "
! 						 "where log_origin = '%s' "
! 						 "and log_txid < '%s'; "
! 						 "delete from %s.sl_log_2 "
! 						 "where log_origin = '%s' "
! 						 "and log_txid < '%s'; "
! 						 "delete from %s.sl_seqlog "
! 						 "where seql_origin = '%s' "
! 						 "and seql_ev_seqno < '%s'; "
! 						 "select %s.logswitch_finish(); ",
! 						 rtcfg_namespace, PQgetvalue(res, t, 0),
! 						 PQgetvalue(res, t, 2),
! 						 rtcfg_namespace, PQgetvalue(res, t, 0),
! 						 PQgetvalue(res, t, 2),
! 						 rtcfg_namespace, PQgetvalue(res, t, 0),
! 						 PQgetvalue(res, t, 1),
! 						 rtcfg_namespace);
! 			res2 = PQexec(dbconn, dstring_data(&query2));
! 			if (PQresultStatus(res2) != PGRES_TUPLES_OK)
! 			{
! 				slon_log(SLON_FATAL,
! 						 "cleanupThread: \"%s\" - %s",
! 						 dstring_data(&query2), PQresultErrorMessage(res2));
! 				PQclear(res);
! 				PQclear(res2);
! 				slon_retry();
! 				break;
! 			}
! 			PQclear(res2);
! 
! 			/*
! 			 * Eventually kick off a logswitch. This might fail,
! 			 * but this is not really slon's problem, so we just
! 			 * shrug and move on if it does.
! 			 */
! 			slon_mkquery(&query2,
! 						 "select %s.logswitch_weekly(); ",
! 						 rtcfg_namespace);
! 			res2 = PQexec(dbconn, dstring_data(&query2));
! 			if (PQresultStatus(res2) != PGRES_TUPLES_OK)
! 			{
! 				slon_log(SLON_WARN,
! 						 "cleanupThread: \"%s\" - %s",
! 						 dstring_data(&query2), PQresultErrorMessage(res2));
! 			}
! 			PQclear(res2);
  		}
! 		PQclear(res);
! 		gettimeofday(&tv_end, NULL);
! 		slon_log(SLON_INFO,
! 				 "cleanupThread: %8.3f seconds for delete logs\n",
! 				 TIMEVAL_DIFF(&tv_start, &tv_end));
! 
  		/*
  		 * Detain the usual suspects (vacuum event and log data)
--- 132,146 ----
  				 TIMEVAL_DIFF(&tv_start, &tv_end));
  
  		slon_mkquery(&query2,
! 			     "select %s.logswitch_weekly(); ",
! 			     rtcfg_namespace);
! 		res2 = PQexec(dbconn, dstring_data(&query2));
! 		if (PQresultStatus(res2) != PGRES_TUPLES_OK)
  		{
! 			slon_log(SLON_WARN,
! 				 "cleanupThread: \"%s\" - %s",
! 				 dstring_data(&query2), PQresultErrorMessage(res2));
  		}
! 		PQclear(res2);
  		/*
  		 * Detain the usual suspects (vacuum event and log data)
***************
*** 267,279 ****
  				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;
--- 203,215 ----
  				slon_log (SLON_DEBUG1, "cleanupThread: %s analyze \"%s\".%s;\n",
  					      vacuum_action, tab_nspname, tab_relname);
! 				dstring_init(&query_pertbl);
! 				slon_mkquery (&query_pertbl, "%s analyze \"%s\".%s;",
  					      vacuum_action, tab_nspname, tab_relname);
! 				res2 = PQexec(dbconn, dstring_data(&query_pertbl));
  				if (PQresultStatus(res) != PGRES_COMMAND_OK)  /* query error */
                                  {
                   	                slon_log(SLON_ERROR,
  	                                        "cleanupThread: \"%s\" - %s",
!                                                 dstring_data(&query_pertbl), PQresultErrorMessage(res2));
                                                  /*
                                                   * slon_retry(); break;
***************
*** 281,285 ****
                                  }
  				PQclear(res2);
! 				dstring_reset(&query3);
  			}
  			gettimeofday(&tv_end, NULL);
--- 217,221 ----
                                  }
  				PQclear(res2);
! 				dstring_reset(&query_pertbl);
  			}
  			gettimeofday(&tv_end, NULL);
***************
*** 291,295 ****
  			 * Free Resources
  			 */
! 			dstring_free(&query3);
  
  		}
--- 227,231 ----
  			 * Free Resources
  			 */
! 			dstring_free(&query_pertbl);
  
  		}
***************
*** 299,303 ****
  	 * Free Resources
  	 */
! 	dstring_free(&query1);
  	dstring_free(&query2);
  
--- 235,239 ----
  	 * Free Resources
  	 */
! 	dstring_free(&query_baseclean);
  	dstring_free(&query2);
  
***************
*** 331,339 ****
  	long long	xid;
  	PGresult   *res;
! 	SlonDString query1;
  
! 	dstring_init(&query1);
! 	(void) slon_mkquery(&query1, "select %s.getMinXid();", rtcfg_namespace);
! 	res = PQexec(dbconn, dstring_data(&query1));
  	if (PQresultStatus(res) != PGRES_TUPLES_OK)
  	{
--- 267,275 ----
  	long long	xid;
  	PGresult   *res;
! 	SlonDString query;
  
! 	dstring_init(&query);
! 	(void) slon_mkquery(&query, "select %s.getMinXid();", rtcfg_namespace);
! 	res = PQexec(dbconn, dstring_data(&query));
  	if (PQresultStatus(res) != PGRES_TUPLES_OK)
  	{
***************
*** 346,350 ****
  	slon_log(SLON_DEBUG1, "cleanupThread: minxid: %d\n", xid);
  	PQclear(res);
! 	dstring_free(&query1);
  	return (unsigned long)xid;
  }
--- 282,286 ----
  	slon_log(SLON_DEBUG1, "cleanupThread: minxid: %d\n", xid);
  	PQclear(res);
! 	dstring_free(&query);
  	return (unsigned long)xid;
  }

Index: confoptions.h
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/slon/confoptions.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** confoptions.h	20 Apr 2007 20:53:18 -0000	1.35
--- confoptions.h	2 Jan 2008 19:00:27 -0000	1.36
***************
*** 14,18 ****
  extern char *archive_dir;
  
- extern int	vac_frequency;
  extern int	slon_log_level;
  extern int	sync_interval;
--- 14,17 ----
***************
*** 28,31 ****
--- 27,40 ----
  extern int	quit_sync_finalsync;
  
+ /*
+  * ----------
+  * Global variables in cleanup_thread.c
+  * ----------
+  */
+ 
+ extern int	vac_frequency;
+ extern char *cleanup_interval;
+ extern bool cleanup_deletelogs;
+ 
  char	   *Syslog_ident;
  char	   *Syslog_facility;



More information about the Slony1-commit mailing list