From: antirez Date: Tue, 12 Jul 2011 10:39:16 +0000 (+0200) Subject: master branch merged into scripting. X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/0681c5ad844cefefbe62f30df6587c0cbec3272e master branch merged into scripting. --- 0681c5ad844cefefbe62f30df6587c0cbec3272e diff --cc Makefile index 20c4f86e,44df36f5..691843d4 --- a/Makefile +++ b/Makefile @@@ -12,8 -12,7 +12,9 @@@ clean cd src && $(MAKE) $@ cd deps/hiredis && $(MAKE) $@ cd deps/linenoise && $(MAKE) $@ + cd deps/jemalloc && $(MAKE) distclean + cd deps/lua && $(MAKE) $@ + -(cd deps/jemalloc && $(MAKE) distclean) $(TARGETS): cd src && $(MAKE) $@ diff --cc redis.conf index 098c28da,1a051e4d..9e9eac5f --- a/redis.conf +++ b/redis.conf @@@ -312,13 -312,30 +312,37 @@@ no-appendfsync-on-rewrite n auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb +################################ LUA SCRIPTING ############################### + +# Max execution time of a Lua script in milliseconds. +# This prevents that a programming error generating an infinite loop will block +# your server forever. Set it to 0 or a negative value for unlimited execution. +lua-time-limit 60000 + + ################################## SLOW LOG ################################### + + # The Redis Slow Log is a system to log queries that exceeded a specified + # execution time. The execution time does not include the I/O operations + # like talking with the client, sending the reply and so forth, + # but just the time needed to actually execute the command (this is the only + # stage of command execution where the thread is blocked and can not serve + # other requests in the meantime). + # + # You can configure the slow log with two parameters: one tells Redis + # what is the execution time, in microseconds, to exceed in order for the + # command to get logged, and the other parameter is the length of the + # slow log. When a new command is logged the oldest one is removed from the + # queue of logged commands. + + # The following time is expressed in microseconds, so 1000000 is equivalent + # to one second. Note that a negative number disables the slow log, while + # a value of zero forces the logging of every command. + slowlog-log-slower-than 10000 + + # There is no limit to this length. Just be aware that it will consume memory. + # You can reclaim memory used by the slow log with SLOWLOG RESET. + slowlog-max-len 1024 + ############################### ADVANCED CONFIG ############################### # Hashes are encoded in a special way (much more memory efficient) when they diff --cc src/Makefile index 7e4b829d,c8647b7d..84cb1cda --- a/src/Makefile +++ b/src/Makefile @@@ -61,7 -61,7 +61,7 @@@ QUIET_CC = @printf ' %b %b\n' $(CCCO QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR); endif - OBJ = adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endian.o scripting.o -OBJ = adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endian.o slowlog.o ++OBJ = adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endian.o slowlog.o scripting.o BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o CHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o diff --cc src/config.c index 88a00d38,e36f588a..5442e036 --- a/src/config.c +++ b/src/config.c @@@ -296,8 -296,12 +296,14 @@@ void loadServerConfig(char *filename) } else if (!strcasecmp(argv[0],"cluster-config-file") && argc == 2) { zfree(server.cluster.configfile); server.cluster.configfile = zstrdup(argv[1]); + } else if (!strcasecmp(argv[0],"lua-time-limit") && argc == 2) { + server.lua_time_limit = strtoll(argv[1],NULL,10); + } else if (!strcasecmp(argv[0],"slowlog-log-slower-than") && + argc == 2) + { + server.slowlog_log_slower_than = strtoll(argv[1],NULL,10); + } else if (!strcasecmp(argv[0],"slowlog-max-len") && argc == 2) { + server.slowlog_max_len = strtoll(argv[1],NULL,10); } else { err = "Bad directive or wrong number of arguments"; goto loaderr; } @@@ -468,9 -472,12 +474,15 @@@ void configSetCommand(redisClient *c) } else if (!strcasecmp(c->argv[2]->ptr,"zset-max-ziplist-value")) { if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; server.zset_max_ziplist_value = ll; + } else if (!strcasecmp(c->argv[2]->ptr,"lua-time-limit")) { + if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; + server.lua_time_limit = ll; + } else if (!strcasecmp(c->argv[2]->ptr,"slowlog-log-slower-than")) { + if (getLongLongFromObject(o,&ll) == REDIS_ERR) goto badfmt; + server.slowlog_log_slower_than = ll; + } else if (!strcasecmp(c->argv[2]->ptr,"slowlog-max-len")) { + if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; + server.slowlog_max_len = (unsigned)ll; } else { addReplyErrorFormat(c,"Unsupported CONFIG parameter: %s", (char*)c->argv[2]->ptr); @@@ -642,9 -649,14 +654,17 @@@ void configGetCommand(redisClient *c) addReplyBulkLongLong(c,server.zset_max_ziplist_value); matches++; } + if (stringmatch(pattern,"lua-time-limit",0)) { + addReplyBulkCString(c,"lua-time-limit"); + addReplyBulkLongLong(c,server.lua_time_limit); + if (stringmatch(pattern,"slowlog-log-slower-than",0)) { + addReplyBulkCString(c,"slowlog-log-slower-than"); + addReplyBulkLongLong(c,server.slowlog_log_slower_than); + matches++; + } + if (stringmatch(pattern,"slowlog-max-len",0)) { + addReplyBulkCString(c,"slowlog-max-len"); + addReplyBulkLongLong(c,server.slowlog_max_len); matches++; } setDeferredMultiBulkLength(c,replylen,matches*2); diff --cc src/redis.c index f4e3f623,0990d98a..7e9c6fd5 --- a/src/redis.c +++ b/src/redis.c @@@ -193,8 -194,7 +194,9 @@@ struct redisCommand redisCommandTable[ {"dump",dumpCommand,2,0,NULL,0,0,0,0,0}, {"object",objectCommand,-2,0,NULL,0,0,0,0,0}, {"client",clientCommand,-2,0,NULL,0,0,0,0,0}, + {"eval",evalCommand,-3,REDIS_CMD_DENYOOM,zunionInterGetKeys,0,0,0,0,0}, - {"evalsha",evalShaCommand,-3,REDIS_CMD_DENYOOM,zunionInterGetKeys,0,0,0,0,0} ++ {"evalsha",evalShaCommand,-3,REDIS_CMD_DENYOOM,zunionInterGetKeys,0,0,0,0,0}, + {"slowlog",slowlogCommand,-2,0,NULL,0,0,0,0,0} }; /*============================ Utility functions ============================ */ @@@ -957,7 -958,7 +963,8 @@@ void initServer() } if (server.cluster_enabled) clusterInit(); + scriptingInit(); + slowlogInit(); srand(time(NULL)^getpid()); } diff --cc src/redis.h index 9775e298,693347ef..1d094c1d --- a/src/redis.h +++ b/src/redis.h @@@ -19,19 -19,18 +19,19 @@@ #include #include #include +#include - #include "ae.h" /* Event driven programming library */ - #include "sds.h" /* Dynamic safe strings */ - #include "dict.h" /* Hash tables */ - #include "adlist.h" /* Linked lists */ + #include "ae.h" /* Event driven programming library */ + #include "sds.h" /* Dynamic safe strings */ + #include "dict.h" /* Hash tables */ + #include "adlist.h" /* Linked lists */ #include "zmalloc.h" /* total memory usage aware version of malloc/free */ - #include "anet.h" /* Networking the easy way */ - #include "zipmap.h" /* Compact string -> string data structure */ + #include "anet.h" /* Networking the easy way */ + #include "zipmap.h" /* Compact string -> string data structure */ #include "ziplist.h" /* Compact list data structure */ - #include "intset.h" /* Compact integer set structure */ - #include "version.h" - #include "util.h" + #include "intset.h" /* Compact integer set structure */ + #include "version.h" /* Version macro */ + #include "util.h" /* Misc functions useful in many places */ /* Error codes */ #define REDIS_OK 0 @@@ -918,10 -915,9 +925,10 @@@ int processCommand(redisClient *c) void setupSignalHandlers(void); struct redisCommand *lookupCommand(sds name); struct redisCommand *lookupCommandByCString(char *s); - void call(redisClient *c, struct redisCommand *cmd); + void call(redisClient *c); int prepareForShutdown(); void redisLog(int level, const char *fmt, ...); +void redisLogRaw(int level, const char *msg); void usage(); void updateDictResizePolicy(void); int htNeedsResize(dict *dict); diff --cc tests/test_helper.tcl index f505f26a,fbd9d3b3..559d0264 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@@ -9,6 -9,32 +9,33 @@@ source tests/support/tmpfile.tc source tests/support/test.tcl source tests/support/util.tcl + set ::all_tests { + unit/printver + unit/auth + unit/protocol + unit/basic + unit/type/list + unit/type/list-2 + unit/type/list-3 + unit/type/set + unit/type/zset + unit/type/hash + unit/sort + unit/expire + unit/other + unit/cas + unit/quit + integration/replication + integration/replication-2 + integration/replication-3 + integration/aof + unit/pubsub + unit/slowlog ++ unit/scripting + } + # Index to the next test to run in the ::all_tests list. + set ::next_test 0 + set ::host 127.0.0.1 set ::port 16379 set ::traceleaks 0