提交 f52ce3c2 编写于 作者: J jonathan pickett

added heapdir directive to allow for configuration of where QFork memory mapped file lives

上级 c6c93699
......@@ -289,7 +289,9 @@ slave-priority 100
# be shared with a child process.
#
# *** There must be disk space available for this file in order for Redis
# to launch. ***
# to launch. *** The default configuration places this file in the local
# appdata directory. If you wish to move this file to another local disk,
# use the heapdir flag as described below.
#
# The maxheap flag controls the maximum size of this memory mapped file,
# as well as the total usable space for the Redis heap. Running Redis
......@@ -314,6 +316,17 @@ slave-priority 100
#
# maxheap <bytes>
# The heap memory mapped file must reside on a local path for heap sharing
# between processes to work. A UNC path will not suffice here. For maximum
# performance this should be located on the fastest local drive available.
# This value defaults to the local application data folder(e.g.,
# "%USERPROFILE%\AppData\Local"). Since this file can be very large, you
# may wish to place this on a drive other than the one the operating system
# is installed on.
#
# Note that you must specify a directory here, not a file name.
# heapdir <directory path(absolute or relative)>
# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys
# accordingly to the eviction policy selected (see maxmemmory-policy).
......
......@@ -353,6 +353,7 @@ static RedisParamterMapper g_redisArgMap =
// QFork flags
{ cQFork, &fp2 }, // qfork [QForkConrolMemoryMap handle] [parent process id]
{ cMaxHeap, &fp1 }, // maxheap [number]
{ cHeapDir, &fp1 }, // heapdir [path]
// service commands
{ cServiceName, &fp1 }, // service-name [name]
......
......@@ -51,6 +51,7 @@ const string cSyslogIdent= "syslog-ident";
const string cLogfile = "logfile";
const string cInclude = "include";
const string cDir = "dir";
const string cHeapDir = "heapdir";
const string cMaxHeap = "maxheap";
const string cMaxMemory = "maxmemory";
......
......@@ -25,6 +25,8 @@
#include <stdio.h>
#include <wchar.h>
#include <Psapi.h>
#include <ShlObj.h>
#include <Shlwapi.h>
#define QFORK_MAIN_IMPL
#include "Win32_QFork.h"
......@@ -332,16 +334,41 @@ BOOL QForkSlaveInit(HANDLE QForkConrolMemoryMapHandle, DWORD ParentProcessID) {
return FALSE;
}
string g_MMFDir;
string GetWorkingDirectory() {
string workingDir = ".\\";
if (g_argMap.find(cDir) != g_argMap.end()) {
workingDir = g_argMap[cDir][0][0];
}
std::replace(workingDir.begin(), workingDir.end(), '/', '\\');
if (workingDir.at(workingDir.length() - 1) != '\\') {
workingDir = workingDir.append("\\");
if (g_MMFDir.length() == 0) {
char defaultDir[_MAX_PATH];
HRESULT hr;
if (S_OK != (hr = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, defaultDir))) {
throw std::system_error(hr,system_category(),"SHGetFolderPathA failed");
}
string workingDir = defaultDir;
if (g_argMap.find(cHeapDir) != g_argMap.end()) {
workingDir = g_argMap[cHeapDir][0][0];
std::replace(workingDir.begin(), workingDir.end(), '/', '\\');
if (PathIsRelativeA(workingDir.c_str())) {
char cwd[MAX_PATH];
if (0 == ::GetCurrentDirectoryA(MAX_PATH, cwd)) {
throw std::system_error(GetLastError(), system_category(), "GetCurrentDirectoryA failed");
}
char fullPath[_MAX_PATH];
if (NULL == PathCombineA(fullPath, cwd, workingDir.c_str())) {
throw std::system_error(GetLastError(), system_category(), "PathCombineA failed");
}
workingDir = fullPath;
}
}
if (workingDir.at(workingDir.length() - 1) != '\\') {
workingDir = workingDir.append("\\");
}
g_MMFDir = workingDir;
}
return workingDir;
return g_MMFDir;
}
BOOL QForkMasterInit( __int64 maxheapBytes ) {
......
......@@ -522,7 +522,9 @@ void loadServerConfigFromString(char *config) {
#ifdef _WIN32
} else if (!strcasecmp(argv[0],"maxheap")) {
// ignore. This is taken care of in the qfork code.
} else if (!strcasecmp(argv[0],"service-name")) {
} else if (!strcasecmp(argv[0], "heapdir")) {
// ignore. This is taken care of in the qfork code.
} else if (!strcasecmp(argv[0], "service-name")) {
// ignore. This is taken care of in the win32_service code.
#endif
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册