X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/05e06e154332cf107d30092dddb94b6b35967ce5..2861cd84f9035f887715da8f51a622b8b5dfe306:/src/redis.c diff --git a/src/redis.c b/src/redis.c index aa5a73f2..9cdca553 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2010, Salvatore Sanfilippo + * Copyright (c) 2009-2012, Salvatore Sanfilippo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -110,6 +110,7 @@ struct redisCommand *commandTable; * t: Allow command while a slave has stale data but is not allowed to * server this data. Normally no command is accepted in this condition * but just a few. + * M: Do not automatically propagate the command on MONITOR. */ struct redisCommand redisCommandTable[] = { {"get",getCommand,2,"r",0,NULL,1,1,1,0,0}, @@ -216,7 +217,7 @@ struct redisCommand redisCommandTable[] = { {"lastsave",lastsaveCommand,1,"r",0,NULL,0,0,0,0,0}, {"type",typeCommand,2,"r",0,NULL,1,1,1,0,0}, {"multi",multiCommand,1,"rs",0,NULL,0,0,0,0,0}, - {"exec",execCommand,1,"s",0,NULL,0,0,0,0,0}, + {"exec",execCommand,1,"sM",0,NULL,0,0,0,0,0}, {"discard",discardCommand,1,"rs",0,NULL,0,0,0,0,0}, {"sync",syncCommand,1,"ars",0,NULL,0,0,0,0,0}, {"replconf",replconfCommand,-1,"ars",0,NULL,0,0,0,0,0}, @@ -901,8 +902,12 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { if (pid == server.rdb_child_pid) { backgroundSaveDoneHandler(exitcode,bysignal); - } else { + } else if (pid == server.aof_child_pid) { backgroundRewriteDoneHandler(exitcode,bysignal); + } else { + redisLog(REDIS_WARNING, + "Warning, detected child with unmatched pid: %ld", + (long)pid); } updateDictResizePolicy(); } @@ -1328,11 +1333,11 @@ void initServer() { /* 32 bit instances are limited to 4GB of address space, so if there is * no explicit limit in the user provided configuration we set a limit - * at 3.5GB using maxmemory with 'noeviction' policy'. This saves - * useless crashes of the Redis instance. */ + * at 3 GB using maxmemory with 'noeviction' policy'. This avoids + * useless crashes of the Redis instance for out of memory. */ if (server.arch_bits == 32 && server.maxmemory == 0) { - redisLog(REDIS_WARNING,"Warning: 32 bit instance detected but no memory limit set. Setting 3.5 GB maxmemory limit with 'noeviction' policy now."); - server.maxmemory = 3584LL*(1024*1024); /* 3584 MB = 3.5 GB */ + redisLog(REDIS_WARNING,"Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now."); + server.maxmemory = 3072LL*(1024*1024); /* 3 GB */ server.maxmemory_policy = REDIS_MAXMEMORY_NO_EVICTION; } @@ -1365,6 +1370,7 @@ void populateCommandTable(void) { case 'S': c->flags |= REDIS_CMD_SORT_FOR_SCRIPT; break; case 'l': c->flags |= REDIS_CMD_LOADING; break; case 't': c->flags |= REDIS_CMD_STALE; break; + case 'M': c->flags |= REDIS_CMD_SKIP_MONITOR; break; default: redisPanic("Unsupported command flag"); break; } f++; @@ -1440,7 +1446,7 @@ struct redisCommand *lookupCommandByCString(char *s) { } /* Propagate the specified command (in the context of the specified database id) - * to AOF, Slaves and Monitors. + * to AOF and Slaves. * * flags are an xor between: * + REDIS_PROPAGATE_NONE (no propagation of command at all) @@ -1470,8 +1476,12 @@ void call(redisClient *c, int flags) { /* Sent the command to clients in MONITOR mode, only if the commands are * not geneated from reading an AOF. */ - if (listLength(server.monitors) && !server.loading) + if (listLength(server.monitors) && + !server.loading && + !(c->cmd->flags & REDIS_CMD_SKIP_MONITOR)) + { replicationFeedMonitors(c,server.monitors,c->db->id,c->argv,c->argc); + } /* Call the command. */ redisOpArrayInit(&server.also_propagate); @@ -1521,7 +1531,7 @@ void call(redisClient *c, int flags) { } /* If this function gets called we already read a whole - * command, argments are in the client argv/argc fields. + * command, arguments are in the client argv/argc fields. * processCommand() execute the command or prepare the * server for a bulk read from the client. * @@ -1623,6 +1633,7 @@ int processCommand(redisClient *c) { /* Lua script too slow? Only allow commands with REDIS_CMD_STALE flag. */ if (server.lua_timedout && + c->cmd->proc != authCommand && !(c->cmd->proc == shutdownCommand && c->argc == 2 && tolower(((char*)c->argv[1]->ptr)[0]) == 'n') && @@ -2063,7 +2074,10 @@ sds genRedisInfoString(char *section) { (long)server.unixtime-server.repl_down_since); } info = sdscatprintf(info, - "slave_priority:%d\r\n", server.slave_priority); + "slave_priority:%d\r\n" + "slave_read_only:%d\r\n", + server.slave_priority, + server.repl_slave_ro); } info = sdscatprintf(info, "connected_slaves:%lu\r\n", @@ -2165,7 +2179,7 @@ void infoCommand(redisClient *c) { } void monitorCommand(redisClient *c) { - /* ignore MONITOR if aleady slave or in monitor mode */ + /* ignore MONITOR if already slave or in monitor mode */ if (c->flags & REDIS_SLAVE) return; c->flags |= (REDIS_SLAVE|REDIS_MONITOR); @@ -2264,7 +2278,7 @@ int freeMemoryIfNeeded(void) { de = dictGetRandomKey(dict); thiskey = dictGetKey(de); - /* When policy is volatile-lru we need an additonal lookup + /* When policy is volatile-lru we need an additional lookup * to locate the real key, as dict is set to db->expires. */ if (server.maxmemory_policy == REDIS_MAXMEMORY_VOLATILE_LRU) de = dictFind(db->dict, thiskey); @@ -2566,7 +2580,7 @@ int main(int argc, char **argv) { redisAsciiArt(); if (!server.sentinel_mode) { - /* Things only needed when not runnign in Sentinel mode. */ + /* Things only needed when not running in Sentinel mode. */ redisLog(REDIS_WARNING,"Server started, Redis version " REDIS_VERSION); #ifdef __linux__ linuxOvercommitMemoryWarning();