X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/ed44a74e720918d2b1ab68f3d50600af38d2a5af..b0aa9bc8cdd36925b2d8e5d3a9c1e1476eaa6fc1:/src/redis.c diff --git a/src/redis.c b/src/redis.c index 87f5e812..eed21263 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 @@ -49,6 +49,7 @@ #include #include #include +#include /* Our shared "common" objects */ @@ -391,7 +392,8 @@ int dictSdsKeyCompare(void *privdata, const void *key1, return memcmp(key1, key2, l1) == 0; } -/* A case insensitive version used for the command lookup table. */ +/* A case insensitive version used for the command lookup table and other + * places where case insensitive non binary-safe comparison is needed. */ int dictSdsKeyCaseCompare(void *privdata, const void *key1, const void *key2) { @@ -506,6 +508,16 @@ dictType dbDictType = { dictRedisObjectDestructor /* val destructor */ }; +/* server.lua_scripts sha (as sds string) -> scripts (as robj) cache. */ +dictType shaScriptObjectDictType = { + dictSdsCaseHash, /* hash function */ + NULL, /* key dup */ + NULL, /* val dup */ + dictSdsKeyCaseCompare, /* key compare */ + dictSdsDestructor, /* key destructor */ + dictRedisObjectDestructor /* val destructor */ +}; + /* Db->expires */ dictType keyptrDictType = { dictSdsHash, /* hash function */ @@ -902,8 +914,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(); } @@ -1033,6 +1049,8 @@ void createSharedObjects(void) { "-READONLY You can't write against a read only slave.\r\n")); shared.oomerr = createObject(REDIS_STRING,sdsnew( "-OOM command not allowed when used memory > 'maxmemory'.\r\n")); + shared.execaborterr = createObject(REDIS_STRING,sdsnew( + "-EXECABORT Transaction discarded because of previous errors.\r\n")); shared.space = createObject(REDIS_STRING,sdsnew(" ")); shared.colon = createObject(REDIS_STRING,sdsnew(":")); shared.plus = createObject(REDIS_STRING,sdsnew("+")); @@ -1102,6 +1120,9 @@ void initServerConfig() { server.pidfile = zstrdup("/var/run/redis.pid"); server.rdb_filename = zstrdup("dump.rdb"); server.aof_filename = zstrdup("appendonly.aof"); + server.mdb_state = REDIS_MDB_OFF; + server.mdb_environment = zstrdup("archive"); + server.mdb_mapsize = 10485760; server.requirepass = NULL; server.rdb_compression = 1; server.rdb_checksum = 1; @@ -1327,6 +1348,15 @@ void initServer() { } } + if (server.aof_state == REDIS_MDB_ON) { + int retval = startKeyArchive(); + if (retval != 0) { + redisLog(REDIS_WARNING, "Can't open the key-archive environment: %s", + mdb_strerror(retval)); + exit(1); + } + } + /* 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 GB using maxmemory with 'noeviction' policy'. This avoids @@ -1549,11 +1579,13 @@ int processCommand(redisClient *c) { * such as wrong arity, bad command name and so forth. */ c->cmd = c->lastcmd = lookupCommand(c->argv[0]->ptr); if (!c->cmd) { + flagTransaction(c); addReplyErrorFormat(c,"unknown command '%s'", (char*)c->argv[0]->ptr); return REDIS_OK; } else if ((c->cmd->arity > 0 && c->cmd->arity != c->argc) || (c->argc < -c->cmd->arity)) { + flagTransaction(c); addReplyErrorFormat(c,"wrong number of arguments for '%s' command", c->cmd->name); return REDIS_OK; @@ -1562,6 +1594,7 @@ int processCommand(redisClient *c) { /* Check if the user is authenticated */ if (server.requirepass && !c->authenticated && c->cmd->proc != authCommand) { + flagTransaction(c); addReplyError(c,"operation not permitted"); return REDIS_OK; } @@ -1574,6 +1607,7 @@ int processCommand(redisClient *c) { if (server.maxmemory) { int retval = freeMemoryIfNeeded(); if ((c->cmd->flags & REDIS_CMD_DENYOOM) && retval == REDIS_ERR) { + flagTransaction(c); addReply(c, shared.oomerr); return REDIS_OK; } @@ -1585,6 +1619,7 @@ int processCommand(redisClient *c) { && server.lastbgsave_status == REDIS_ERR && c->cmd->flags & REDIS_CMD_WRITE) { + flagTransaction(c); addReply(c, shared.bgsaveerr); return REDIS_OK; } @@ -1616,6 +1651,7 @@ int processCommand(redisClient *c) { server.repl_serve_stale_data == 0 && !(c->cmd->flags & REDIS_CMD_STALE)) { + flagTransaction(c); addReply(c, shared.masterdownerr); return REDIS_OK; } @@ -1637,6 +1673,7 @@ int processCommand(redisClient *c) { c->argc == 2 && tolower(((char*)c->argv[1]->ptr)[0]) == 'k')) { + flagTransaction(c); addReply(c, shared.slowscripterr); return REDIS_OK; } @@ -2313,6 +2350,8 @@ int freeMemoryIfNeeded(void) { long long delta; robj *keyobj = createStringObject(bestkey,sdslen(bestkey)); + int archived = archive(db, keyobj); + redisAssert(archived != 0); propagateExpire(db,keyobj); /* We compute the amount of memory freed by dbDelete() alone. * It is possible that actually the memory needed to propagate