Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2c0a6d6

Browse files
committedNov 12, 2017
fix arbiter port assignment logic
1 parent 689b326 commit 2c0a6d6

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed
 

‎arbiter.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,7 @@ static void MtmOpenConnections()
507507
}
508508
for (i = 0; i < nNodes; i++) {
509509
if (i+1 != MtmNodeId && i < Mtm->nAllNodes) {
510-
int arbiterPort = Mtm->nodes[i].con.arbiterPort;
511-
if (arbiterPort == 0) {
512-
arbiterPort = MtmArbiterPort + i + 1;
513-
}
514-
sockets[i] = MtmConnectSocket(i, arbiterPort, MtmConnectTimeout);
510+
sockets[i] = MtmConnectSocket(i, Mtm->nodes[i].con.arbiterPort, MtmConnectTimeout);
515511
if (sockets[i] < 0) {
516512
MtmOnNodeDisconnect(i+1);
517513
}
@@ -542,13 +538,13 @@ static bool MtmSendToNode(int node, void const* buf, int size)
542538
BIT_CLEAR(Mtm->reconnectMask, node);
543539
MtmUnlock();
544540
}
545-
if (sockets[node] < 0 || !MtmWriteSocket(sockets[node], buf, size)) {
541+
if (sockets[node] < 0 || !MtmWriteSocket(sockets[node], buf, size)) {
546542
if (sockets[node] >= 0) {
547543
elog(WARNING, "Arbiter fail to write to node %d: %d", node+1, errno);
548544
close(sockets[node]);
549545
sockets[node] = -1;
550546
}
551-
sockets[node] = MtmConnectSocket(node, MtmArbiterPort + node + 1, MtmReconnectTimeout);
547+
sockets[node] = MtmConnectSocket(node, Mtm->nodes[node].con.arbiterPort, MtmReconnectTimeout);
552548
if (sockets[node] < 0) {
553549
MtmOnNodeDisconnect(node+1);
554550
result = false;
@@ -638,7 +634,7 @@ static void MtmAcceptIncomingConnections()
638634
}
639635
sock_inet.sin_family = AF_INET;
640636
sock_inet.sin_addr.s_addr = htonl(INADDR_ANY);
641-
sock_inet.sin_port = htons(MtmArbiterPort + MtmNodeId);
637+
sock_inet.sin_port = htons(MtmArbiterPort);
642638

643639
gateway = socket(sock_inet.sin_family, SOCK_STREAM, 0);
644640
if (gateway < 0) {

‎multimaster.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -2161,8 +2161,10 @@ void MtmUpdateNodeConnectionInfo(MtmConnectionInfo* conn, char const* connStr)
21612161
elog(ERROR, "Invalid arbiter port: %s", port+12);
21622162
}
21632163
} else {
2164-
conn->arbiterPort = 0;
2164+
conn->arbiterPort = MULTIMASTER_DEFAULT_ARBITER_PORT;
21652165
}
2166+
2167+
elog(WARNING, "Using arbiter port: %d", conn->arbiterPort);
21662168
}
21672169

21682170
static void MtmSplitConnStrs(void)
@@ -2647,7 +2649,7 @@ _PG_init(void)
26472649
"Base value for assigning arbiter ports",
26482650
NULL,
26492651
&MtmArbiterPort,
2650-
54320,
2652+
MULTIMASTER_DEFAULT_ARBITER_PORT,
26512653
0,
26522654
INT_MAX,
26532655
PGC_BACKEND,

‎multimaster.h

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#define MULTIMASTER_BROADCAST_SERVICE "mtm_broadcast"
5959
#define MULTIMASTER_ADMIN "mtm_admin"
6060

61+
#define MULTIMASTER_DEFAULT_ARBITER_PORT 5433
62+
6163
#define MB (1024*1024L)
6264

6365
#define USEC_TO_MSEC(t) ((t)/1000)

‎tests2/docker-compose.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
POSTGRES_USER: 'pg'
1111
POSTGRES_DB: 'regression'
1212
NODE_ID: 1
13-
CONNSTR: |
13+
CONNSTRS: >-
1414
dbname=regression user=pg host=node1 arbiterport=5433,
1515
dbname=regression user=pg host=toxi port=12000 arbiterport=12001,
1616
dbname=regression user=pg host=toxi port=13000 arbiterport=13001
@@ -25,7 +25,7 @@ services:
2525
POSTGRES_USER: 'pg'
2626
POSTGRES_DB: 'regression'
2727
NODE_ID: 2
28-
CONNSTR: |
28+
CONNSTRS: >-
2929
dbname=regression user=pg host=toxi port=21000 arbiterport=21001,
3030
dbname=regression user=pg host=node2 arbiterport=5433,
3131
dbname=regression user=pg host=toxi port=23000 arbiterport=23001
@@ -40,7 +40,7 @@ services:
4040
POSTGRES_USER: 'pg'
4141
POSTGRES_DB: 'regression'
4242
NODE_ID: 3
43-
CONNSTR: |
43+
CONNSTRS: >-
4444
dbname=regression user=pg host=toxi port=31000 arbiterport=31001,
4545
dbname=regression user=pg host=toxi port=32000 arbiterport=32001,
4646
dbname=regression user=pg host=node3 arbiterport=5433

‎tests2/docker-entrypoint.sh

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ if [ "$1" = 'postgres' ]; then
7070
multimaster.twopc_min_timeout = 400000
7171
EOF
7272

73+
cat $PGDATA/postgresql.conf
74+
7375
pg_ctl -D "$PGDATA" -m fast -w stop
7476
fi
7577
fi

‎tests2/test_regression.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class RecoveryTest(unittest.TestCase):
88
def setUpClass(self):
99
subprocess.check_call(['docker-compose','up',
1010
'--force-recreate',
11+
'--build',
1112
'-d'])
1213

1314
@classmethod

0 commit comments

Comments
 (0)
Please sign in to comment.