提交 46f3a9c0 编写于 作者: E Enrico Giordani

[Fix] Duplicated sockets management for diskless replication.

上级 5ebdc7e3
......@@ -354,16 +354,17 @@ BOOL QForkChildInit(HANDLE QForkControlMemoryMapHandle, DWORD ParentProcessID) {
} else if (g_pQForkControl->typeOfOperation == OperationType::otSocket) {
LPWSAPROTOCOL_INFO lpProtocolInfo = (LPWSAPROTOCOL_INFO) g_pQForkControl->globalData.protocolInfo;
int pipe_write_fd = FDAPI_open_osfhandle((intptr_t) g_pQForkControl->globalData.pipe_write_handle, _O_APPEND);
int* fds = (int*) malloc(sizeof(int) * g_pQForkControl->globalData.numfds);
for (int i = 0; i < g_pQForkControl->globalData.numfds; i++) {
g_pQForkControl->globalData.fds[i] = FDAPI_WSASocket(FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO,
&lpProtocolInfo[i],
0,
WSA_FLAG_OVERLAPPED);
fds[i] = FDAPI_WSASocket(FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO,
&lpProtocolInfo[i],
0,
WSA_FLAG_OVERLAPPED);
}
g_ChildExitCode = do_socketSave(g_pQForkControl->globalData.fds,
g_ChildExitCode = do_socketSave(fds,
g_pQForkControl->globalData.numfds,
g_pQForkControl->globalData.clientids,
pipe_write_fd);
......@@ -371,8 +372,9 @@ BOOL QForkChildInit(HANDLE QForkControlMemoryMapHandle, DWORD ParentProcessID) {
// Failing to close the sockets properly will produce a socket read error
// on both the parent process and the slave.
for (int i = 0; i < g_pQForkControl->globalData.numfds; i++) {
FDAPI_CloseDuplicatedSocket(g_pQForkControl->globalData.fds[i]);
FDAPI_CloseDuplicatedSocket(fds[i]);
}
free(fds);
} else {
throw runtime_error("unexpected operation type");
}
......
......@@ -21,6 +21,7 @@
*/
#include "..\redis.h"
#include "Win32_Portability.h"
void SetupRedisGlobals(LPVOID redisData, size_t redisDataSize, uint32_t dictHashSeed)
{
......@@ -74,12 +75,13 @@ int do_rdbSaveToSlavesSockets(int *fds, int numfds, uint64_t *clientids)
server.rdb_child_pid = GetCurrentProcessId();
rioInitWithFdset(&slave_sockets,fds,numfds);
zfree(fds);
// On Windows we need to use the fds after do_socketSave2 has finished
// so we don't free them here, moreover since we allocate the fds in
// QFork.cpp it's better to use malloc instead of zmalloc.
POSIX_ONLY(zfree(fds););
// On Windows we haven't duplicated the listening sockets so we shouldn't close them
#ifndef _WIN32
closeListeningSockets(0);
#endif
POSIX_ONLY(closeListeningSockets(0);)
redisSetProcTitle("redis-rdb-to-slaves");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册