Called in diskless master, when there's data to read from the child's rdb pipe */
| 1979 | |
| 1980 | /* Called in diskless master, when there's data to read from the child's rdb pipe */ |
| 1981 | void rdbPipeReadHandler(struct aeEventLoop *eventLoop, int fd, void *clientData, int mask) { |
| 1982 | UNUSED(mask); |
| 1983 | UNUSED(clientData); |
| 1984 | |
| 1985 | int i; |
| 1986 | if (!g_pserver->rdb_pipe_buff) |
| 1987 | g_pserver->rdb_pipe_buff = (char*)zmalloc(PROTO_IOBUF_LEN); |
| 1988 | serverAssert(g_pserver->rdb_pipe_numconns_writing==0); |
| 1989 | serverAssert(eventLoop == g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el); |
| 1990 | |
| 1991 | while (1) { |
| 1992 | g_pserver->rdb_pipe_bufflen = read(fd, g_pserver->rdb_pipe_buff, PROTO_IOBUF_LEN); |
| 1993 | if (g_pserver->rdb_pipe_bufflen < 0) { |
| 1994 | if (errno == EAGAIN || errno == EWOULDBLOCK) |
| 1995 | return; |
| 1996 | serverLog(LL_WARNING,"Diskless rdb transfer, read error sending DB to replicas: %s", strerror(errno)); |
| 1997 | for (i=0; i < g_pserver->rdb_pipe_numconns; i++) { |
| 1998 | connection *conn = g_pserver->rdb_pipe_conns[i]; |
| 1999 | if (!conn) |
| 2000 | continue; |
| 2001 | client *slave = (client*)connGetPrivateData(conn); |
| 2002 | freeClientAsync(slave); |
| 2003 | g_pserver->rdb_pipe_conns[i] = NULL; |
| 2004 | } |
| 2005 | killRDBChild(); |
| 2006 | return; |
| 2007 | } |
| 2008 | |
| 2009 | if (g_pserver->rdb_pipe_bufflen == 0 && !g_pserver->rdbThreadVars.fRdbThreadCancel) { |
| 2010 | /* EOF - write end was closed. */ |
| 2011 | int stillUp = 0; |
| 2012 | aeDeleteFileEvent(eventLoop, g_pserver->rdb_pipe_read, AE_READABLE); |
| 2013 | for (i=0; i < g_pserver->rdb_pipe_numconns; i++) |
| 2014 | { |
| 2015 | connection *conn = g_pserver->rdb_pipe_conns[i]; |
| 2016 | if (!conn) |
| 2017 | continue; |
| 2018 | stillUp++; |
| 2019 | } |
| 2020 | serverLog(LL_WARNING,"Diskless rdb transfer, done reading from pipe, %d replicas still up.", stillUp); |
| 2021 | /* Now that the replicas have finished reading, notify the child that it's safe to exit. |
| 2022 | * When the server detectes the child has exited, it can mark the replica as online, and |
| 2023 | * start streaming the replication buffers. */ |
| 2024 | close(g_pserver->rdb_child_exit_pipe); |
| 2025 | g_pserver->rdb_child_exit_pipe = -1; |
| 2026 | return; |
| 2027 | } |
| 2028 | |
| 2029 | int stillAlive = 0; |
| 2030 | for (i=0; i < g_pserver->rdb_pipe_numconns; i++) |
| 2031 | { |
| 2032 | int nwritten; |
| 2033 | connection *conn = g_pserver->rdb_pipe_conns[i]; |
| 2034 | if (!conn) |
| 2035 | continue; |
| 2036 | |
| 2037 | client *slave = (client*)connGetPrivateData(conn); |
| 2038 | std::unique_lock<fastlock> ul(slave->lock); |
nothing calls this directly
no test coverage detected