Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7952632

Browse files
committed
handcrafted fairness for MtmCommitBarrier LWLock
1 parent dd9b26b commit 7952632

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

src/commit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ MtmTwoPhaseCommit(MtmCurrentTrans* x)
163163
*
164164
* See also comments at the end of MtmReplicationStartupHook().
165165
*/
166+
while (Mtm->stop_new_commits)
167+
MtmSleep(USECS_PER_SEC);
168+
166169
LWLockAcquire(MtmCommitBarrier, LW_SHARED);
167170

168171
MtmLock(LW_SHARED);

src/include/multimaster.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ typedef struct
126126
typedef struct
127127
{
128128
bool extension_created;
129+
bool stop_new_commits;
129130
bool recovered;
130131
MtmNodeStatus status; /* Status of this node */
131132
char *statusReason; /* A human-readable description of why the current status was set */

src/multimaster.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ static void MtmInitialize()
565565
{
566566
MemSet(Mtm, 0, sizeof(MtmState) + sizeof(MtmNodeInfo)*(MtmMaxNodes-1));
567567
Mtm->extension_created = false;
568+
Mtm->stop_new_commits = false;
568569
Mtm->recovered = false;
569570
Mtm->status = MTM_DISABLED; //MTM_INITIALIZATION;
570571
Mtm->recoverySlot = 0;

src/pglogical_proto.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,12 @@ MtmReplicationStartupHook(struct PGLogicalStartupHookArgs* args)
836836
XLogRecPtr msg_xptr;
837837
char *session_id = psprintf(INT64_FORMAT, hooks_data->session_id);
838838

839+
Mtm->stop_new_commits = true;
839840
LWLockAcquire(MtmCommitBarrier, LW_EXCLUSIVE);
840841
MtmStateProcessNeighborEvent(MtmReplicationNodeId, MTM_NEIGHBOR_WAL_SENDER_START_RECOVERED, false);
841842
msg_xptr = LogLogicalMessage("P", session_id, strlen(session_id) + 1, false);
842843
LWLockRelease(MtmCommitBarrier);
844+
Mtm->stop_new_commits = false;
843845

844846
XLogFlush(msg_xptr);
845847
}

tests/docker-entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ if [ "$1" = 'postgres' ]; then
5959
shared_preload_libraries = 'multimaster'
6060
log_line_prefix = '%m [%p]: '
6161
wal_writer_delay = 500ms
62+
archive_mode = on
63+
archive_command = '/bin/false'
6264
# log_statement = all
6365
6466
multimaster.max_nodes = 3

0 commit comments

Comments
 (0)