On 12/13/18 8:35 AM, David Steele wrote:
> On 12/12/18 7:17 PM, Michael Paquier wrote:
>> On Wed, Dec 12, 2018 at 07:54:05AM -0500, David Steele wrote:
> 
>>> But, we could at least use the . notation and end up with something like
>>> 000000010000000100000001.00000002.partial or perhaps
>>> 000000010000000100000001.T00000002.partial?  Maybe
>>> 000000010000000100000001.00000002.tpartial?
>>>

I updated the patch to use 000000010000000100000001.00000002.partial
since this is more consistent with what we do in other cases.

-- 
-David
da...@pgmasters.net
From 7eda6932eab47cd25a4fa25a8a5575b41b51c9ff Mon Sep 17 00:00:00 2001
From: David Steele <da...@pgmasters.net>
Date: Thu, 13 Dec 2018 12:20:43 -0500
Subject: [PATCH] Add timeline to partial WAL segments.

If two clusters are promoted from the same timeline on the same WAL segment, 
they will both archive a .partial file with the same name even if they select 
different timelines to promote to.

If one partially promotes and later fails we want to be able to promote another 
cluster.  This duplicate .partial file causes problems for archive commands 
that 
won't overwrite an existing file.  Even if the archive command checks the 
contents they might not be binary identical due to differing unused space at 
the 
end of the file or because one cluster accepted more transactions.

Add the timeline being promoted *to* into the .partial filename to prevent the 
conflict, e.g. 000000010000000100000001.00000002.partial.

If more than one cluster tries to promote to the same timeline there will still 
be a conflict but this is desirable.  Once a cluster has claimed a timeline no 
other cluster should be archiving on it.
---
 src/backend/access/transam/xlog.c | 12 ++++++++----
 src/include/postmaster/pgarch.h   |  2 +-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/backend/access/transam/xlog.c 
b/src/backend/access/transam/xlog.c
index c80b14ed97..be4da2c3d0 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7624,8 +7624,10 @@ StartupXLOG(void)
                 * the completed version of the same segment later, it will 
fail. (We
                 * used to do that in 9.4 and below, and it caused such 
problems).
                 *
-                * As a compromise, we rename the last segment with the .partial
-                * suffix, and archive it. Archive recovery will never try to 
read
+                * As a compromise, we rename the last segment with the new 
timeline and
+                * .partial suffix, and archive it. The timeline is added in 
case there
+                * are multiple promotions from the same timeline before a 
stable
+                * primary emerges.  Archive recovery will never try to read
                 * .partial segments, so they will normally go unused. But in 
the odd
                 * PITR case, the administrator can copy them manually to the 
pg_wal
                 * directory (removing the suffix). They can be useful in 
debugging,
@@ -7653,8 +7655,10 @@ StartupXLOG(void)
                                char            partialpath[MAXPGPATH];
 
                                XLogFilePath(origpath, EndOfLogTLI, 
endLogSegNo, wal_segment_size);
-                               snprintf(partialfname, MAXFNAMELEN, 
"%s.partial", origfname);
-                               snprintf(partialpath, MAXPGPATH, "%s.partial", 
origpath);
+                               snprintf(partialfname, MAXFNAMELEN, 
"%s.%08X.partial",
+                                                origfname, ThisTimeLineID);
+                               snprintf(partialpath, MAXPGPATH, 
"%s.%08X.partial", origpath,
+                                                ThisTimeLineID);
 
                                /*
                                 * Make sure there's no .done or .ready file 
for the .partial
diff --git a/src/include/postmaster/pgarch.h b/src/include/postmaster/pgarch.h
index 292e63a26a..504ab7b9dc 100644
--- a/src/include/postmaster/pgarch.h
+++ b/src/include/postmaster/pgarch.h
@@ -23,7 +23,7 @@
  * ----------
  */
 #define MIN_XFN_CHARS  16
-#define MAX_XFN_CHARS  40
+#define MAX_XFN_CHARS  41
 #define VALID_XFN_CHARS "0123456789ABCDEF.history.backup.partial"
 
 /* ----------
-- 
2.17.2 (Apple Git-113)

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to