Skip to content
Snippets Groups Projects
Commit 3f77b5ab authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Fix broken recovery bootstrap.

The code responsible for writing into a socket
in blocking mode was broken. And the socket was non-blocking
to begin with.
parent 4d2cdd71
No related branches found
No related tags found
No related merge requests found
......@@ -745,6 +745,8 @@ replication_relay_loop()
ev_io_init(&sock_read_ev, replication_relay_recv,
relay.sock, EV_READ);
ev_io_start(loop(), &sock_read_ev);
/** Turn off the non-blocking mode,if any. */
sio_setfl(relay.sock, O_NONBLOCK, 0);
/* Initialize the recovery process */
recovery_init(cfg_snap_dir, cfg_wal_dir,
......
......@@ -293,6 +293,33 @@ sio_writev(int fd, const struct iovec *iov, int iovcnt)
return n;
}
/** Blocking I/O writev */
ssize_t
sio_writev_all(int fd, struct iovec *iov, int iovcnt)
{
ssize_t bytes_total = 0;
struct iovec *iovend = iov + iovcnt;
while(1) {
int cnt = iovend - iov;
if (cnt > IOV_MAX)
cnt = IOV_MAX;
ssize_t bytes_written = writev(fd, iov, cnt);
if (bytes_written < 0) {
if (errno == EINTR)
continue;
tnt_raise(SocketError, fd, "writev(%d)", cnt);
}
bytes_total += bytes_written;
while (bytes_written >= iov->iov_len)
bytes_written -= (iov++)->iov_len;
if (iov == iovend)
break;
iov->iov_base = (char *) iov->iov_base + bytes_written;
iov->iov_len -= bytes_written;
}
return bytes_total;
}
ssize_t
sio_readn_ahead(int fd, void *buf, size_t count, size_t buf_size)
{
......
......@@ -118,24 +118,8 @@ ssize_t
sio_writen(int fd, const void *buf, size_t count);
/* Only for blocked I/O */
static inline ssize_t
sio_writev_all(int fd, struct iovec *iov, int iovcnt)
{
ssize_t bytes_total = 0;
struct iovec *iovend = iov + iovcnt;
while(1) {
ssize_t bytes_written = sio_writev(fd, iov, iovend - iov);
bytes_total += bytes_written;
while (bytes_written > 0 && bytes_written >= iov->iov_len)
bytes_written -= (iov++)->iov_len;
if (iov == iovend)
break;
iov->iov_base = (char *) iov->iov_base + bytes_written;
iov->iov_len -= bytes_written;
}
return bytes_total;
}
ssize_t
sio_writev_all(int fd, struct iovec *iov, int iovcnt);
/**
* A wrapper over sendfile.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment