Skip to content

Commit c695e9e

Browse files
x4mreshke
authored andcommitted
Fuse shared archive with ycmdb.shared_archive
1 parent 5f5ec29 commit c695e9e

6 files changed

Lines changed: 26 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
@@ -119,6 +119,7 @@ int wal_keep_size_mb = 0;
119119
int XLOGbuffers = -1;
120120
int XLogArchiveTimeout = 0;
121121
int XLogArchiveMode = ARCHIVE_MODE_OFF;
122+
bool ycmdb_shared_archive = false; /* makes archive_mode=on act as shared */
122123
char *XLogArchiveCommand = NULL;
123124
bool EnableHotStandby = false;
124125
bool fullPageWrites = true;

src/backend/postmaster/pgarch.c

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

391391
/* 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
@@ -1098,7 +1098,7 @@ XLogWalRcvClose(XLogRecPtr recptr, TimeLineID tli)
10981098
{
10991099
XLogArchiveNotify(xlogfname);
11001100
}
1101-
else if (XLogArchiveMode == ARCHIVE_MODE_SHARED)
1101+
else if (EffectiveArchiveModeIsShared())
11021102
{
11031103
/*
11041104
* In shared mode, check if this segment is already archived on primary.

src/backend/replication/walsender.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,8 +2465,8 @@ WalSndArchivalReport(void)
24652465
TimestampTz now;
24662466
char *last_archived;
24672467

2468-
/* Only send reports when archive_mode=shared */
2469-
if (XLogArchiveMode != ARCHIVE_MODE_SHARED)
2468+
/* Only send reports when shared archive is active */
2469+
if (!EffectiveArchiveModeIsShared())
24702470
return;
24712471

24722472
/* Only send reports during physical streaming replication, not logical or backup */

src/backend/utils/misc/guc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "access/twophase.h"
4242
#include "access/xact.h"
4343
#include "access/yc_checker.h"
44+
#include "access/xlog.h"
4445
#include "access/xlog_internal.h"
4546
#include "access/xlogprefetcher.h"
4647
#include "access/xlogrecovery.h"
@@ -1381,6 +1382,17 @@ static struct config_bool ConfigureNamesBool[] =
13811382
NULL, NULL, NULL
13821383
},
13831384

1385+
{
1386+
{"ycmdb.shared_archive", PGC_POSTMASTER, WAL_ARCHIVING,
1387+
gettext_noop("Makes archive_mode=on behave as shared (for managed service compatibility)."),
1388+
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."),
1389+
GUC_NOT_IN_SAMPLE
1390+
},
1391+
&ycmdb_shared_archive,
1392+
false,
1393+
NULL, NULL, NULL
1394+
},
1395+
13841396
{
13851397
{"wal_init_zero", PGC_SUSET, WAL_SETTINGS,
13861398
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
@@ -63,6 +63,15 @@ typedef enum ArchiveMode
6363
ARCHIVE_MODE_SHARED, /* shared archive between primary and standby */
6464
} ArchiveMode;
6565
extern PGDLLIMPORT int XLogArchiveMode;
66+
extern PGDLLIMPORT bool ycmdb_shared_archive;
67+
68+
/*
69+
* True when shared archive behavior is active: either archive_mode=shared
70+
* or archive_mode=on with ycmdb.shared_archive=true (managed service).
71+
*/
72+
#define EffectiveArchiveModeIsShared() \
73+
(XLogArchiveMode == ARCHIVE_MODE_SHARED || \
74+
(XLogArchiveMode == ARCHIVE_MODE_ON && ycmdb_shared_archive))
6675

6776
/* WAL levels */
6877
typedef enum WalLevel

0 commit comments

Comments
 (0)