swap file name pid expansion removed. Not suited for mission critical software...

This commit is contained in:
antirez 2010-05-07 09:36:37 +02:00
parent 8b5bb414f1
commit a0e7e5f516
3 changed files with 32 additions and 28 deletions

18
redis.c
View File

@ -4485,7 +4485,6 @@ static void shutdownCommand(redisClient *c) {
unlink(server.pidfile);
redisLog(REDIS_WARNING,"%zu bytes used at exit",zmalloc_used_memory());
redisLog(REDIS_WARNING,"Server exit now, bye bye...");
if (server.vm_enabled) unlink(server.vm_swap_file);
exit(0);
} else {
/* Ooops.. error saving! The best we can do is to continue
@ -8584,22 +8583,6 @@ static void aofRemoveTempFile(pid_t childpid) {
/* =================== Virtual Memory - Blocking Side ====================== */
/* substitute the first occurrence of '%p' with the process pid in the
* swap file name. */
static void expandVmSwapFilename(void) {
char *p = strstr(server.vm_swap_file,"%p");
sds new;
if (!p) return;
new = sdsempty();
*p = '\0';
new = sdscat(new,server.vm_swap_file);
new = sdscatprintf(new,"%ld",(long) getpid());
new = sdscat(new,p+2);
zfree(server.vm_swap_file);
server.vm_swap_file = new;
}
static void vmInit(void) {
off_t totsize;
int pipefds[2];
@ -8609,7 +8592,6 @@ static void vmInit(void) {
if (server.vm_max_threads != 0)
zmalloc_enable_thread_safeness(); /* we need thread safe zmalloc() */
expandVmSwapFilename();
redisLog(REDIS_NOTICE,"Using '%s' as swap file",server.vm_swap_file);
/* Try to open the old swap file, otherwise create it */
if ((server.vm_fp = fopen(server.vm_swap_file,"r+b")) == NULL) {

View File

@ -206,20 +206,16 @@ vm-enabled no
# This is the path of the Redis swap file. As you can guess, swap files
# can't be shared by different Redis instances, so make sure to use a swap
# file for every redis process you are running.
# file for every redis process you are running. Redis will complain if the
# swap file is already in use.
#
# The swap file name may contain "%p" that is substituted with the PID of
# the Redis process, so the default name /tmp/redis-%p.vm will work even
# with multiple instances as Redis will use, for example, redis-811.vm
# for one instance and redis-593.vm for another one.
#
# Useless to say, the best kind of disk for a Redis swap file (that's accessed
# at random) is a Solid State Disk (SSD).
# The best kind of storage for the Redis swap file (that's accessed at random)
# is a Solid State Disk (SSD).
#
# *** WARNING *** if you are using a shared hosting the default of putting
# the swap file under /tmp is not secure. Create a dir with access granted
# only to Redis user and configure Redis to create the swap file there.
vm-swap-file /tmp/redis-%p.vm
vm-swap-file /tmp/redis.swap
# vm-max-memory configures the VM to use at max the specified amount of
# RAM. Everything that deos not fit will be swapped on disk *if* possible, that

View File

@ -1,6 +1,7 @@
static struct redisFunctionSym symsTable[] = {
{"IOThreadEntryPoint",(unsigned long)IOThreadEntryPoint},
{"_redisAssert",(unsigned long)_redisAssert},
{"_redisPanic",(unsigned long)_redisPanic},
{"acceptHandler",(unsigned long)acceptHandler},
{"addReply",(unsigned long)addReply},
{"addReplyBulk",(unsigned long)addReplyBulk},
@ -41,6 +42,7 @@ static struct redisFunctionSym symsTable[] = {
{"createSharedObjects",(unsigned long)createSharedObjects},
{"createSortOperation",(unsigned long)createSortOperation},
{"createStringObject",(unsigned long)createStringObject},
{"createStringObjectFromLongLong",(unsigned long)createStringObjectFromLongLong},
{"createZsetObject",(unsigned long)createZsetObject},
{"daemonize",(unsigned long)daemonize},
{"dbsizeCommand",(unsigned long)dbsizeCommand},
@ -63,14 +65,15 @@ static struct redisFunctionSym symsTable[] = {
{"dupStringObject",(unsigned long)dupStringObject},
{"echoCommand",(unsigned long)echoCommand},
{"execCommand",(unsigned long)execCommand},
{"execCommandReplicateMulti",(unsigned long)execCommandReplicateMulti},
{"existsCommand",(unsigned long)existsCommand},
{"expandVmSwapFilename",(unsigned long)expandVmSwapFilename},
{"expireCommand",(unsigned long)expireCommand},
{"expireGenericCommand",(unsigned long)expireGenericCommand},
{"expireIfNeeded",(unsigned long)expireIfNeeded},
{"expireatCommand",(unsigned long)expireatCommand},
{"feedAppendOnlyFile",(unsigned long)feedAppendOnlyFile},
{"findFuncName",(unsigned long)findFuncName},
{"flushAppendOnlyFile",(unsigned long)flushAppendOnlyFile},
{"flushallCommand",(unsigned long)flushallCommand},
{"flushdbCommand",(unsigned long)flushdbCommand},
{"freeClient",(unsigned long)freeClient},
@ -94,13 +97,29 @@ static struct redisFunctionSym symsTable[] = {
{"genericZrangebyscoreCommand",(unsigned long)genericZrangebyscoreCommand},
{"getCommand",(unsigned long)getCommand},
{"getDecodedObject",(unsigned long)getDecodedObject},
{"getDoubleFromObject",(unsigned long)getDoubleFromObject},
{"getDoubleFromObjectOrReply",(unsigned long)getDoubleFromObjectOrReply},
{"getExpire",(unsigned long)getExpire},
{"getGenericCommand",(unsigned long)getGenericCommand},
{"getLongFromObjectOrReply",(unsigned long)getLongFromObjectOrReply},
{"getLongLongFromObject",(unsigned long)getLongLongFromObject},
{"getLongLongFromObjectOrReply",(unsigned long)getLongLongFromObjectOrReply},
{"getMcontextEip",(unsigned long)getMcontextEip},
{"getsetCommand",(unsigned long)getsetCommand},
{"glueReplyBuffersIfNeeded",(unsigned long)glueReplyBuffersIfNeeded},
{"handleClientsBlockedOnSwappedKey",(unsigned long)handleClientsBlockedOnSwappedKey},
{"handleClientsWaitingListPush",(unsigned long)handleClientsWaitingListPush},
{"hashCurrent",(unsigned long)hashCurrent},
{"hashDelete",(unsigned long)hashDelete},
{"hashExists",(unsigned long)hashExists},
{"hashGet",(unsigned long)hashGet},
{"hashInitIterator",(unsigned long)hashInitIterator},
{"hashLookupWriteOrCreate",(unsigned long)hashLookupWriteOrCreate},
{"hashNext",(unsigned long)hashNext},
{"hashReleaseIterator",(unsigned long)hashReleaseIterator},
{"hashSet",(unsigned long)hashSet},
{"hashTryConversion",(unsigned long)hashTryConversion},
{"hashTryObjectEncoding",(unsigned long)hashTryObjectEncoding},
{"hdelCommand",(unsigned long)hdelCommand},
{"hexistsCommand",(unsigned long)hexistsCommand},
{"hgetCommand",(unsigned long)hgetCommand},
@ -108,13 +127,17 @@ static struct redisFunctionSym symsTable[] = {
{"hincrbyCommand",(unsigned long)hincrbyCommand},
{"hkeysCommand",(unsigned long)hkeysCommand},
{"hlenCommand",(unsigned long)hlenCommand},
{"hmgetCommand",(unsigned long)hmgetCommand},
{"hmsetCommand",(unsigned long)hmsetCommand},
{"hsetCommand",(unsigned long)hsetCommand},
{"hsetnxCommand",(unsigned long)hsetnxCommand},
{"htNeedsResize",(unsigned long)htNeedsResize},
{"hvalsCommand",(unsigned long)hvalsCommand},
{"incrCommand",(unsigned long)incrCommand},
{"incrDecrCommand",(unsigned long)incrDecrCommand},
{"incrRefCount",(unsigned long)incrRefCount},
{"incrbyCommand",(unsigned long)incrbyCommand},
{"incrementallyRehash",(unsigned long)incrementallyRehash},
{"infoCommand",(unsigned long)infoCommand},
{"initClientMultiState",(unsigned long)initClientMultiState},
{"initServer",(unsigned long)initServer},
@ -197,6 +220,7 @@ static struct redisFunctionSym symsTable[] = {
{"renameCommand",(unsigned long)renameCommand},
{"renameGenericCommand",(unsigned long)renameGenericCommand},
{"renamenxCommand",(unsigned long)renamenxCommand},
{"replicationFeedMonitors",(unsigned long)replicationFeedMonitors},
{"replicationFeedSlaves",(unsigned long)replicationFeedSlaves},
{"resetClient",(unsigned long)resetClient},
{"resetServerSaveParams",(unsigned long)resetServerSaveParams},
@ -211,6 +235,7 @@ static struct redisFunctionSym symsTable[] = {
{"sdiffCommand",(unsigned long)sdiffCommand},
{"sdiffstoreCommand",(unsigned long)sdiffstoreCommand},
{"sdsDictKeyCompare",(unsigned long)sdsDictKeyCompare},
{"sdscatrepr",(unsigned long)sdscatrepr},
{"segvHandler",(unsigned long)segvHandler},
{"selectCommand",(unsigned long)selectCommand},
{"selectDb",(unsigned long)selectDb},
@ -221,6 +246,7 @@ static struct redisFunctionSym symsTable[] = {
{"setCommand",(unsigned long)setCommand},
{"setExpire",(unsigned long)setExpire},
{"setGenericCommand",(unsigned long)setGenericCommand},
{"setexCommand",(unsigned long)setexCommand},
{"setnxCommand",(unsigned long)setnxCommand},
{"setupSigSegvAction",(unsigned long)setupSigSegvAction},
{"shutdownCommand",(unsigned long)shutdownCommand},