Skip to content

Commit f3c0e4e

Browse files
committed
fix arbiter socket after failed connect()
1 parent bfa7286 commit f3c0e4e

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

contrib/mmts/arbiter.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,30 +243,34 @@ static int MtmConnectSocket(char const* host, int port, int max_attempts)
243243
if (!MtmResolveHostByName(host, addrs, &n_addrs)) {
244244
elog(ERROR, "Arbiter failed to resolve host '%s' by name", host);
245245
}
246-
Retry:
247-
sd = socket(AF_INET, SOCK_STREAM, 0);
248-
if (sd < 0) {
249-
elog(ERROR, "Arbiter failed to create socket: %d", errno);
250-
}
246+
247+
Retry:
248+
251249
while (1) {
252250
int rc = -1;
251+
252+
sd = socket(AF_INET, SOCK_STREAM, 0);
253+
if (sd < 0) {
254+
elog(ERROR, "Arbiter failed to create socket: %d", errno);
255+
}
253256
for (i = 0; i < n_addrs; ++i) {
254257
memcpy(&sock_inet.sin_addr, &addrs[i], sizeof sock_inet.sin_addr);
255258
do {
256259
rc = connect(sd, (struct sockaddr*)&sock_inet, sizeof(sock_inet));
257260
} while (rc < 0 && errno == EINTR);
258-
261+
259262
if (rc >= 0 || errno == EINPROGRESS) {
260263
break;
261264
}
262265
}
263266
if (rc < 0) {
264267
if ((errno != ENOENT && errno != ECONNREFUSED && errno != EINPROGRESS) || max_attempts == 0) {
265-
elog(WARNING, "Arbiter failed to connect to %s:%d: %d", host, port, errno);
268+
elog(WARNING, "Arbiter failed to connect to %s:%d: error=%d", host, port, errno);
266269
return -1;
267270
} else {
268271
max_attempts -= 1;
269-
MtmSleep(MtmConnectTimeout);
272+
elog(WARNING, "Arbiter trying to connect to %s:%d: error=%d", host, port, errno);
273+
MtmSleep(5*MtmConnectTimeout);
270274
}
271275
continue;
272276
} else {

contrib/mmts/tests/pg_hba.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,7 @@ host all all ::1/128 trust
9090
# replication privilege.
9191
local replication knizhnik trust
9292
host replication knizhnik 127.0.0.1/32 trust
93+
local replication stas trust
94+
host replication stas ::1/128 trust
95+
host replication stas 127.0.0.1/32 trust
9396
#host replication knizhnik ::1/128 trust

contrib/mmts/tests/postgresql.conf.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,4 @@
625625
# Add settings for extensions here
626626

627627
multimaster.workers=8
628-
multimaster.queue_size=1073741824
628+
multimaster.queue_size=104857600 # 100mb

contrib/mmts/tests/reinit-mm.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ export PATH=~/code/postgres_cluster/install/bin/:$PATH
33
ulimit -c unlimited
44
pkill -9 postgres
55
pkill -9 arbiter
6+
7+
cd ~/code/postgres_cluster/contrib/mmts/
8+
make install
9+
cd ~/code/postgres_cluster/contrib/mmts/tests
10+
11+
612
rm -fr node? *.log dtm
713
mkdir dtm
814
conn_str=""
@@ -28,9 +34,10 @@ do
2834
echo "multimaster.conn_strings = '$conn_str'" >> node$i/postgresql.conf
2935
echo "multimaster.node_id = $i" >> node$i/postgresql.conf
3036
cp pg_hba.conf node$i
31-
pg_ctl -D node$i -l node$i.log start
37+
pg_ctl -w -D node$i -l node$i.log start
3238
done
3339

34-
sleep 5
40+
# sleep 5
41+
# psql -c "create extension multimaster;" postgres
3542

3643
echo Done

0 commit comments

Comments
 (0)