diff --git a/src/zmalloc.c b/src/zmalloc.c index ed19616b889798d72ba49c9583c59caffdf78b41..b438017dc7c3b7fad6994e8bd2ffae7ca7bbdb5d 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -186,7 +186,7 @@ size_t zmalloc_used_memory(void) { } size_t zmalloc_allocations_for_size(size_t size) { - if (size > ZMALLOC_MAX_ALLOC_STAT || size < 0) return 0; + if (size > ZMALLOC_MAX_ALLOC_STAT) return 0; return zmalloc_allocations[size]; } diff --git a/tests/assets/default.conf b/tests/assets/default.conf index 042332848152940452217bdbe02980d2d3450dbe..150eb6907b64fc6f286c0182798a7482a6c59ac4 100644 --- a/tests/assets/default.conf +++ b/tests/assets/default.conf @@ -18,9 +18,9 @@ daemonize no # When running daemonized, Redis writes a pid file in /var/run/redis.pid by # default. You can specify a custom pid file location here. -pidfile redis.pid +pidfile /var/run/redis.pid -# Accept connections on the specified port, default is 6379 +# Accept connections on the specified port, default is 6379. port 6379 # If you want you can bind a single interface, if the bind option is not @@ -28,6 +28,12 @@ port 6379 # # bind 127.0.0.1 +# Specify the path for the unix socket that will be used to listen for +# incoming connections. There is no default, so Redis will not listen +# on a unix socket when not specified. +# +# unixsocket /tmp/redis.sock + # Close the connection after a client is idle for N seconds (0 to disable) timeout 300 @@ -44,6 +50,16 @@ loglevel verbose # output for logging but daemonize, logs will be sent to /dev/null logfile stdout +# To enable logging to the system logger, just set 'syslog-enabled' to yes, +# and optionally update the other syslog parameters to suit your needs. +# syslog-enabled no + +# Specify the syslog identity. +# syslog-ident redis + +# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7. +# syslog-facility local0 + # Set the number of databases. The default database is DB 0, you can select # a different one on a per-connection basis using SELECT where # dbid is a number between 0 and 'databases'-1 @@ -86,7 +102,7 @@ dbfilename dump.rdb # Also the Append Only File will be created inside this directory. # # Note that you must specify a directory here, not a file name. -dir /tmp +dir ./ ################################# REPLICATION ################################# @@ -104,6 +120,19 @@ dir /tmp # # masterauth +# When a slave lost the connection with the master, or when the replication +# is still in progress, the slave can act in two different ways: +# +# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will +# still reply to client requests, possibly with out of data data, or the +# data set may just be empty if this is the first synchronization. +# +# 2) if slave-serve-stale data is set to 'no' the slave will reply with +# an error "SYNC with master in progress" to all the kind of commands +# but to INFO and SLAVEOF. +# +slave-serve-stale-data yes + ################################## SECURITY ################################### # Require clients to issue AUTH before processing any other @@ -119,6 +148,22 @@ dir /tmp # # requirepass foobared +# Command renaming. +# +# It is possilbe to change the name of dangerous commands in a shared +# environment. For instance the CONFIG command may be renamed into something +# of hard to guess so that it will be still available for internal-use +# tools but not available for general clients. +# +# Example: +# +# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 +# +# It is also possilbe to completely kill a command renaming it into +# an empty string: +# +# rename-command CONFIG "" + ################################### LIMITS #################################### # Set the max number of connected clients at the same time. By default there @@ -148,6 +193,37 @@ dir /tmp # # maxmemory +# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory +# is reached? You can select among five behavior: +# +# volatile-lru -> remove the key with an expire set using an LRU algorithm +# allkeys-lru -> remove any key accordingly to the LRU algorithm +# volatile-random -> remove a random key with an expire set +# allkeys->random -> remove a random key, any key +# volatile-ttl -> remove the key with the nearest expire time (minor TTL) +# noeviction -> don't expire at all, just return an error on write operations +# +# Note: with all the kind of policies, Redis will return an error on write +# operations, when there are not suitable keys for eviction. +# +# At the date of writing this commands are: set setnx setex append +# incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd +# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby +# zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby +# getset mset msetnx exec sort +# +# The default is: +# +# maxmemory-policy volatile-lru + +# LRU and minimal TTL algorithms are not precise algorithms but approximated +# algorithms (in order to save memory), so you can select as well the sample +# size to check. For instance for default Redis will check three keys and +# pick the one that was used less recently, you can change the sample size +# using the following configuration directive. +# +# maxmemory-samples 3 + ############################## APPEND ONLY MODE ############################### # By default Redis asynchronously dumps the dataset on disk. If you can live @@ -195,29 +271,54 @@ appendonly no appendfsync everysec # appendfsync no -################################ VIRTUAL MEMORY ############################### +# When the AOF fsync policy is set to always or everysec, and a background +# saving process (a background save or AOF log background rewriting) is +# performing a lot of I/O against the disk, in some Linux configurations +# Redis may block too long on the fsync() call. Note that there is no fix for +# this currently, as even performing fsync in a different thread will block +# our synchronous write(2) call. +# +# In order to mitigate this problem it's possible to use the following option +# that will prevent fsync() from being called in the main process while a +# BGSAVE or BGREWRITEAOF is in progress. +# +# This means that while another child is saving the durability of Redis is +# the same as "appendfsync none", that in pratical terms means that it is +# possible to lost up to 30 seconds of log in the worst scenario (with the +# default Linux settings). +# +# If you have latency problems turn this to "yes". Otherwise leave it as +# "no" that is the safest pick from the point of view of durability. +no-appendfsync-on-rewrite no + +#################################### DISK STORE ############################### -# Virtual Memory allows Redis to work with datasets bigger than the actual -# amount of RAM needed to hold the whole dataset in memory. -# In order to do so very used keys are taken in memory while the other keys -# are swapped into a swap file, similarly to what operating systems do -# with memory pages. +# When disk store is active Redis works as an on-disk database, where memory +# is only used as a object cache. +# +# This mode is good for datasets that are bigger than memory, and in general +# when you want to trade speed for: # -# To enable VM just set 'vm-enabled' to yes, and set the following three -# VM parameters accordingly to your needs. +# - less memory used +# - immediate server restart +# - per key durability, without need for backgrond savig +# +# On the other hand, with disk store enabled MULTI/EXEC are no longer +# transactional from the point of view of the persistence on disk, that is, +# Redis transactions will still guarantee that commands are either processed +# all or nothing, but there is no guarantee that all the keys are flushed +# on disk in an atomic way. +# +# Of course with disk store enabled Redis is not as fast as it is when +# working with just the memory back end. -diskstore-enabled yes +diskstore-enabled no diskstore-path redis.ds cache-max-memory 0 cache-flush-delay 0 ############################### ADVANCED CONFIG ############################### -# Glue small output buffers together in order to send small replies in a -# single TCP packet. Uses a bit more CPU but most of the times it is a win -# in terms of number of queries per second. Use 'yes' if unsure. -glueoutputbuf yes - # Hashes are encoded in a special way (much more memory efficient) when they # have at max a given numer of elements, and the biggest element does not # exceed a given threshold. You can configure this limits with the following @@ -225,6 +326,19 @@ glueoutputbuf yes hash-max-zipmap-entries 64 hash-max-zipmap-value 512 +# Similarly to hashes, small lists are also encoded in a special way in order +# to save a lot of space. The special representation is only used when +# you are under the following limits: +list-max-ziplist-entries 512 +list-max-ziplist-value 64 + +# Sets have a special encoding in just one case: when a set is composed +# of just strings that happens to be integers in radix 10 in the range +# of 64 bit signed integers. +# The following configuration setting sets the limit in the size of the +# set in order to use this special memory saving encoding. +set-max-intset-entries 512 + # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in # order to help rehashing the main Redis hash table (the one mapping top-level # keys to values). The hash table implementation redis uses (see dict.c) diff --git a/tests/support/server.tcl b/tests/support/server.tcl index ad711e6ee224f382bcf80a3ceba4a2b279cd4c5f..4f48d22dcafbd023acde952340890bc262a7ee10 100644 --- a/tests/support/server.tcl +++ b/tests/support/server.tcl @@ -177,9 +177,6 @@ proc start_server {options {code undefined}} { if {$::valgrind} { exec valgrind --suppressions=src/valgrind.sup src/redis-server $config_file > $stdout 2> $stderr & } else { - if {$::verbose} { - puts "Logging on $stdout / $stderr" - } exec src/redis-server $config_file > $stdout 2> $stderr & } diff --git a/tests/support/tmpfile.tcl b/tests/support/tmpfile.tcl index 809f587306c68f6adeceba36fcbd30d90782c5a4..287b093177098371336c2df486c9eb61a8cc1ae0 100644 --- a/tests/support/tmpfile.tcl +++ b/tests/support/tmpfile.tcl @@ -4,7 +4,13 @@ file mkdir $::tmproot # returns a dirname unique to this process to write to proc tmpdir {basename} { - set dir [file join $::tmproot $basename.[pid].[incr ::tmpcounter]] + if {$::diskstore} { + # For diskstore we want to use the same dir again and again + # otherwise everything is too slow. + set dir [file join $::tmproot $basename.diskstore] + } else { + set dir [file join $::tmproot $basename.[pid].[incr ::tmpcounter]] + } file mkdir $dir set _ $dir } diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index 8ab2f6e40b9f0aa9443d148bd63b10ce57889033..ec207b13af78a7c47ebfda0c26b9483af3853c90 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -13,12 +13,13 @@ set ::host 127.0.0.1 set ::port 16379 set ::traceleaks 0 set ::valgrind 0 -set ::verbose 1 +set ::verbose 0 set ::denytags {} set ::allowtags {} set ::external 0; # If "1" this means, we are running against external instance set ::file ""; # If set, runs only the tests in this comma separated list set ::curfile ""; # Hold the filename of the current suite +set ::diskstore 0; # Don't touch this by hand. The test itself will toggle it. proc execute_tests name { set path "tests/$name.tcl" @@ -103,6 +104,9 @@ proc s {args} { } proc cleanup {} { + if {$::diskstore} { + puts "Cleanup: warning may take some minute (diskstore enabled)" + } catch {exec rm -rf {*}[glob tests/tmp/redis.conf.*]} catch {exec rm -rf {*}[glob tests/tmp/server.*]} } @@ -125,8 +129,9 @@ proc execute_everything {} { # execute_tests "integration/redis-cli" execute_tests "unit/pubsub" - # run tests with VM enabled - set ::global_overrides {vm-enabled yes} + # run tests with diskstore enabled + set ::diskstore 1 + set ::global_overrides {diskstore-enabled yes} execute_tests "unit/protocol" execute_tests "unit/basic" execute_tests "unit/type/list"