I suppose it makes sense to do check for clear_bkup_dir() & bkup_dir() in a 
similar fashion.

On Wednesday 16 January 2008 02:01:05 am At.Mitani wrote:
> Hi Rick,
>
> Thank you for create patch.
> If you can agree with , I'd like to recomend check it in the
> "restore_dir()" as following patch.
>
> --- recovery.c.old      2008-01-16 16:53:43.000000000 +0900
> +++ recovery.c  2008-01-16 16:52:03.000000000 +0900
> @@ -682,6 +682,10 @@
>         char bkp_dir[256];
>         pid_t pid = getpid();
>
> +       if (PGR_Recovery_Mode == PGR_WITHOUT_BACKUP)
> +       {
> +               return STATUS_OK;
> +       }
>         sprintf(org_dir,"%s",dir_name);
>         sprintf(bkp_dir,"%s_%d",dir_name,pid);
>         status = rename(bkp_dir,org_dir);
>
>
> Regards,
> ----------------
> At.Mitani
>
>
> On Wed, 16 Jan 2008 00:00:12 -0600
>
> Rick Vernam <[EMAIL PROTECTED]> wrote:
> > I wrote a patch for pgcluster (which cybercluster is based on) that were
> > not applied correctly to cybercluster.
> >
> > in src/backend/libpq/recovery.c
> > all occurrences of restore_dir(...) should be conditional upon
> > if (PGR_Recovery_Mode != PGR_WITHOUT_BACKUP)
> >
> > so, instead of
> > restore_dir(...)
> >
> > it should be
> > if (PGR_Recovery_Mode != PGR_WITHOUT_BACKUP)
> >     restore_dir(...)
> >
> > This is a serious bug that occurs when a node starts recovery with -u
> > (rsync recovery without backup), and results in a lost base directory.
> >
> > see attached patch for fix.
> >
> > -Rick


--- src/backend/libpq/recovery.old	2007-01-16 10:21:30.000000000 -0600
+++ src/backend/libpq/recovery.c	2007-01-16 10:21:43.000000000 -0600
@@ -704,6 +704,9 @@
 	char bkp_dir[256];
 	pid_t pid = getpid();
 
+	if (PGR_Recovery_Mode == PGR_WITHOUT_BACKUP)
+		return STATUS_OK;
+
 	sprintf(bkp_dir,"%s_%d",dir_name,pid);
 	return (remove_dir(bkp_dir));
 }
@@ -716,6 +719,9 @@
 	char bkp_dir[256];
 	pid_t pid = getpid();
 
+	if (PGR_Recovery_Mode == PGR_WITHOUT_BACKUP)
+		return STATUS_OK;
+
 	sprintf(org_dir,"%s",dir_name);
 	sprintf(bkp_dir,"%s_%d",dir_name,pid);
 	status = rename(org_dir,bkp_dir);
@@ -734,6 +740,9 @@
 	char bkp_dir[256];
 	pid_t pid = getpid();
 
+	if (PGR_Recovery_Mode == PGR_WITHOUT_BACKUP)
+		return STATUS_OK;
+
 	sprintf(org_dir,"%s",dir_name);
 	sprintf(bkp_dir,"%s_%d",dir_name,pid);
 	status = rename(bkp_dir,org_dir);
@@ -761,7 +770,7 @@
 
 	sprintf(org_dir,"%s/global",dest);
 	sprintf(control_file,"%s/global/pg_control",dest);
-	if ((stage == PGR_1ST_RECOVERY) && (PGR_Recovery_Mode != PGR_WITHOUT_BACKUP))
+	if (stage == PGR_1ST_RECOVERY)
 	{
 		if (bkup_dir(org_dir) != STATUS_OK)
 		{
@@ -787,7 +796,7 @@
 		cnt ++;
 		sleep(1);
 	}
-	if ((stage == PGR_2ND_RECOVERY) && (PGR_Recovery_Mode != PGR_WITHOUT_BACKUP))
+	if (stage == PGR_2ND_RECOVERY)
 	{
 		clear_bkup_dir(org_dir);
 	}
@@ -805,14 +814,12 @@
 	memset(dest_dir,0,sizeof(dest_dir));
 	sprintf(src_dir,"%s/%s",src,dir);
 	sprintf(dest_dir,"%s/%s",dest,dir);
-	if (PGR_Recovery_Mode != PGR_WITHOUT_BACKUP)
+	status = bkup_dir(dest_dir);
+	if (status < 0)
 	{
-		status = bkup_dir(dest_dir);
-		if (status < 0)
-		{
-			return STATUS_ERROR;
-		}
+		return STATUS_ERROR;
 	}
+
 	status = rsync_pg_data(src_dir, dest);
 	if (status != STATUS_OK )
 	{
@@ -840,11 +847,8 @@
 		restore_dir(dest_dir);
 		return STATUS_ERROR;
 	}
-	if (PGR_Recovery_Mode != PGR_WITHOUT_BACKUP)
-	{
-		clear_bkup_dir(dest_dir);
-	}
 
+	clear_bkup_dir(dest_dir);
 	return STATUS_OK;
 }
 
@@ -1308,7 +1312,7 @@
 	sprintf(src_dir,"%s:%s",hostName,location);
 	strncpy(dest_dir,location,sizeof(dest_dir));
 
-	if ((stage == PGR_1ST_RECOVERY) && (PGR_Recovery_Mode != PGR_WITHOUT_BACKUP))
+	if (stage == PGR_1ST_RECOVERY)
 	{
 		status = bkup_dir(location);
 	}
@@ -1330,7 +1334,7 @@
 		cnt ++;
 		sleep(1);
 	}
-	if ((stage == PGR_2ND_RECOVERY) && (PGR_Recovery_Mode != PGR_WITHOUT_BACKUP))
+	if (stage == PGR_2ND_RECOVERY)
 	{
 		clear_bkup_dir(location);
 	}
_______________________________________________
Pgcluster-general mailing list
[email protected]
http://pgfoundry.org/mailman/listinfo/pgcluster-general

Reply via email to