Skip to content

Commit eb0a42c

Browse files
committed
Fix die_commit_pending_replication.sql
1 parent 8e1eab0 commit eb0a42c

4 files changed

Lines changed: 45 additions & 46 deletions

File tree

src/backend/replication/gp_replication.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ GetMirrorStatus(FtsResponse *response, bool *ready_for_syncrep)
582582
break;
583583
}
584584

585-
response->IsSyncRepEnabled = WalSndCtl->sync_standbys_defined;
585+
response->IsSyncRepEnabled = WalSndCtl->sync_standbys_status & SYNC_STANDBY_DEFINED;
586586

587587
LWLockRelease(SyncRepLock);
588588

@@ -598,7 +598,8 @@ GetMirrorStatus(FtsResponse *response, bool *ready_for_syncrep)
598598
void
599599
SetSyncStandbysDefined(void)
600600
{
601-
if (!WalSndCtl->sync_standbys_defined)
601+
if (((((volatile WalSndCtlData *) WalSndCtl)->sync_standbys_status) &
602+
(SYNC_STANDBY_INIT | SYNC_STANDBY_DEFINED)) == SYNC_STANDBY_INIT)
602603
{
603604
set_gp_replication_config("synchronous_standby_names", "*");
604605

@@ -611,7 +612,7 @@ SetSyncStandbysDefined(void)
611612
void
612613
UnsetSyncStandbysDefined(void)
613614
{
614-
if (WalSndCtl->sync_standbys_defined)
615+
if (WalSndCtl->sync_standbys_status & SYNC_STANDBY_DEFINED)
615616
{
616617
set_gp_replication_config("synchronous_standby_names", "");
617618

src/backend/replication/syncrep.c

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
222222
* don't touch the queue.
223223
*/
224224
if (!SyncRepRequested() ||
225-
(!IS_QUERY_DISPATCHER() && !((volatile WalSndCtlData *) WalSndCtl)->sync_standbys_defined))
225+
(!IS_QUERY_DISPATCHER() && ((((volatile WalSndCtlData *) WalSndCtl)->sync_standbys_status) &
226+
(SYNC_STANDBY_INIT | SYNC_STANDBY_DEFINED)) == SYNC_STANDBY_INIT))
226227
return;
227228

228229
/* Cap the level for anything other than commit to remote flush only. */
@@ -335,19 +336,46 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
335336
* (SYNC_STANDBY_INIT is not set), fall back to a check based on the LSN,
336337
* then do a direct GUC check.
337338
*/
338-
if (((!IS_QUERY_DISPATCHER()) && !WalSndCtl->sync_standbys_defined) ||
339-
lsn <= WalSndCtl->lsn[mode])
339+
if (!IS_QUERY_DISPATCHER())
340340
{
341-
elogif(debug_walrepl_syncrep, LOG,
342-
"syncrep wait -- Not waiting for syncrep because xlog up to LSN (%X/%X) which is "
343-
"greater than this backend's commit LSN (%X/%X) has already "
344-
"been replicated.",
345-
(uint32) (WalSndCtl->lsn[mode] >> 32), (uint32) WalSndCtl->lsn[mode],
346-
(uint32) (lsn >> 32), (uint32) lsn);
347-
348-
349-
LWLockRelease(SyncRepLock);
350-
return;
341+
if (WalSndCtl->sync_standbys_status & SYNC_STANDBY_INIT)
342+
{
343+
if ((WalSndCtl->sync_standbys_status & SYNC_STANDBY_DEFINED) == 0 ||
344+
lsn <= WalSndCtl->lsn[mode])
345+
{
346+
LWLockRelease(SyncRepLock);
347+
return;
348+
}
349+
}
350+
else if (lsn <= WalSndCtl->lsn[mode])
351+
{
352+
/*
353+
* The LSN is older than what we need to wait for. The sync standby
354+
* data has not been initialized yet, but we are OK to not wait
355+
* because we know that there is no point in doing so based on the
356+
* LSN.
357+
*/
358+
LWLockRelease(SyncRepLock);
359+
return;
360+
}
361+
else if (!SyncStandbysDefined())
362+
{
363+
/*
364+
* If we are here, the sync standby data has not been initialized yet,
365+
* and the LSN is newer than what need to wait for, so we have fallen
366+
* back to the best thing we could do in this case: a check on
367+
* SyncStandbysDefined() to see if the GUC is set or not.
368+
*
369+
* When the GUC has a value, we wait until the checkpointer updates
370+
* the status data because we cannot be sure yet if we should wait or
371+
* not. Here, the GUC has *no* value, we are sure that there is no
372+
* point to wait; this matters for example when initializing a
373+
* cluster, where we should never wait, and no sync standbys is the
374+
* default behavior.
375+
*/
376+
LWLockRelease(SyncRepLock);
377+
return;
378+
}
351379
}
352380

353381
/*

src/backend/utils/misc/guc.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4748,29 +4748,6 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
47484748
break;
47494749
}
47504750

4751-
/*
4752-
* Check permission to run ALTER SYSTEM on the target variable
4753-
*/
4754-
if (!superuser())
4755-
{
4756-
if (resetall)
4757-
ereport(ERROR,
4758-
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4759-
errmsg("permission denied to perform ALTER SYSTEM RESET ALL")));
4760-
else
4761-
{
4762-
AclResult aclresult;
4763-
4764-
aclresult = pg_parameter_aclcheck(name, GetUserId(),
4765-
ACL_ALTER_SYSTEM);
4766-
if (aclresult != ACLCHECK_OK)
4767-
ereport(ERROR,
4768-
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4769-
errmsg("permission denied to set parameter \"%s\"",
4770-
name)));
4771-
}
4772-
}
4773-
47744751
/*
47754752
* Unless it's RESET_ALL, validate the target variable and value
47764753
*/

src/include/replication/walsender_private.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ typedef struct
138138
*/
139139
XLogRecPtr lsn[NUM_SYNC_REP_WAIT_MODE];
140140

141-
/*
142-
* Are any sync standbys defined? Waiting backends can't reload the
143-
* config file safely, so checkpointer updates this value as needed.
144-
* Protected by SyncRepLock.
145-
*/
146-
bool sync_standbys_defined;
147-
148141
/*
149142
* Status of data related to the synchronous standbys. Waiting backends
150143
* can't reload the config file safely, so checkpointer updates this value

0 commit comments

Comments
 (0)