Skip to content

Commit e2eaa0c

Browse files
knizhnikkelvich
authored andcommitted
Reduce WaitLatch timeout
1 parent ce87760 commit e2eaa0c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

multimaster.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,13 @@ MtmPrePrepareTransaction(MtmCurrentTrans* x)
736736
Assert(TransactionIdIsValid(x->xid));
737737

738738
if (Mtm->disabledNodeMask != 0) {
739-
MtmRefreshClusterStatus(true);
739+
timestamp_t now = MtmGetSystemTime();
740+
if (Mtm->lastClusterStatusUpdate + MSEC_TO_USEC(MtmRaftPollDelay) < now) {
741+
Mtm->lastClusterStatusUpdate = now;
742+
MtmRefreshClusterStatus(true);
743+
}
740744
if (!IsBackgroundWorker && Mtm->status != MTM_ONLINE) {
741-
/* Do not take in accoutn bg-workers which are performing recovery */
745+
/* Do not take in account bg-workers which are performing recovery */
742746
elog(ERROR, "Abort current transaction because this cluster node is in %s status", MtmNodeStatusMnem[Mtm->status]);
743747
}
744748
}
@@ -834,8 +838,10 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
834838
time_t transTimeout = Max(Mtm2PCMinTimeout, (ts->csn - ts->snapshot)*Mtm2PCPrepareRatio/100000); /* usec->msec and percents */
835839
int result = 0;
836840
int nConfigChanges = Mtm->nConfigChanges;
841+
842+
timestamp_t start = MtmGetSystemTime();
837843
/* wait votes from all nodes */
838-
while (!ts->votingCompleted && !(result & WL_TIMEOUT))
844+
while (!ts->votingCompleted && start + transTimeout >= MtmGetSystemTime())
839845
{
840846
MtmUnlock();
841847
MtmWatchdog();
@@ -844,7 +850,7 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
844850
x->status = TRANSACTION_STATUS_ABORTED;
845851
return;
846852
}
847-
result = WaitLatch(&MyProc->procLatch, WL_LATCH_SET|WL_TIMEOUT, transTimeout);
853+
result = WaitLatch(&MyProc->procLatch, WL_LATCH_SET|WL_TIMEOUT, MtmHeartbeatRecvTimeout);
848854
if (result & WL_LATCH_SET) {
849855
ResetLatch(&MyProc->procLatch);
850856
}
@@ -1568,6 +1574,7 @@ static void MtmInitialize()
15681574
Mtm->recoverySlot = 0;
15691575
Mtm->locks = GetNamedLWLockTranche(MULTIMASTER_NAME);
15701576
Mtm->csn = MtmGetCurrentTime();
1577+
Mtm->lastClusterStatusUpdate = MtmGetSystemTime();
15711578
Mtm->lastCsn = INVALID_CSN;
15721579
Mtm->oldestXid = FirstNormalTransactionId;
15731580
Mtm->nLiveNodes = MtmNodes;

multimaster.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ typedef struct
189189
This list is expected to be in CSN ascending order, by strict order may be violated */
190190
uint64 transCount; /* Counter of transactions perfromed by this node */
191191
uint64 gcCount; /* Number of global transactions performed since last GC */
192-
BgwPool pool; /* Pool of background workers for applying logical replication patches */
192+
timestamp_t lastClusterStatusUpdate;/* Time of last update of cluster status */
193+
BgwPool pool; /* Pool of background workers for applying logical replication patches */
193194
MtmNodeInfo nodes[1]; /* [Mtm->nAllNodes]: per-node data */
194195
} MtmState;
195196

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy