修复catchup时丢失未归档xlog的bug

This commit is contained in:
luozihao 2021-11-15 17:41:43 +08:00
parent e7d541bc7a
commit d52064490d
3 changed files with 15 additions and 8 deletions

View File

@ -152,12 +152,11 @@ ThreadId pgarch_start(void)
/*
* Do nothing if no archiver needed
*/
if (!XLogArchivingActive() && !(getObsReplicationSlot()))
ReplicationSlot* slot = getObsReplicationSlot();
if (!XLogArchivingActive() && slot == NULL)
return 0;
load_server_mode();
if (getObsReplicationSlot() != NULL &&
t_thrd.xlog_cxt.server_mode != PRIMARY_MODE &&
t_thrd.xlog_cxt.server_mode != STANDBY_MODE) {
if (slot != NULL && t_thrd.xlog_cxt.server_mode != PRIMARY_MODE && t_thrd.xlog_cxt.server_mode != STANDBY_MODE) {
return 0;
}
/*
@ -227,9 +226,17 @@ NON_EXEC_STATIC void PgArchiverMain()
*/
init_ps_display("archiver process", "", "", "");
setObsArchLatch(&t_thrd.arch.mainloop_latch);
ReplicationSlot* slot = getObsReplicationSlot();
if (slot != NULL) {
load_server_mode();
if (t_thrd.xlog_cxt.server_mode == PRIMARY_MODE) {
ReplicationSlotAcquire(NameStr(slot->data.name), slot->data.isDummyStandby);
}
}
initLastTaskLsn();
initArchiveCxt();
pgarch_MainLoop();
ReplicationSlotRelease();
gs_thread_exit(0);
}

View File

@ -834,8 +834,8 @@ void ReplicationSlotsComputeRequiredLSN(ReplicationSlotState *repl_slt_state)
in_use = true;
restart_lsn = vslot->data.restart_lsn;
/* ignore restart lsn of slot not active. backup slot is always considered. */
if (!s->active && s->data.database == InvalidOid && GET_SLOT_PERSISTENCY(vslot->data) != RS_BACKUP) {
/* ignore restart lsn of slot not active. backup slot and archive slot are always considered. */
if (s->archive_obs == NULL && !s->active && s->data.database == InvalidOid && GET_SLOT_PERSISTENCY(vslot->data) != RS_BACKUP) {
goto lock_release;
}
@ -1944,7 +1944,6 @@ void advanceObsSlot(XLogRecPtr restart_pos)
long current = TIME_GET_MILLISEC(tv);
long diff = current - t_thrd.arch.last_advance_slot_time;
if (diff > t_thrd.arch.advance_slot_wait_interval) {
t_thrd.slot_cxt.MyReplicationSlot = slot;
flushSlot(current);
}
} else {

View File

@ -634,7 +634,8 @@ bool SyncRepGetSyncRecPtr(XLogRecPtr *receivePtr, XLogRecPtr *writePtr, XLogRecP
*/
if ((!(*am_sync) && check_am_sync) || t_thrd.syncrep_cxt.SyncRepConfig == NULL ||
(!t_thrd.walsender_cxt.WalSndCtl->most_available_sync &&
list_length(sync_standbys) < t_thrd.syncrep_cxt.SyncRepConfig->num_sync)) {
list_length(sync_standbys) < t_thrd.syncrep_cxt.SyncRepConfig->num_sync) ||
(t_thrd.walsender_cxt.WalSndCtl->most_available_sync && list_length((sync_standbys)) == 0)) {
list_free(sync_standbys);
return false;
}