Skip to content

Commit 1c02163

Browse files
x4mrobot-cloud-aw
authored andcommitted
Fuse shared archive with ycmdb.shared_archive
1 parent 52e387d commit 1c02163

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
@@ -388,7 +388,7 @@ pgarch_ArchiverCopyLoop(void)
388388
* marks files as .done when the primary confirms archival. After
389389
* promotion, the archiver starts working normally.
390390
*/
391-
if (XLogArchiveMode == ARCHIVE_MODE_SHARED && RecoveryInProgress())
391+
if (EffectiveArchiveModeIsShared() && RecoveryInProgress())
392392
return;
393393

394394
/* 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
@@ -1115,7 +1115,7 @@ XLogWalRcvClose(XLogRecPtr recptr, TimeLineID tli)
11151115
{
11161116
XLogArchiveNotify(xlogfname);
11171117
}
1118-
else if (XLogArchiveMode == ARCHIVE_MODE_SHARED)
1118+
else if (EffectiveArchiveModeIsShared())
11191119
{
11201120
/*
11211121
* 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
@@ -84,6 +84,7 @@
8484
#include "storage/ipc.h"
8585
#include "storage/pmsignal.h"
8686
#include "storage/proc.h"
87+
#include "storage/procarray.h"
8788
#include "tcop/dest.h"
8889
#include "tcop/tcopprot.h"
8990
#include "utils/acl.h"
@@ -2779,8 +2780,8 @@ WalSndArchivalReport(void)
27792780
TimestampTz now;
27802781
char *last_archived;
27812782

2782-
/* Only send reports when archive_mode=shared */
2783-
if (XLogArchiveMode != ARCHIVE_MODE_SHARED)
2783+
/* Only send reports when shared archive is active */
2784+
if (!EffectiveArchiveModeIsShared())
27842785
return;
27852786

27862787
/* 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
@@ -34,6 +34,7 @@
3434
#include "access/slru.h"
3535
#include "access/toast_compression.h"
3636
#include "access/twophase.h"
37+
#include "access/xlog.h"
3738
#include "access/xlog_internal.h"
3839
#include "access/xlogprefetcher.h"
3940
#include "access/xlogrecovery.h"
@@ -1226,6 +1227,17 @@ struct config_bool ConfigureNamesBool[] =
12261227
NULL, NULL, NULL
12271228
},
12281229

1230+
{
1231+
{"ycmdb.shared_archive", PGC_POSTMASTER, WAL_ARCHIVING,
1232+
gettext_noop("Makes archive_mode=on behave as shared (for managed service compatibility)."),
1233+
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."),
1234+
GUC_NOT_IN_SAMPLE
1235+
},
1236+
&ycmdb_shared_archive,
1237+
false,
1238+
NULL, NULL, NULL
1239+
},
1240+
12291241
{
12301242
{"wal_init_zero", PGC_SUSET, WAL_SETTINGS,
12311243
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
@@ -68,6 +68,15 @@ typedef enum ArchiveMode
6868
ARCHIVE_MODE_SHARED, /* shared archive between primary and standby */
6969
} ArchiveMode;
7070
extern PGDLLIMPORT int XLogArchiveMode;
71+
extern PGDLLIMPORT bool ycmdb_shared_archive;
72+
73+
/*
74+
* True when shared archive behavior is active: either archive_mode=shared
75+
* or archive_mode=on with ycmdb.shared_archive=true (managed service).
76+
*/
77+
#define EffectiveArchiveModeIsShared() \
78+
(XLogArchiveMode == ARCHIVE_MODE_SHARED || \
79+
(XLogArchiveMode == ARCHIVE_MODE_ON && ycmdb_shared_archive))
7180

7281
/* WAL levels */
7382
typedef enum WalLevel

0 commit comments

Comments
 (0)