Skip to content

Commit 97c1c45

Browse files
x4mreshke
authored andcommitted
Fuse shared archive with ycmdb.shared_archive
1 parent e0d1154 commit 97c1c45

6 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/backend/access/transam/xlog.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ int wal_keep_size_mb = 0;
118118
int XLOGbuffers = -1;
119119
int XLogArchiveTimeout = 0;
120120
int XLogArchiveMode = ARCHIVE_MODE_OFF;
121+
bool ycmdb_shared_archive = false; /* makes archive_mode=on act as shared */
121122
char *XLogArchiveCommand = NULL;
122123
bool EnableHotStandby = false;
123124
bool fullPageWrites = true;

src/backend/postmaster/pgarch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ pgarch_ArchiverCopyLoop(void)
387387
* marks files as .done when the primary confirms archival. After
388388
* promotion, the archiver starts working normally.
389389
*/
390-
if (XLogArchiveMode == ARCHIVE_MODE_SHARED && RecoveryInProgress())
390+
if (EffectiveArchiveModeIsShared() && RecoveryInProgress())
391391
return;
392392

393393
/* force directory scan in the first call to pgarch_readyXlog() */

src/backend/replication/walreceiver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ XLogWalRcvClose(XLogRecPtr recptr, TimeLineID tli)
11231123
{
11241124
XLogArchiveNotify(xlogfname);
11251125
}
1126-
else if (XLogArchiveMode == ARCHIVE_MODE_SHARED)
1126+
else if (EffectiveArchiveModeIsShared())
11271127
{
11281128
/*
11291129
* In shared mode, check if this segment is already archived on primary.

src/backend/replication/walsender.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include "storage/ipc.h"
8484
#include "storage/pmsignal.h"
8585
#include "storage/proc.h"
86+
#include "storage/procarray.h"
8687
#include "tcop/dest.h"
8788
#include "tcop/tcopprot.h"
8889
#include "utils/acl.h"
@@ -2782,8 +2783,8 @@ WalSndArchivalReport(void)
27822783
TimestampTz now;
27832784
char *last_archived;
27842785

2785-
/* Only send reports when archive_mode=shared */
2786-
if (XLogArchiveMode != ARCHIVE_MODE_SHARED)
2786+
/* Only send reports when shared archive is active */
2787+
if (!EffectiveArchiveModeIsShared())
27872788
return;
27882789

27892790
/* Only send reports during physical streaming replication, not during backup */

src/backend/utils/misc/guc_tables.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "access/slru.h"
3232
#include "access/toast_compression.h"
3333
#include "access/twophase.h"
34+
#include "access/xlog.h"
3435
#include "access/xlog_internal.h"
3536
#include "access/xlogprefetcher.h"
3637
#include "access/xlogrecovery.h"
@@ -1190,6 +1191,17 @@ struct config_bool ConfigureNamesBool[] =
11901191
NULL, NULL, NULL
11911192
},
11921193

1194+
{
1195+
{"ycmdb.shared_archive", PGC_POSTMASTER, WAL_ARCHIVING,
1196+
gettext_noop("Makes archive_mode=on behave as shared (for managed service compatibility)."),
1197+
gettext_noop("When true, archive_mode=on is treated as archive_mode=shared. Does not affect archive_mode=off or archive_mode=always. Used when control plane cannot configure archive_mode=shared directly."),
1198+
GUC_NOT_IN_SAMPLE
1199+
},
1200+
&ycmdb_shared_archive,
1201+
false,
1202+
NULL, NULL, NULL
1203+
},
1204+
11931205
{
11941206
{"wal_init_zero", PGC_SUSET, WAL_SETTINGS,
11951207
gettext_noop("Writes zeroes to new WAL files before first use."),

src/include/access/xlog.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ typedef enum ArchiveMode
6666
ARCHIVE_MODE_SHARED, /* shared archive between primary and standby */
6767
} ArchiveMode;
6868
extern PGDLLIMPORT int XLogArchiveMode;
69+
extern PGDLLIMPORT bool ycmdb_shared_archive;
70+
71+
/*
72+
* True when shared archive behavior is active: either archive_mode=shared
73+
* or archive_mode=on with ycmdb.shared_archive=true (managed service).
74+
*/
75+
#define EffectiveArchiveModeIsShared() \
76+
(XLogArchiveMode == ARCHIVE_MODE_SHARED || \
77+
(XLogArchiveMode == ARCHIVE_MODE_ON && ycmdb_shared_archive))
6978

7079
/* WAL levels */
7180
typedef enum WalLevel

0 commit comments

Comments
 (0)