Compare commits
154
Commits
rdbchanges
..
nosync
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1d10e8bb7 | ||
|
|
ede98af9da | ||
|
|
de6f74838a | ||
|
|
abbfbcf161 | ||
|
|
b1de179c01 | ||
|
|
cd4e0f43df | ||
|
|
866b3fc0ec | ||
|
|
29b54db320 | ||
|
|
2b3eba056c | ||
|
|
a1d9ec0d44 | ||
|
|
dffbbb5a78 | ||
|
|
a37d0f8b48 | ||
|
|
9feee428f2 | ||
|
|
55003f7a11 | ||
|
|
cc7f0434b5 | ||
|
|
6b5922dcbb | ||
|
|
585d1a60bf | ||
|
|
8ddc14523f | ||
|
|
edda00b902 | ||
|
|
05841a6386 | ||
|
|
8696874d75 | ||
|
|
5792a217f8 | ||
|
|
f25fdd6246 | ||
|
|
2385630d0d | ||
|
|
4f427bc298 | ||
|
|
1bcf67a75f | ||
|
|
88cd9ebc09 | ||
|
|
cd0fcf11e7 | ||
|
|
777020839a | ||
|
|
170e41464d | ||
|
|
5e3dcc522b | ||
|
|
e1fce55237 | ||
|
|
9e9abe29fe | ||
|
|
50a57c67b2 | ||
|
|
bd128f7969 | ||
|
|
ca23b2a6b7 | ||
|
|
cfe21852e7 | ||
|
|
2723412b7b | ||
|
|
ace1acc532 | ||
|
|
c83a739bd8 | ||
|
|
414df143f5 | ||
|
|
2860cf4139 | ||
|
|
ba74711e06 | ||
|
|
2ac7b5a8b4 | ||
|
|
78dd2b313e | ||
|
|
c5dd686ecb | ||
|
|
719c6c2b96 | ||
|
|
96abf65900 | ||
|
|
5fbb36f9e7 | ||
|
|
1dbd8e94a7 | ||
|
|
51010007bc | ||
|
|
fad758b322 | ||
|
|
7d1e158084 | ||
|
|
45102a6f63 | ||
|
|
128c642d05 | ||
|
|
cdc0e9bfb5 | ||
|
|
c908774b9e | ||
|
|
6502947a85 | ||
|
|
79fa67cdb8 | ||
|
|
233729fe7f | ||
|
|
69b4f00d28 | ||
|
|
6b1c6334be | ||
|
|
e5a22064cc | ||
|
|
1efacfe53d | ||
|
|
3fd43062c8 | ||
|
|
d59ad97d76 | ||
|
|
69583be181 | ||
|
|
8899f91a7f | ||
|
|
d3ef6c94bf | ||
|
|
d8c7db1bdb | ||
|
|
764b000c3e | ||
|
|
145473acc5 | ||
|
|
6ec5f1f780 | ||
|
|
9802ec3c83 | ||
|
|
8aaf5075c5 | ||
|
|
7885e1264e | ||
|
|
e22d75734e | ||
|
|
ca14440aa1 | ||
|
|
d5ba544e67 | ||
|
|
e4d65e35e6 | ||
|
|
a330b6ca97 | ||
|
|
9826038f0b | ||
|
|
87301be151 | ||
|
|
af8d1b4bda | ||
|
|
7e79b3f51a | ||
|
|
051a43e03a | ||
|
|
29049507ec | ||
|
|
30152554ea | ||
|
|
72b8574cca | ||
|
|
acb1d8debf | ||
|
|
4433f5a7f2 | ||
|
|
b3bf7584b0 | ||
|
|
a5bb0a0774 | ||
|
|
2601e3e461 | ||
|
|
59ad6ac5fe | ||
|
|
491d57abaa | ||
|
|
b0146aafeb | ||
|
|
92cfab44b2 | ||
|
|
e467cf5db3 | ||
|
|
bc8675612f | ||
|
|
839767ad0b | ||
|
|
cf76af6b9f | ||
|
|
5b0f4a83ac | ||
|
|
237ab727b9 | ||
|
|
f08586347d | ||
|
|
2c925b0c30 | ||
|
|
10007cb78c | ||
|
|
e6416ca71c | ||
|
|
6274a6789d | ||
|
|
eb7d67a3ab | ||
|
|
36a3b75355 | ||
|
|
5e8b7e4f35 | ||
|
|
e6d499a446 | ||
|
|
0d22121c27 | ||
|
|
792a94153a | ||
|
|
f3fd58eb4a | ||
|
|
da95d22ad2 | ||
|
|
1019c72930 | ||
|
|
bf58f8b513 | ||
|
|
1c477f62bc | ||
|
|
622c69e93d | ||
|
|
b45e16e7ee | ||
|
|
161ff77572 | ||
|
|
219ab66cc8 | ||
|
|
42357668e8 | ||
|
|
a7722dc31b | ||
|
|
4c0e8923a6 | ||
|
|
206cd219b6 | ||
|
|
1a30e7ded1 | ||
|
|
e8614a1a77 | ||
|
|
32b10004e2 | ||
|
|
f699b5e801 | ||
|
|
68bc02c36c | ||
|
|
05ba119fbb | ||
|
|
5870e22423 | ||
|
|
25e12d10be | ||
|
|
9e11d07909 | ||
|
|
02bb515a09 | ||
|
|
bbbbfb1442 | ||
|
|
5f506b6d2b | ||
|
|
abdd1414a8 | ||
|
|
5127e39980 | ||
|
|
8d7021892e | ||
|
|
e0d94a7b01 | ||
|
|
101b3a6e42 | ||
|
|
127c15e2b2 | ||
|
|
e1619772db | ||
|
|
c6bf20c2a7 | ||
|
|
60a9418ed9 | ||
|
|
0f15eb183b | ||
|
|
9d2dc0249c | ||
|
|
5e362b84ab | ||
|
|
352172a7ef | ||
|
|
e9b014cfac |
@@ -4,6 +4,7 @@
|
||||
dump.rdb
|
||||
redis-benchmark
|
||||
redis-check-aof
|
||||
redis-check-rdb
|
||||
redis-check-dump
|
||||
redis-cli
|
||||
redis-sentinel
|
||||
|
||||
@@ -26,6 +26,25 @@ After building Redis is a good idea to test it, using:
|
||||
|
||||
% make test
|
||||
|
||||
Fixing build problems with dependencies or cached build options
|
||||
—--------
|
||||
Redis has some dependencies which are included into the "deps" directory.
|
||||
"make" does not rebuild dependencies automatically, even if something in the
|
||||
source code of dependencies is changes.
|
||||
|
||||
When you update the source code with `git pull` or when code inside the
|
||||
dependencies tree is modified in any other way, make sure to use the following
|
||||
command in order to really clean everything and rebuild from scratch:
|
||||
|
||||
make distclean
|
||||
|
||||
This will clean: jemalloc, lua, hiredis, linenoise.
|
||||
|
||||
Also if you force certain build options like 32bit target, no C compiler
|
||||
optimizations (for debugging purposes), and other similar build time options,
|
||||
those options are cached indefinitely until you issue a "make distclean"
|
||||
command.
|
||||
|
||||
Fixing problems building 32 bit binaries
|
||||
---------
|
||||
|
||||
|
||||
+50
-1
@@ -36,6 +36,17 @@
|
||||
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
|
||||
daemonize no
|
||||
|
||||
# If you run Redis from upstart or systemd, Redis can interact with your
|
||||
# supervision tree. Options:
|
||||
# supervised no - no supervision interaction
|
||||
# supervised upstart - signal upstart by putting Redis into SIGSTOP mode
|
||||
# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
|
||||
# supervised auto - detect upstart or systemd method based on
|
||||
# UPSTART_JOB or NOTIFY_SOCKET environment variables
|
||||
# Note: these supervision methods only signal "process is ready."
|
||||
# They do not enable continuous liveness pings back to your supervisor.
|
||||
supervised 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 /var/run/redis.pid
|
||||
@@ -289,6 +300,38 @@ repl-diskless-sync-delay 5
|
||||
#
|
||||
# repl-ping-slave-period 10
|
||||
|
||||
# WARNING: This feature is experimental, just an evaluation draft.
|
||||
#
|
||||
# No-sync replication is a special, inconistent, mode of operation for slaves
|
||||
# that is sometimes useful in caching scenarios.
|
||||
#
|
||||
# In this setup slaves, when connecting to masters, don't ask for the pre
|
||||
# existing state of the key space, so no synchronization with the current
|
||||
# master data is performed at all. However the slaves will get all the new
|
||||
# stream of writes receiving the master, starting from the moment the slave
|
||||
# connects.
|
||||
#
|
||||
# This means that:
|
||||
# 1) There is no consistency between master and slaves operating in this mode.
|
||||
# 2) It is possible that keys with an expire in the master will never expire
|
||||
# in the slave (because the slave may miss the EXPIRE command).
|
||||
# 3) Keys updated with non-idempotent commands may end with different values.
|
||||
#
|
||||
# However if your workload is about idempotent updates (for example using
|
||||
# just the SET command), and no-sync slaves are configured in order to evict
|
||||
# data on their own using maxmemory and a suitable policy, there are certain
|
||||
# advantages:
|
||||
#
|
||||
# 1) Slaves are always available (assuming they are configured to serve stale
|
||||
# data), since reconnecting with the master has no cost.
|
||||
# 2) Masters don't have to persist on disk and/or stream an RDB file to the
|
||||
# slaves, slaves are just accepted ASAP and put online.
|
||||
#
|
||||
# To enable, simply set repl-no-sync to yes. By default this feature is
|
||||
# disabled.
|
||||
#
|
||||
# repl-no-sync no
|
||||
|
||||
# The following option sets the replication timeout for:
|
||||
#
|
||||
# 1) Bulk transfer I/O during SYNC, from the point of view of slave.
|
||||
@@ -619,6 +662,12 @@ lua-time-limit 5000
|
||||
|
||||
################################ REDIS CLUSTER ###############################
|
||||
#
|
||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
# WARNING EXPERIMENTAL: Redis Cluster is considered to be stable code, however
|
||||
# in order to mark it as "mature" we need to wait for a non trivial percentage
|
||||
# of users to deploy it in production.
|
||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
#
|
||||
# Normal Redis instances can't be part of a Redis Cluster; only nodes that are
|
||||
# started as cluster nodes can. In order to start a Redis instance as a
|
||||
# cluster node enable the cluster support uncommenting the following:
|
||||
@@ -764,7 +813,7 @@ slowlog-max-len 128
|
||||
# "CONFIG SET latency-monitor-threshold <milliseconds>" if needed.
|
||||
latency-monitor-threshold 0
|
||||
|
||||
############################# Event notification ##############################
|
||||
############################# EVENT NOTIFICATION ##############################
|
||||
|
||||
# Redis can notify Pub/Sub clients about events happening in the key space.
|
||||
# This feature is documented at http://redis.io/topics/notifications
|
||||
|
||||
+10
-11
@@ -62,7 +62,7 @@ ifeq ($(uname_S),SunOS)
|
||||
# SunOS
|
||||
INSTALL=cp -pf
|
||||
FINAL_CFLAGS+= -D__EXTENSIONS__ -D_XPG6
|
||||
FINAL_LIBS+= -ldl -lnsl -lsocket -lresolv -lpthread
|
||||
FINAL_LIBS+= -ldl -lnsl -lsocket -lresolv -lpthread -lrt
|
||||
else
|
||||
ifeq ($(uname_S),Darwin)
|
||||
# Darwin (nothing to do)
|
||||
@@ -117,17 +117,16 @@ endif
|
||||
|
||||
REDIS_SERVER_NAME=redis-server
|
||||
REDIS_SENTINEL_NAME=redis-sentinel
|
||||
REDIS_SERVER_OBJ=adlist.o quicklist.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 endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o
|
||||
REDIS_SERVER_OBJ=adlist.o quicklist.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 endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o redis-check-rdb.o
|
||||
REDIS_CLI_NAME=redis-cli
|
||||
REDIS_CLI_OBJ=anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o crc64.o
|
||||
REDIS_BENCHMARK_NAME=redis-benchmark
|
||||
REDIS_BENCHMARK_OBJ=ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
|
||||
REDIS_CHECK_DUMP_NAME=redis-check-dump
|
||||
REDIS_CHECK_DUMP_OBJ=redis-check-dump.o lzf_c.o lzf_d.o crc64.o
|
||||
REDIS_CHECK_RDB_NAME=redis-check-rdb
|
||||
REDIS_CHECK_AOF_NAME=redis-check-aof
|
||||
REDIS_CHECK_AOF_OBJ=redis-check-aof.o
|
||||
|
||||
all: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME)
|
||||
all: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_RDB_NAME) $(REDIS_CHECK_AOF_NAME)
|
||||
@echo ""
|
||||
@echo "Hint: It's a good idea to run 'make test' ;)"
|
||||
@echo ""
|
||||
@@ -178,6 +177,10 @@ $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ)
|
||||
$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
|
||||
$(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME)
|
||||
|
||||
# redis-check-rdb
|
||||
$(REDIS_CHECK_RDB_NAME): $(REDIS_SERVER_NAME)
|
||||
$(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_CHECK_RDB_NAME)
|
||||
|
||||
# redis-cli
|
||||
$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
|
||||
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
|
||||
@@ -186,10 +189,6 @@ $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
|
||||
$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
|
||||
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
|
||||
|
||||
# redis-check-dump
|
||||
$(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ)
|
||||
$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
|
||||
|
||||
# redis-check-aof
|
||||
$(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
|
||||
$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
|
||||
@@ -201,7 +200,7 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
|
||||
$(REDIS_CC) -c $<
|
||||
|
||||
clean:
|
||||
rm -rf $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html
|
||||
rm -rf $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_RDB_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
@@ -257,6 +256,6 @@ install: all
|
||||
$(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN)
|
||||
$(REDIS_INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN)
|
||||
$(REDIS_INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN)
|
||||
$(REDIS_INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN)
|
||||
$(REDIS_INSTALL) $(REDIS_CHECK_RDB_NAME) $(INSTALL_BIN)
|
||||
$(REDIS_INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN)
|
||||
@ln -sf $(REDIS_SERVER_NAME) $(INSTALL_BIN)/$(REDIS_SENTINEL_NAME)
|
||||
|
||||
@@ -1082,6 +1082,7 @@ int rewriteAppendOnlyFile(char *filename) {
|
||||
}
|
||||
}
|
||||
dictReleaseIterator(di);
|
||||
di = NULL;
|
||||
}
|
||||
|
||||
/* Do an initial slow fsync here while the parent is still sending
|
||||
|
||||
+135
-39
@@ -40,6 +40,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/file.h>
|
||||
#include <math.h>
|
||||
|
||||
/* A global reference to myself is handy to make code more clear.
|
||||
* Myself always points to server.cluster->myself, that is, the clusterNode
|
||||
@@ -479,6 +480,7 @@ void clusterInit(void) {
|
||||
* the IP address via MEET messages. */
|
||||
myself->port = server.port;
|
||||
|
||||
server.cluster->mf_end = 0;
|
||||
resetManualFailover();
|
||||
}
|
||||
|
||||
@@ -782,8 +784,11 @@ int clusterNodeRemoveSlave(clusterNode *master, clusterNode *slave) {
|
||||
|
||||
for (j = 0; j < master->numslaves; j++) {
|
||||
if (master->slaves[j] == slave) {
|
||||
memmove(master->slaves+j,master->slaves+(j+1),
|
||||
(master->numslaves-1)-j);
|
||||
if ((j+1) < master->numslaves) {
|
||||
int remaining_slaves = (master->numslaves - j) - 1;
|
||||
memmove(master->slaves+j,master->slaves+(j+1),
|
||||
(sizeof(*master->slaves) * remaining_slaves));
|
||||
}
|
||||
master->numslaves--;
|
||||
return REDIS_OK;
|
||||
}
|
||||
@@ -818,15 +823,30 @@ int clusterCountNonFailingSlaves(clusterNode *n) {
|
||||
return okslaves;
|
||||
}
|
||||
|
||||
/* Low level cleanup of the node structure. Only called by clusterDelNode(). */
|
||||
void freeClusterNode(clusterNode *n) {
|
||||
sds nodename;
|
||||
int j;
|
||||
|
||||
/* If the node is a master with associated slaves, we have to set
|
||||
* all the slaves->slaveof fields to NULL (unknown). */
|
||||
if (nodeIsMaster(n)) {
|
||||
for (j = 0; j < n->numslaves; j++)
|
||||
n->slaves[j]->slaveof = NULL;
|
||||
}
|
||||
|
||||
/* Remove this node from the list of slaves of its master. */
|
||||
if (nodeIsSlave(n) && n->slaveof) clusterNodeRemoveSlave(n->slaveof,n);
|
||||
|
||||
/* Unlink from the set of nodes. */
|
||||
nodename = sdsnewlen(n->name, REDIS_CLUSTER_NAMELEN);
|
||||
redisAssert(dictDelete(server.cluster->nodes,nodename) == DICT_OK);
|
||||
sdsfree(nodename);
|
||||
if (n->slaveof) clusterNodeRemoveSlave(n->slaveof, n);
|
||||
|
||||
/* Release link and associated data structures. */
|
||||
if (n->link) freeClusterLink(n->link);
|
||||
listRelease(n->fail_reports);
|
||||
zfree(n->slaves);
|
||||
zfree(n);
|
||||
}
|
||||
|
||||
@@ -839,11 +859,16 @@ int clusterAddNode(clusterNode *node) {
|
||||
return (retval == DICT_OK) ? REDIS_OK : REDIS_ERR;
|
||||
}
|
||||
|
||||
/* Remove a node from the cluster:
|
||||
* 1) Mark all the nodes handled by it as unassigned.
|
||||
* 2) Remove all the failure reports sent by this node.
|
||||
* 3) Free the node, that will in turn remove it from the hash table
|
||||
* and from the list of slaves of its master, if it is a slave node.
|
||||
/* Remove a node from the cluster. The functio performs the high level
|
||||
* cleanup, calling freeClusterNode() for the low level cleanup.
|
||||
* Here we do the following:
|
||||
*
|
||||
* 1) Mark all the slots handled by it as unassigned.
|
||||
* 2) Remove all the failure reports sent by this node and referenced by
|
||||
* other nodes.
|
||||
* 3) Free the node with freeClusterNode() that will in turn remove it
|
||||
* from the hash table and from the list of slaves of its master, if
|
||||
* it is a slave node.
|
||||
*/
|
||||
void clusterDelNode(clusterNode *delnode) {
|
||||
int j;
|
||||
@@ -870,11 +895,7 @@ void clusterDelNode(clusterNode *delnode) {
|
||||
}
|
||||
dictReleaseIterator(di);
|
||||
|
||||
/* 3) Remove this node from its master's slaves if needed. */
|
||||
if (nodeIsSlave(delnode) && delnode->slaveof)
|
||||
clusterNodeRemoveSlave(delnode->slaveof,delnode);
|
||||
|
||||
/* 4) Free the node, unlinking it from the cluster. */
|
||||
/* 3) Free the node, unlinking it from the cluster. */
|
||||
freeClusterNode(delnode);
|
||||
}
|
||||
|
||||
@@ -1118,6 +1139,7 @@ int clusterStartHandshake(char *ip, int port) {
|
||||
|
||||
/* Set norm_ip as the normalized string representation of the node
|
||||
* IP address. */
|
||||
memset(norm_ip,0,REDIS_IP_STR_LEN);
|
||||
if (sa.ss_family == AF_INET)
|
||||
inet_ntop(AF_INET,
|
||||
(void*)&(((struct sockaddr_in *)&sa)->sin_addr),
|
||||
@@ -1232,7 +1254,7 @@ void nodeIp2String(char *buf, clusterLink *link) {
|
||||
* The function returns 0 if the node address is still the same,
|
||||
* otherwise 1 is returned. */
|
||||
int nodeUpdateAddressIfNeeded(clusterNode *node, clusterLink *link, int port) {
|
||||
char ip[REDIS_IP_STR_LEN];
|
||||
char ip[REDIS_IP_STR_LEN] = {0};
|
||||
|
||||
/* We don't proceed if the link is the same as the sender link, as this
|
||||
* function is designed to see if the node link is consistent with the
|
||||
@@ -1463,7 +1485,8 @@ int clusterProcessPacket(clusterLink *link) {
|
||||
|
||||
/* Perform sanity checks */
|
||||
if (totlen < 16) return 1; /* At least signature, version, totlen, count. */
|
||||
if (ntohs(hdr->ver) != 0) return 1; /* Can't handle versions other than 0.*/
|
||||
if (ntohs(hdr->ver) != CLUSTER_PROTO_VER)
|
||||
return 1; /* Can't handle versions other than the current one.*/
|
||||
if (totlen > sdslen(link->rcvbuf)) return 1;
|
||||
if (type == CLUSTERMSG_TYPE_PING || type == CLUSTERMSG_TYPE_PONG ||
|
||||
type == CLUSTERMSG_TYPE_MEET)
|
||||
@@ -1544,18 +1567,20 @@ int clusterProcessPacket(clusterLink *link) {
|
||||
* later if we changed address, and those nodes will use our
|
||||
* official address to connect to us. So by obtaining this address
|
||||
* from the socket is a simple way to discover / update our own
|
||||
* address in the cluster without it being hardcoded in the config. */
|
||||
if (type == CLUSTERMSG_TYPE_MEET) {
|
||||
* address in the cluster without it being hardcoded in the config.
|
||||
*
|
||||
* However if we don't have an address at all, we update the address
|
||||
* even with a normal PING packet. If it's wrong it will be fixed
|
||||
* by MEET later. */
|
||||
if (type == CLUSTERMSG_TYPE_MEET || myself->ip[0] == '\0') {
|
||||
char ip[REDIS_IP_STR_LEN];
|
||||
|
||||
if (anetSockName(link->fd,ip,sizeof(ip),NULL) != -1 &&
|
||||
strcmp(ip,myself->ip))
|
||||
{
|
||||
memcpy(myself->ip,ip,REDIS_IP_STR_LEN);
|
||||
|
||||
anetFormatAddr(ip, sizeof(ip), myself->ip, -1);
|
||||
redisLog(REDIS_WARNING,"IP address for this node updated to %s",
|
||||
ip);
|
||||
myself->ip);
|
||||
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG);
|
||||
}
|
||||
}
|
||||
@@ -1606,7 +1631,7 @@ int clusterProcessPacket(clusterLink *link) {
|
||||
}
|
||||
/* Free this node as we already have it. This will
|
||||
* cause the link to be freed as well. */
|
||||
freeClusterNode(link->node);
|
||||
clusterDelNode(link->node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2013,7 +2038,8 @@ void clusterBroadcastMessage(void *buf, size_t len) {
|
||||
dictReleaseIterator(di);
|
||||
}
|
||||
|
||||
/* Build the message header */
|
||||
/* Build the message header. hdr must point to a buffer at least
|
||||
* sizeof(clusterMsg) in bytes. */
|
||||
void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
|
||||
int totlen = 0;
|
||||
uint64_t offset;
|
||||
@@ -2027,6 +2053,7 @@ void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
|
||||
myself->slaveof : myself;
|
||||
|
||||
memset(hdr,0,sizeof(*hdr));
|
||||
hdr->ver = htons(CLUSTER_PROTO_VER);
|
||||
hdr->sig[0] = 'R';
|
||||
hdr->sig[1] = 'C';
|
||||
hdr->sig[2] = 'm';
|
||||
@@ -2073,40 +2100,90 @@ void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
|
||||
/* Send a PING or PONG packet to the specified node, making sure to add enough
|
||||
* gossip informations. */
|
||||
void clusterSendPing(clusterLink *link, int type) {
|
||||
unsigned char buf[sizeof(clusterMsg)+sizeof(clusterMsgDataGossip)*3];
|
||||
clusterMsg *hdr = (clusterMsg*) buf;
|
||||
int gossipcount = 0, totlen;
|
||||
/* freshnodes is the number of nodes we can still use to populate the
|
||||
* gossip section of the ping packet. Basically we start with the nodes
|
||||
* we have in memory minus two (ourself and the node we are sending the
|
||||
* message to). Every time we add a node we decrement the counter, so when
|
||||
* it will drop to <= zero we know there is no more gossip info we can
|
||||
* send. */
|
||||
unsigned char *buf;
|
||||
clusterMsg *hdr;
|
||||
int gossipcount = 0; /* Number of gossip sections added so far. */
|
||||
int wanted; /* Number of gossip sections we want to append if possible. */
|
||||
int totlen; /* Total packet length. */
|
||||
/* freshnodes is the max number of nodes we can hope to append at all:
|
||||
* nodes available minus two (ourself and the node we are sending the
|
||||
* message to). However practically there may be less valid nodes since
|
||||
* nodes in handshake state, disconnected, are not considered. */
|
||||
int freshnodes = dictSize(server.cluster->nodes)-2;
|
||||
|
||||
/* How many gossip sections we want to add? 1/10 of the number of nodes
|
||||
* and anyway at least 3. Why 1/10?
|
||||
*
|
||||
* If we have N masters, with N/10 entries, and we consider that in
|
||||
* node_timeout we exchange with each other node at least 4 packets
|
||||
* (we ping in the worst case in node_timeout/2 time, and we also
|
||||
* receive two pings from the host), we have a total of 8 packets
|
||||
* in the node_timeout*2 falure reports validity time. So we have
|
||||
* that, for a single PFAIL node, we can expect to receive the following
|
||||
* number of failure reports (in the specified window of time):
|
||||
*
|
||||
* PROB * GOSSIP_ENTRIES_PER_PACKET * TOTAL_PACKETS:
|
||||
*
|
||||
* PROB = probability of being featured in a single gossip entry,
|
||||
* which is 1 / NUM_OF_NODES.
|
||||
* ENTRIES = 10.
|
||||
* TOTAL_PACKETS = 2 * 4 * NUM_OF_MASTERS.
|
||||
*
|
||||
* If we assume we have just masters (so num of nodes and num of masters
|
||||
* is the same), with 1/10 we always get over the majority, and specifically
|
||||
* 80% of the number of nodes, to account for many masters failing at the
|
||||
* same time.
|
||||
*
|
||||
* Since we have non-voting slaves that lower the probability of an entry
|
||||
* to feature our node, we set the number of entires per packet as
|
||||
* 10% of the total nodes we have. */
|
||||
wanted = floor(dictSize(server.cluster->nodes)/10);
|
||||
if (wanted < 3) wanted = 3;
|
||||
if (wanted > freshnodes) wanted = freshnodes;
|
||||
|
||||
/* Compute the maxium totlen to allocate our buffer. We'll fix the totlen
|
||||
* later according to the number of gossip sections we really were able
|
||||
* to put inside the packet. */
|
||||
totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
|
||||
totlen += (sizeof(clusterMsgDataGossip)*wanted);
|
||||
/* Note: clusterBuildMessageHdr() expects the buffer to be always at least
|
||||
* sizeof(clusterMsg) or more. */
|
||||
if (totlen < (int)sizeof(clusterMsg)) totlen = sizeof(clusterMsg);
|
||||
buf = zcalloc(totlen);
|
||||
hdr = (clusterMsg*) buf;
|
||||
|
||||
/* Populate the header. */
|
||||
if (link->node && type == CLUSTERMSG_TYPE_PING)
|
||||
link->node->ping_sent = mstime();
|
||||
clusterBuildMessageHdr(hdr,type);
|
||||
|
||||
/* Populate the gossip fields */
|
||||
while(freshnodes > 0 && gossipcount < 3) {
|
||||
int maxiterations = wanted*3;
|
||||
while(freshnodes > 0 && gossipcount < wanted && maxiterations--) {
|
||||
dictEntry *de = dictGetRandomKey(server.cluster->nodes);
|
||||
clusterNode *this = dictGetVal(de);
|
||||
clusterMsgDataGossip *gossip;
|
||||
int j;
|
||||
|
||||
/* Don't include this node: the whole packet header is about us
|
||||
* already, so we just gossip about other nodes. */
|
||||
if (this == myself) continue;
|
||||
|
||||
/* Give a bias to FAIL/PFAIL nodes. */
|
||||
if (maxiterations > wanted*2 &&
|
||||
!(this->flags & (REDIS_NODE_PFAIL|REDIS_NODE_FAIL)))
|
||||
continue;
|
||||
|
||||
/* In the gossip section don't include:
|
||||
* 1) Myself.
|
||||
* 2) Nodes in HANDSHAKE state.
|
||||
* 1) Nodes in HANDSHAKE state.
|
||||
* 3) Nodes with the NOADDR flag set.
|
||||
* 4) Disconnected nodes if they don't have configured slots.
|
||||
*/
|
||||
if (this == myself ||
|
||||
this->flags & (REDIS_NODE_HANDSHAKE|REDIS_NODE_NOADDR) ||
|
||||
if (this->flags & (REDIS_NODE_HANDSHAKE|REDIS_NODE_NOADDR) ||
|
||||
(this->link == NULL && this->numslots == 0))
|
||||
{
|
||||
freshnodes--; /* otherwise we may loop forever. */
|
||||
continue;
|
||||
freshnodes--; /* Tecnically not correct, but saves CPU. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check if we already added this node */
|
||||
@@ -2125,13 +2202,19 @@ void clusterSendPing(clusterLink *link, int type) {
|
||||
memcpy(gossip->ip,this->ip,sizeof(this->ip));
|
||||
gossip->port = htons(this->port);
|
||||
gossip->flags = htons(this->flags);
|
||||
gossip->notused1 = 0;
|
||||
gossip->notused2 = 0;
|
||||
gossipcount++;
|
||||
}
|
||||
|
||||
/* Ready to send... fix the totlen fiend and queue the message in the
|
||||
* output buffer. */
|
||||
totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
|
||||
totlen += (sizeof(clusterMsgDataGossip)*gossipcount);
|
||||
hdr->count = htons(gossipcount);
|
||||
hdr->totlen = htonl(totlen);
|
||||
clusterSendMessage(link,buf,totlen);
|
||||
zfree(buf);
|
||||
}
|
||||
|
||||
/* Send a PONG packet to every connected node that's not in handshake state
|
||||
@@ -2778,6 +2861,7 @@ void clusterHandleSlaveMigration(int max_slaves) {
|
||||
}
|
||||
}
|
||||
}
|
||||
dictReleaseIterator(di);
|
||||
|
||||
/* Step 4: perform the migration if there is a target, and if I'm the
|
||||
* candidate. */
|
||||
@@ -2899,7 +2983,7 @@ void clusterCron(void) {
|
||||
/* A Node in HANDSHAKE state has a limited lifespan equal to the
|
||||
* configured node timeout. */
|
||||
if (nodeInHandshake(node) && now - node->ctime > handshake_timeout) {
|
||||
freeClusterNode(node);
|
||||
clusterDelNode(node);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -4010,6 +4094,18 @@ void clusterCommand(redisClient *c) {
|
||||
addReplyBulkCString(c,ni);
|
||||
sdsfree(ni);
|
||||
}
|
||||
} else if (!strcasecmp(c->argv[1]->ptr,"count-failure-reports") &&
|
||||
c->argc == 3)
|
||||
{
|
||||
/* CLUSTER COUNT-FAILURE-REPORTS <NODE ID> */
|
||||
clusterNode *n = clusterLookupNode(c->argv[2]->ptr);
|
||||
|
||||
if (!n) {
|
||||
addReplyErrorFormat(c,"Unknown node %s", (char*)c->argv[2]->ptr);
|
||||
return;
|
||||
} else {
|
||||
addReplyLongLong(c,clusterNodeFailureReportsCount(n));
|
||||
}
|
||||
} else if (!strcasecmp(c->argv[1]->ptr,"failover") &&
|
||||
(c->argc == 2 || c->argc == 3))
|
||||
{
|
||||
|
||||
+6
-4
@@ -163,10 +163,11 @@ typedef struct {
|
||||
char nodename[REDIS_CLUSTER_NAMELEN];
|
||||
uint32_t ping_sent;
|
||||
uint32_t pong_received;
|
||||
char ip[REDIS_IP_STR_LEN]; /* IP address last time it was seen */
|
||||
uint16_t port; /* port last time it was seen */
|
||||
uint16_t flags;
|
||||
uint32_t notused; /* for 64 bit alignment */
|
||||
char ip[REDIS_IP_STR_LEN]; /* IP address last time it was seen */
|
||||
uint16_t port; /* port last time it was seen */
|
||||
uint16_t flags; /* node->flags copy */
|
||||
uint16_t notused1; /* Some room for future improvements. */
|
||||
uint32_t notused2;
|
||||
} clusterMsgDataGossip;
|
||||
|
||||
typedef struct {
|
||||
@@ -211,6 +212,7 @@ union clusterMsgData {
|
||||
} update;
|
||||
};
|
||||
|
||||
#define CLUSTER_PROTO_VER 0 /* Cluster bus protocol version. */
|
||||
|
||||
typedef struct {
|
||||
char sig[4]; /* Siganture "RCmb" (Redis Cluster message bus). */
|
||||
|
||||
+60
-6
@@ -60,6 +60,8 @@ clientBufferLimitsConfig clientBufferLimitsDefaults[REDIS_CLIENT_TYPE_COUNT] = {
|
||||
* Config file parsing
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
int supervisedToMode(const char *str);
|
||||
|
||||
int yesnotoi(char *s) {
|
||||
if (!strcasecmp(s,"yes")) return 1;
|
||||
else if (!strcasecmp(s,"no")) return 0;
|
||||
@@ -274,6 +276,10 @@ void loadServerConfigFromString(char *config) {
|
||||
if ((server.repl_diskless_sync = yesnotoi(argv[1])) == -1) {
|
||||
err = "argument must be 'yes' or 'no'"; goto loaderr;
|
||||
}
|
||||
} else if (!strcasecmp(argv[0],"repl-no-sync") && argc==2) {
|
||||
if ((server.repl_no_sync = yesnotoi(argv[1])) == -1) {
|
||||
err = "argument must be 'yes' or 'no'"; goto loaderr;
|
||||
}
|
||||
} else if (!strcasecmp(argv[0],"repl-diskless-sync-delay") && argc==2) {
|
||||
server.repl_diskless_sync_delay = atoi(argv[1]);
|
||||
if (server.repl_diskless_sync_delay < 0) {
|
||||
@@ -533,6 +539,15 @@ void loadServerConfigFromString(char *config) {
|
||||
goto loaderr;
|
||||
}
|
||||
server.notify_keyspace_events = flags;
|
||||
} else if (!strcasecmp(argv[0],"supervised") && argc == 2) {
|
||||
int mode = supervisedToMode(argv[1]);
|
||||
|
||||
if (mode == -1) {
|
||||
err = "Invalid option for 'supervised'. "
|
||||
"Allowed values: 'upstart', 'systemd', 'auto', or 'no'";
|
||||
goto loaderr;
|
||||
}
|
||||
server.supervised_mode = mode;
|
||||
} else if (!strcasecmp(argv[0],"sentinel")) {
|
||||
/* argc == 1 is handled by main() as we need to enter the sentinel
|
||||
* mode ASAP. */
|
||||
@@ -613,6 +628,7 @@ void loadServerConfig(char *filename, char *options) {
|
||||
void configSetCommand(redisClient *c) {
|
||||
robj *o;
|
||||
long long ll;
|
||||
int err;
|
||||
redisAssertWithInfo(c,c->argv[2],sdsEncodedObject(c->argv[2]));
|
||||
redisAssertWithInfo(c,c->argv[3],sdsEncodedObject(c->argv[3]));
|
||||
o = c->argv[3];
|
||||
@@ -632,8 +648,8 @@ void configSetCommand(redisClient *c) {
|
||||
zfree(server.masterauth);
|
||||
server.masterauth = ((char*)o->ptr)[0] ? zstrdup(o->ptr) : NULL;
|
||||
} else if (!strcasecmp(c->argv[2]->ptr,"maxmemory")) {
|
||||
if (getLongLongFromObject(o,&ll) == REDIS_ERR ||
|
||||
ll < 0) goto badfmt;
|
||||
ll = memtoll(o->ptr,&err);
|
||||
if (err || ll < 0) goto badfmt;
|
||||
server.maxmemory = ll;
|
||||
if (server.maxmemory) {
|
||||
if (server.maxmemory < zmalloc_used_memory()) {
|
||||
@@ -855,7 +871,6 @@ void configSetCommand(redisClient *c) {
|
||||
* whole configuration string or accept it all, even if a single
|
||||
* error in a single client class is present. */
|
||||
for (j = 0; j < vlen; j++) {
|
||||
char *eptr;
|
||||
long val;
|
||||
|
||||
if ((j % 4) == 0) {
|
||||
@@ -864,8 +879,8 @@ void configSetCommand(redisClient *c) {
|
||||
goto badfmt;
|
||||
}
|
||||
} else {
|
||||
val = strtoll(v[j], &eptr, 10);
|
||||
if (eptr[0] != '\0' || val < 0) {
|
||||
val = memtoll(v[j], &err);
|
||||
if (err || val < 0) {
|
||||
sdsfreesplitres(v,vlen);
|
||||
goto badfmt;
|
||||
}
|
||||
@@ -899,7 +914,8 @@ void configSetCommand(redisClient *c) {
|
||||
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) goto badfmt;
|
||||
server.repl_timeout = ll;
|
||||
} else if (!strcasecmp(c->argv[2]->ptr,"repl-backlog-size")) {
|
||||
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) goto badfmt;
|
||||
ll = memtoll(o->ptr,&err);
|
||||
if (err || ll < 0) goto badfmt;
|
||||
resizeReplicationBacklog(ll);
|
||||
} else if (!strcasecmp(c->argv[2]->ptr,"repl-backlog-ttl")) {
|
||||
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt;
|
||||
@@ -1022,6 +1038,33 @@ char *maxmemoryToString() {
|
||||
return s;
|
||||
}
|
||||
|
||||
int supervisedToMode(const char *str) {
|
||||
int mode;
|
||||
if (!strcasecmp(str,"upstart")) {
|
||||
mode = REDIS_SUPERVISED_UPSTART;
|
||||
} else if (!strcasecmp(str,"systemd")) {
|
||||
mode = REDIS_SUPERVISED_SYSTEMD;
|
||||
} else if (!strcasecmp(str,"auto")) {
|
||||
mode = REDIS_SUPERVISED_AUTODETECT;
|
||||
} else if (!strcasecmp(str,"no")) {
|
||||
mode = REDIS_SUPERVISED_NONE;
|
||||
} else {
|
||||
mode = -1;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
char *supervisedToString(void) {
|
||||
char *s;
|
||||
switch(server.supervised_mode) {
|
||||
case REDIS_SUPERVISED_UPSTART: s = "upstart"; break;
|
||||
case REDIS_SUPERVISED_SYSTEMD: s = "systemd"; break;
|
||||
case REDIS_SUPERVISED_AUTODETECT: s = "auto"; break;
|
||||
case REDIS_SUPERVISED_NONE: s = "no"; break;
|
||||
default: s = "no"; break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
void configGetCommand(redisClient *c) {
|
||||
robj *o = c->argv[2];
|
||||
void *replylen = addDeferredMultiBulkLength(c);
|
||||
@@ -1177,6 +1220,11 @@ void configGetCommand(redisClient *c) {
|
||||
addReplyBulkCString(c,s);
|
||||
matches++;
|
||||
}
|
||||
if (stringmatch(pattern,"supervised",0)) {
|
||||
addReplyBulkCString(c,"supervised");
|
||||
addReplyBulkCString(c,supervisedToString());
|
||||
matches++;
|
||||
}
|
||||
if (stringmatch(pattern,"client-output-buffer-limit",0)) {
|
||||
sds buf = sdsempty();
|
||||
int j;
|
||||
@@ -1872,6 +1920,12 @@ int rewriteConfig(char *path) {
|
||||
rewriteConfigNumericalOption(state,"hz",server.hz,REDIS_DEFAULT_HZ);
|
||||
rewriteConfigYesNoOption(state,"aof-rewrite-incremental-fsync",server.aof_rewrite_incremental_fsync,REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC);
|
||||
rewriteConfigYesNoOption(state,"aof-load-truncated",server.aof_load_truncated,REDIS_DEFAULT_AOF_LOAD_TRUNCATED);
|
||||
rewriteConfigEnumOption(state,"supervised",server.supervised_mode,
|
||||
"upstart", REDIS_SUPERVISED_UPSTART,
|
||||
"systemd", REDIS_SUPERVISED_SYSTEMD,
|
||||
"auto", REDIS_SUPERVISED_AUTODETECT,
|
||||
"no", REDIS_SUPERVISED_NONE,
|
||||
NULL, REDIS_SUPERVISED_NONE);
|
||||
if (server.sentinel_mode) rewriteConfigSentinelOption(state);
|
||||
|
||||
/* Step 3: remove all the orphaned lines in the old file, that is, lines
|
||||
|
||||
+7
-4
@@ -34,6 +34,11 @@
|
||||
#include <AvailabilityMacros.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/version.h>
|
||||
#include <features.h>
|
||||
#endif
|
||||
|
||||
/* Define redis_fstat to fstat or fstat64() */
|
||||
#if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_6)
|
||||
#define redis_fstat fstat64
|
||||
@@ -57,7 +62,7 @@
|
||||
#endif
|
||||
|
||||
/* Test for backtrace() */
|
||||
#if defined(__APPLE__) || defined(__linux__)
|
||||
#if defined(__APPLE__) || (defined(__linux__) && defined(__GLIBC__))
|
||||
#define HAVE_BACKTRACE 1
|
||||
#endif
|
||||
|
||||
@@ -92,8 +97,6 @@
|
||||
/* Define rdb_fsync_range to sync_file_range() on Linux, otherwise we use
|
||||
* the plain fsync() call. */
|
||||
#ifdef __linux__
|
||||
#include <linux/version.h>
|
||||
#include <features.h>
|
||||
#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
|
||||
#if (LINUX_VERSION_CODE >= 0x020611 && __GLIBC_PREREQ(2, 6))
|
||||
#define HAVE_SYNC_FILE_RANGE 1
|
||||
@@ -118,7 +121,7 @@
|
||||
#define USE_SETPROCTITLE
|
||||
#endif
|
||||
|
||||
#if (defined __linux || defined __APPLE__)
|
||||
#if ((defined __linux && defined(__GLIBC__)) || defined __APPLE__)
|
||||
#define USE_SETPROCTITLE
|
||||
#define INIT_SETPROCTITLE_REPLACEMENT
|
||||
void spt_init(int argc, char *argv[]);
|
||||
|
||||
@@ -418,6 +418,13 @@ void debugCommand(redisClient *c) {
|
||||
errstr = sdsmapchars(errstr,"\n\r"," ",2); /* no newlines in errors. */
|
||||
errstr = sdscatlen(errstr,"\r\n",2);
|
||||
addReplySds(c,errstr);
|
||||
} else if (!strcasecmp(c->argv[1]->ptr,"structsize") && c->argc == 2) {
|
||||
sds sizes = sdsempty();
|
||||
sizes = sdscatprintf(sizes,"bits:%d ", (sizeof(void*) == 8)?64:32);
|
||||
sizes = sdscatprintf(sizes,"robj:%d ", (int)sizeof(robj));
|
||||
sizes = sdscatprintf(sizes,"dictentry:%d ", (int)sizeof(dictEntry));
|
||||
sizes = sdscatprintf(sizes,"sdshdr:%d", (int)sizeof(struct sdshdr));
|
||||
addReplyBulkSds(c,sizes);
|
||||
} else if (!strcasecmp(c->argv[1]->ptr,"jemalloc") && c->argc == 3) {
|
||||
#if defined(USE_JEMALLOC)
|
||||
if (!strcasecmp(c->argv[2]->ptr, "info")) {
|
||||
|
||||
+94
-36
@@ -211,6 +211,9 @@ int dictExpand(dict *d, unsigned long size)
|
||||
if (dictIsRehashing(d) || d->ht[0].used > size)
|
||||
return DICT_ERR;
|
||||
|
||||
/* Rehashing to the same table size is not useful. */
|
||||
if (realsize == d->ht[0].size) return DICT_ERR;
|
||||
|
||||
/* Allocate the new hash table and initialize all pointers to NULL */
|
||||
n.size = realsize;
|
||||
n.sizemask = realsize-1;
|
||||
@@ -232,27 +235,27 @@ int dictExpand(dict *d, unsigned long size)
|
||||
|
||||
/* Performs N steps of incremental rehashing. Returns 1 if there are still
|
||||
* keys to move from the old to the new hash table, otherwise 0 is returned.
|
||||
*
|
||||
* Note that a rehashing step consists in moving a bucket (that may have more
|
||||
* than one key as we use chaining) from the old to the new hash table. */
|
||||
* than one key as we use chaining) from the old to the new hash table, however
|
||||
* since part of the hash table may be composed of empty spaces, it is not
|
||||
* guaranteed that this function will rehash even a single bucket, since it
|
||||
* will visit at max N*10 empty buckets in total, otherwise the amount of
|
||||
* work it does would be unbound and the function may block for a long time. */
|
||||
int dictRehash(dict *d, int n) {
|
||||
int empty_visits = n*10; /* Max number of empty buckets to visit. */
|
||||
if (!dictIsRehashing(d)) return 0;
|
||||
|
||||
while(n--) {
|
||||
while(n-- && d->ht[0].used != 0) {
|
||||
dictEntry *de, *nextde;
|
||||
|
||||
/* Check if we already rehashed the whole table... */
|
||||
if (d->ht[0].used == 0) {
|
||||
zfree(d->ht[0].table);
|
||||
d->ht[0] = d->ht[1];
|
||||
_dictReset(&d->ht[1]);
|
||||
d->rehashidx = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Note that rehashidx can't overflow as we are sure there are more
|
||||
* elements because ht[0].used != 0 */
|
||||
assert(d->ht[0].size > (unsigned long)d->rehashidx);
|
||||
while(d->ht[0].table[d->rehashidx] == NULL) d->rehashidx++;
|
||||
while(d->ht[0].table[d->rehashidx] == NULL) {
|
||||
d->rehashidx++;
|
||||
if (--empty_visits == 0) return 1;
|
||||
}
|
||||
de = d->ht[0].table[d->rehashidx];
|
||||
/* Move all the keys in this bucket from the old to the new hash HT */
|
||||
while(de) {
|
||||
@@ -270,6 +273,17 @@ int dictRehash(dict *d, int n) {
|
||||
d->ht[0].table[d->rehashidx] = NULL;
|
||||
d->rehashidx++;
|
||||
}
|
||||
|
||||
/* Check if we already rehashed the whole table... */
|
||||
if (d->ht[0].used == 0) {
|
||||
zfree(d->ht[0].table);
|
||||
d->ht[0] = d->ht[1];
|
||||
_dictReset(&d->ht[1]);
|
||||
d->rehashidx = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* More to rehash... */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -342,7 +356,10 @@ dictEntry *dictAddRaw(dict *d, void *key)
|
||||
if ((index = _dictKeyIndex(d, key)) == -1)
|
||||
return NULL;
|
||||
|
||||
/* Allocate the memory and store the new entry */
|
||||
/* Allocate the memory and store the new entry.
|
||||
* Insert the element in top, with the assumption that in a database
|
||||
* system it is more likely that recently added entries are accessed
|
||||
* more frequently. */
|
||||
ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0];
|
||||
entry = zmalloc(sizeof(*entry));
|
||||
entry->next = ht->table[index];
|
||||
@@ -616,7 +633,11 @@ dictEntry *dictGetRandomKey(dict *d)
|
||||
if (dictIsRehashing(d)) _dictRehashStep(d);
|
||||
if (dictIsRehashing(d)) {
|
||||
do {
|
||||
h = random() % (d->ht[0].size+d->ht[1].size);
|
||||
/* We are sure there are no elements in indexes from 0
|
||||
* to rehashidx-1 */
|
||||
h = d->rehashidx + (random() % (d->ht[0].size +
|
||||
d->ht[1].size -
|
||||
d->rehashidx));
|
||||
he = (h >= d->ht[0].size) ? d->ht[1].table[h - d->ht[0].size] :
|
||||
d->ht[0].table[h];
|
||||
} while(he == NULL);
|
||||
@@ -643,9 +664,12 @@ dictEntry *dictGetRandomKey(dict *d)
|
||||
return he;
|
||||
}
|
||||
|
||||
/* This is a version of dictGetRandomKey() that is modified in order to
|
||||
* return multiple entries by jumping at a random place of the hash table
|
||||
* and scanning linearly for entries.
|
||||
/* This function samples the dictionary to return a few keys from random
|
||||
* locations.
|
||||
*
|
||||
* It does not guarantee to return all the keys specified in 'count', nor
|
||||
* it does guarantee to return non-duplicated elements, however it will make
|
||||
* some effort to do both things.
|
||||
*
|
||||
* Returned pointers to hash table entries are stored into 'des' that
|
||||
* points to an array of dictEntry pointers. The array must have room for
|
||||
@@ -654,28 +678,65 @@ dictEntry *dictGetRandomKey(dict *d)
|
||||
*
|
||||
* The function returns the number of items stored into 'des', that may
|
||||
* be less than 'count' if the hash table has less than 'count' elements
|
||||
* inside.
|
||||
* inside, or if not enough elements were found in a reasonable amount of
|
||||
* steps.
|
||||
*
|
||||
* Note that this function is not suitable when you need a good distribution
|
||||
* of the returned items, but only when you need to "sample" a given number
|
||||
* of continuous elements to run some kind of algorithm or to produce
|
||||
* statistics. However the function is much faster than dictGetRandomKey()
|
||||
* at producing N elements, and the elements are guaranteed to be non
|
||||
* repeating. */
|
||||
unsigned int dictGetRandomKeys(dict *d, dictEntry **des, unsigned int count) {
|
||||
int j; /* internal hash table id, 0 or 1. */
|
||||
unsigned int stored = 0;
|
||||
* at producing N elements. */
|
||||
unsigned int dictGetSomeKeys(dict *d, dictEntry **des, unsigned int count) {
|
||||
unsigned int j; /* internal hash table id, 0 or 1. */
|
||||
unsigned int tables; /* 1 or 2 tables? */
|
||||
unsigned int stored = 0, maxsizemask;
|
||||
unsigned int maxsteps;
|
||||
|
||||
if (dictSize(d) < count) count = dictSize(d);
|
||||
while(stored < count) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
/* Pick a random point inside the hash table 0 or 1. */
|
||||
unsigned int i = random() & d->ht[j].sizemask;
|
||||
int size = d->ht[j].size;
|
||||
maxsteps = count*10;
|
||||
|
||||
/* Make sure to visit every bucket by iterating 'size' times. */
|
||||
while(size--) {
|
||||
dictEntry *he = d->ht[j].table[i];
|
||||
/* Try to do a rehashing work proportional to 'count'. */
|
||||
for (j = 0; j < count; j++) {
|
||||
if (dictIsRehashing(d))
|
||||
_dictRehashStep(d);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
tables = dictIsRehashing(d) ? 2 : 1;
|
||||
maxsizemask = d->ht[0].sizemask;
|
||||
if (tables > 1 && maxsizemask < d->ht[1].sizemask)
|
||||
maxsizemask = d->ht[1].sizemask;
|
||||
|
||||
/* Pick a random point inside the larger table. */
|
||||
unsigned int i = random() & maxsizemask;
|
||||
unsigned int emptylen = 0; /* Continuous empty entries so far. */
|
||||
while(stored < count && maxsteps--) {
|
||||
for (j = 0; j < tables; j++) {
|
||||
/* Invariant of the dict.c rehashing: up to the indexes already
|
||||
* visited in ht[0] during the rehashing, there are no populated
|
||||
* buckets, so we can skip ht[0] for indexes between 0 and idx-1. */
|
||||
if (tables == 2 && j == 0 && i < d->rehashidx) {
|
||||
/* Moreover, if we are currently out of range in the second
|
||||
* table, there will be no elements in both tables up to
|
||||
* the current rehashing index, so we jump if possible.
|
||||
* (this happens when going from big to small table). */
|
||||
if (i >= d->ht[1].size) i = d->rehashidx;
|
||||
continue;
|
||||
}
|
||||
if (i >= d->ht[j].size) continue; /* Out of range for this table. */
|
||||
dictEntry *he = d->ht[j].table[i];
|
||||
|
||||
/* Count contiguous empty buckets, and jump to other
|
||||
* locations if they reach 'count' (with a minimum of 5). */
|
||||
if (he == NULL) {
|
||||
emptylen++;
|
||||
if (emptylen >= 5 && emptylen > count) {
|
||||
i = random() & maxsizemask;
|
||||
emptylen = 0;
|
||||
}
|
||||
} else {
|
||||
emptylen = 0;
|
||||
while (he) {
|
||||
/* Collect all the elements of the buckets found non
|
||||
* empty while iterating. */
|
||||
@@ -685,14 +746,11 @@ unsigned int dictGetRandomKeys(dict *d, dictEntry **des, unsigned int count) {
|
||||
stored++;
|
||||
if (stored == count) return stored;
|
||||
}
|
||||
i = (i+1) & d->ht[j].sizemask;
|
||||
}
|
||||
/* If there is only one table and we iterated it all, we should
|
||||
* already have 'count' elements. Assert this condition. */
|
||||
assert(dictIsRehashing(d) != 0);
|
||||
}
|
||||
i = (i+1) & maxsizemask;
|
||||
}
|
||||
return stored; /* Never reached. */
|
||||
return stored;
|
||||
}
|
||||
|
||||
/* Function to reverse bits. Algorithm from:
|
||||
|
||||
+1
-1
@@ -164,7 +164,7 @@ dictIterator *dictGetSafeIterator(dict *d);
|
||||
dictEntry *dictNext(dictIterator *iter);
|
||||
void dictReleaseIterator(dictIterator *iter);
|
||||
dictEntry *dictGetRandomKey(dict *d);
|
||||
unsigned int dictGetRandomKeys(dict *d, dictEntry **des, unsigned int count);
|
||||
unsigned int dictGetSomeKeys(dict *d, dictEntry **des, unsigned int count);
|
||||
void dictPrintStats(dict *d);
|
||||
unsigned int dictGenHashFunction(const void *key, int len);
|
||||
unsigned int dictGenCaseHashFunction(const unsigned char *buf, int len);
|
||||
|
||||
@@ -261,90 +261,6 @@ int64_t intsetRandom(intset *is) {
|
||||
return _intsetGet(is,rand()%intrev32ifbe(is->length));
|
||||
}
|
||||
|
||||
/* How many times bigger should the set length be compared to the requested
|
||||
* count of members for us to use the Floyd algorithm instead of
|
||||
* the Knuth algorithm */
|
||||
#define RANDOMMEMBERS_ALGORITHM_SELECTION_RATIO (2)
|
||||
|
||||
/* Copies 'count' random members from the set into the 'values' array.
|
||||
* 'values' must be an array of int64_t values, of length 'count'.
|
||||
* Returns the amount of items returned. If this amount is less than 'count',
|
||||
* then the remaining 'values' are left uninitialized. */
|
||||
int intsetRandomMembers(intset *is, int64_t* values, int count) {
|
||||
|
||||
/* We don't check that is and values are non-NULL - the caller must
|
||||
* play nice. */
|
||||
|
||||
int length = intsetLen(is);
|
||||
|
||||
if (count > length) {
|
||||
/* Return everything in the set */
|
||||
count = length;
|
||||
}
|
||||
|
||||
/* Choose between the Knuth shuffle algorithm, O(1) space, O(length) time,
|
||||
* and the Floyd algorithm, O(length) space, O(count) time. */
|
||||
if ((RANDOMMEMBERS_ALGORITHM_SELECTION_RATIO * count) > length) {
|
||||
|
||||
/* If the count of members requested is almost the length of the set,
|
||||
* use the Knuth shuffle algorithm, O(1) space, O(length) time. */
|
||||
|
||||
/* First, fill the values array with unique random indexes inside
|
||||
* the set. */
|
||||
int in, im, rn, rm;
|
||||
im = 0;
|
||||
for (in = 0; in < length && im < count; in++) {
|
||||
|
||||
rn = length - in;
|
||||
rm = count - im;
|
||||
if (rand() % rn < rm) {
|
||||
values[im++] = in;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/* If the length is considerably more than the count of members
|
||||
* requested, use Robert Floyd's algorithm, O(length) space,
|
||||
* O(count) time.
|
||||
* Based on Jon Bentley's Programming Pearls */
|
||||
|
||||
int64_t *is_used = zcalloc(sizeof(int64_t) * length);
|
||||
int in, im, r;
|
||||
|
||||
r = 0;
|
||||
im = 0;
|
||||
|
||||
for (in = length - count; in < length && im < count; in++) {
|
||||
|
||||
/* Generate a random number r */
|
||||
r = rand() % (in + 1);
|
||||
|
||||
/* Do we already have the value in r? */
|
||||
if (is_used[r]) {
|
||||
/* Use in instead of the generated number */
|
||||
r = in;
|
||||
}
|
||||
|
||||
values[im++] = r ;
|
||||
|
||||
/* Mark it as used */
|
||||
is_used[r] = 1;
|
||||
}
|
||||
|
||||
zfree(is_used);
|
||||
}
|
||||
|
||||
/* Replace each random index with the value stored there in the intset */
|
||||
uint8_t encoding = intrev32ifbe(is->encoding);
|
||||
for (int currentValue = 0; currentValue < count; currentValue++) {
|
||||
values[currentValue] =
|
||||
_intsetGetEncoded(is, values[currentValue], encoding);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/* Sets the value to the value at the given position. When this position is
|
||||
* out of range the function returns 0, when in range it returns 1. */
|
||||
uint8_t intsetGet(intset *is, uint32_t pos, int64_t *value) {
|
||||
|
||||
@@ -43,7 +43,6 @@ intset *intsetAdd(intset *is, int64_t value, uint8_t *success);
|
||||
intset *intsetRemove(intset *is, int64_t value, int *success);
|
||||
uint8_t intsetFind(intset *is, int64_t value);
|
||||
int64_t intsetRandom(intset *is);
|
||||
int intsetRandomMembers(intset *is, int64_t* value, int count);
|
||||
uint8_t intsetGet(intset *is, uint32_t pos, int64_t *value);
|
||||
uint32_t intsetLen(intset *is);
|
||||
size_t intsetBlobLen(intset *is);
|
||||
|
||||
+11
-1
@@ -228,6 +228,7 @@ sds createLatencyReport(void) {
|
||||
int advise_write_load_info = 0; /* Print info about AOF and write load. */
|
||||
int advise_hz = 0; /* Use higher HZ. */
|
||||
int advise_large_objects = 0; /* Deletion of large objects. */
|
||||
int advise_mass_eviction = 0; /* Avoid mass eviction of keys. */
|
||||
int advise_relax_fsync_policy = 0; /* appendfsync always is slow. */
|
||||
int advise_disable_thp = 0; /* AnonHugePages detected. */
|
||||
int advices = 0;
|
||||
@@ -364,11 +365,16 @@ sds createLatencyReport(void) {
|
||||
}
|
||||
|
||||
/* Eviction cycle. */
|
||||
if (!strcasecmp(event,"eviction-cycle")) {
|
||||
if (!strcasecmp(event,"eviction-del")) {
|
||||
advise_large_objects = 1;
|
||||
advices++;
|
||||
}
|
||||
|
||||
if (!strcasecmp(event,"eviction-cycle")) {
|
||||
advise_mass_eviction = 1;
|
||||
advices++;
|
||||
}
|
||||
|
||||
report = sdscatlen(report,"\n",1);
|
||||
}
|
||||
dictReleaseIterator(di);
|
||||
@@ -452,6 +458,10 @@ sds createLatencyReport(void) {
|
||||
report = sdscat(report,"- Deleting, expiring or evicting (because of maxmemory policy) large objects is a blocking operation. If you have very large objects that are often deleted, expired, or evicted, try to fragment those objects into multiple smaller objects.\n");
|
||||
}
|
||||
|
||||
if (advise_mass_eviction) {
|
||||
report = sdscat(report,"- Sudden changes to the 'maxmemory' setting via 'CONFIG SET', or allocation of large objects via sets or sorted sets intersections, STORE option of SORT, Redis Cluster large keys migrations (RESTORE command), may create sudden memory pressure forcing the server to block trying to evict keys. \n");
|
||||
}
|
||||
|
||||
if (advise_disable_thp) {
|
||||
report = sdscat(report,"- I detected a non zero amount of anonymous huge pages used by your process. This creates very serious latency events in different conditions, especially when Redis is persisting on disk. To disable THP support use the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled', make sure to also add it into /etc/rc.local so that the command will be executed again after a reboot. Note that even if you have already disabled THP, you still need to restart the Redis process to get rid of the huge pages already created.\n");
|
||||
}
|
||||
|
||||
@@ -86,4 +86,8 @@ int THPIsEnabled(void);
|
||||
(var) >= server.latency_monitor_threshold) \
|
||||
latencyAddSample((event),(var));
|
||||
|
||||
/* Remove time from a nested event. */
|
||||
#define latencyRemoveNestedEvent(event_var,nested_var) \
|
||||
event_var += nested_var;
|
||||
|
||||
#endif /* __LATENCY_H */
|
||||
|
||||
+4
-1
@@ -673,7 +673,10 @@ void freeClient(redisClient *c) {
|
||||
*
|
||||
* Note that before doing this we make sure that the client is not in
|
||||
* some unexpected state, by checking its flags. */
|
||||
if (server.master && c->flags & REDIS_MASTER) {
|
||||
if (server.master &&
|
||||
c->flags & REDIS_MASTER &&
|
||||
server.repl_no_sync == 0)
|
||||
{
|
||||
redisLog(REDIS_WARNING,"Connection with master lost.");
|
||||
if (!(c->flags & (REDIS_CLOSE_AFTER_REPLY|
|
||||
REDIS_CLOSE_ASAP|
|
||||
|
||||
+15
-16
@@ -44,7 +44,7 @@
|
||||
#endif
|
||||
|
||||
/* Optimization levels for size-based filling */
|
||||
static const size_t optimization_level[] = { 4096, 8192, 16384, 32768, 65536 };
|
||||
static const size_t optimization_level[] = {4096, 8192, 16384, 32768, 65536};
|
||||
|
||||
/* Maximum size in bytes of any multi-element ziplist.
|
||||
* Larger values will live in their own isolated ziplists. */
|
||||
@@ -79,7 +79,7 @@ static const size_t optimization_level[] = { 4096, 8192, 16384, 32768, 65536 };
|
||||
(e)->node = NULL; \
|
||||
(e)->offset = 123456789; \
|
||||
(e)->sz = 0; \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
@@ -544,7 +544,7 @@ quicklist *quicklistAppendValuesFromZiplist(quicklist *quicklist,
|
||||
unsigned char *value;
|
||||
unsigned int sz;
|
||||
long long longval;
|
||||
char longstr[32] = { 0 };
|
||||
char longstr[32] = {0};
|
||||
|
||||
unsigned char *p = ziplistIndex(zl, 0);
|
||||
while (ziplistGet(p, &value, &sz, &longval)) {
|
||||
@@ -1287,7 +1287,7 @@ void quicklistRotate(quicklist *quicklist) {
|
||||
unsigned char *value;
|
||||
long long longval;
|
||||
unsigned int sz;
|
||||
char longstr[32] = { 0 };
|
||||
char longstr[32] = {0};
|
||||
ziplistGet(p, &value, &sz, &longval);
|
||||
|
||||
/* If value found is NULL, then ziplistGet populated longval instead */
|
||||
@@ -1371,8 +1371,7 @@ int quicklistPopCustom(quicklist *quicklist, int where, unsigned char **data,
|
||||
REDIS_STATIC void *_quicklistSaver(unsigned char *data, unsigned int sz) {
|
||||
unsigned char *vstr;
|
||||
if (data) {
|
||||
if ((vstr = zmalloc(sz)) == NULL)
|
||||
return 0;
|
||||
vstr = zmalloc(sz);
|
||||
memcpy(data, vstr, sz);
|
||||
return vstr;
|
||||
}
|
||||
@@ -1603,7 +1602,7 @@ static int _ql_verify(quicklist *ql, uint32_t len, uint32_t count,
|
||||
|
||||
/* Generate new string concatenating integer i against string 'prefix' */
|
||||
static char *genstr(char *prefix, int i) {
|
||||
static char result[64] = { 0 };
|
||||
static char result[64] = {0};
|
||||
snprintf(result, sizeof(result), "%s%d", prefix, i);
|
||||
return result;
|
||||
}
|
||||
@@ -1619,7 +1618,7 @@ int quicklistTest(int argc, char *argv[]) {
|
||||
|
||||
printf("Starting optimization offset at: %d\n", optimize_start);
|
||||
|
||||
int options[] = { 0, 1, 2, 3, 4, 5, 6, 10 };
|
||||
int options[] = {0, 1, 2, 3, 4, 5, 6, 10};
|
||||
size_t option_count = sizeof(options) / sizeof(*options);
|
||||
long long runtime[option_count];
|
||||
|
||||
@@ -2268,12 +2267,12 @@ int quicklistTest(int argc, char *argv[]) {
|
||||
for (int f = optimize_start; f < 16; f++) {
|
||||
TEST_DESC("lrem test at fill %d at compress %d", f, options[_i]) {
|
||||
quicklist *ql = quicklistNew(f, options[_i]);
|
||||
char *words[] = { "abc", "foo", "bar", "foobar", "foobared",
|
||||
"zap", "bar", "test", "foo" };
|
||||
char *result[] = { "abc", "foo", "foobar", "foobared",
|
||||
"zap", "test", "foo" };
|
||||
char *resultB[] = { "abc", "foo", "foobar",
|
||||
"foobared", "zap", "test" };
|
||||
char *words[] = {"abc", "foo", "bar", "foobar", "foobared",
|
||||
"zap", "bar", "test", "foo"};
|
||||
char *result[] = {"abc", "foo", "foobar", "foobared",
|
||||
"zap", "test", "foo"};
|
||||
char *resultB[] = {"abc", "foo", "foobar",
|
||||
"foobared", "zap", "test"};
|
||||
for (int i = 0; i < 9; i++)
|
||||
quicklistPushTail(ql, words[i], strlen(words[i]));
|
||||
|
||||
@@ -2376,7 +2375,7 @@ int quicklistTest(int argc, char *argv[]) {
|
||||
/* Check results after deletion of "hij" */
|
||||
iter = quicklistGetIterator(ql, AL_START_HEAD);
|
||||
i = 0;
|
||||
char *vals[] = { "abc", "def", "jkl", "oop" };
|
||||
char *vals[] = {"abc", "def", "jkl", "oop"};
|
||||
while (quicklistNext(iter, &entry)) {
|
||||
if (!quicklistCompare(entry.zi, (unsigned char *)vals[i],
|
||||
3)) {
|
||||
@@ -2575,7 +2574,7 @@ int quicklistTest(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
/* Run a longer test of compression depth outside of primary test loop. */
|
||||
int list_sizes[] = { 250, 251, 500, 999, 1000 };
|
||||
int list_sizes[] = {250, 251, 500, 999, 1000};
|
||||
long long start = mstime();
|
||||
for (int list = 0; list < (int)(sizeof(list_sizes) / sizeof(*list_sizes));
|
||||
list++) {
|
||||
|
||||
@@ -44,6 +44,16 @@
|
||||
#define RDB_LOAD_ENC (1<<0)
|
||||
#define RDB_LOAD_PLAIN (1<<1)
|
||||
|
||||
#define rdbExitReportCorruptRDB(reason) rdbCheckThenExit(reason, __LINE__);
|
||||
|
||||
void rdbCheckThenExit(char *reason, int where) {
|
||||
redisLog(REDIS_WARNING, "Corrupt RDB detected at rdb.c:%d (%s). "
|
||||
"Running 'redis-check-rdb %s'",
|
||||
where, reason, server.rdb_filename);
|
||||
redis_check_rdb(server.rdb_filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static int rdbWriteRaw(rio *rdb, void *p, size_t len) {
|
||||
if (rdb && rioWrite(rdb,p,len) == 0)
|
||||
return -1;
|
||||
@@ -188,7 +198,7 @@ void *rdbLoadIntegerObject(rio *rdb, int enctype, int flags) {
|
||||
val = (int32_t)v;
|
||||
} else {
|
||||
val = 0; /* anti-warning */
|
||||
redisPanic("Unknown RDB integer encoding type");
|
||||
rdbExitReportCorruptRDB("Unknown RDB integer encoding type");
|
||||
}
|
||||
if (plain) {
|
||||
char buf[REDIS_LONGSTR_SIZE], *p;
|
||||
@@ -394,7 +404,7 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags) {
|
||||
case REDIS_RDB_ENC_LZF:
|
||||
return rdbLoadLzfStringObject(rdb,flags);
|
||||
default:
|
||||
redisPanic("Unknown RDB encoding type");
|
||||
rdbExitReportCorruptRDB("Unknown RDB encoding type");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,7 +717,7 @@ int rdbSaveAuxFieldStrInt(rio *rdb, char *key, long long val) {
|
||||
int rdbSaveInfoAuxFields(rio *rdb) {
|
||||
int redis_bits = (sizeof(void*) == 8) ? 64 : 32;
|
||||
|
||||
/* Add a few fiels about the state when the RDB was created. */
|
||||
/* Add a few fields about the state when the RDB was created. */
|
||||
if (rdbSaveAuxFieldStrStr(rdb,"redis-ver",REDIS_VERSION) == -1) return -1;
|
||||
if (rdbSaveAuxFieldStrInt(rdb,"redis-bits",redis_bits) == -1) return -1;
|
||||
if (rdbSaveAuxFieldStrInt(rdb,"ctime",time(NULL)) == -1) return -1;
|
||||
@@ -923,7 +933,7 @@ void rdbRemoveTempFile(pid_t childpid) {
|
||||
/* Load a Redis object of the specified type from the specified file.
|
||||
* On success a newly allocated object is returned, otherwise NULL. */
|
||||
robj *rdbLoadObject(int rdbtype, rio *rdb) {
|
||||
robj *o, *ele, *dec;
|
||||
robj *o = NULL, *ele, *dec;
|
||||
size_t len;
|
||||
unsigned int i;
|
||||
|
||||
@@ -1078,7 +1088,9 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
|
||||
|
||||
/* Add pair to hash table */
|
||||
ret = dictAdd((dict*)o->ptr, field, value);
|
||||
redisAssert(ret == DICT_OK);
|
||||
if (ret == DICT_ERR) {
|
||||
rdbExitReportCorruptRDB("Duplicate keys detected");
|
||||
}
|
||||
}
|
||||
|
||||
/* All pairs should be read by now */
|
||||
@@ -1164,11 +1176,11 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
|
||||
hashTypeConvert(o, REDIS_ENCODING_HT);
|
||||
break;
|
||||
default:
|
||||
redisPanic("Unknown encoding");
|
||||
rdbExitReportCorruptRDB("Unknown encoding");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
redisPanic("Unknown object type");
|
||||
rdbExitReportCorruptRDB("Unknown object type");
|
||||
}
|
||||
return o;
|
||||
}
|
||||
@@ -1316,16 +1328,18 @@ int rdbLoad(char *filename) {
|
||||
/* All the fields with a name staring with '%' are considered
|
||||
* information fields and are logged at startup with a log
|
||||
* level of NOTICE. */
|
||||
redisLog(REDIS_NOTICE,"RDB '%s': %s", auxkey->ptr, auxval->ptr);
|
||||
redisLog(REDIS_NOTICE,"RDB '%s': %s",
|
||||
(char*)auxkey->ptr,
|
||||
(char*)auxval->ptr);
|
||||
} else {
|
||||
/* We ignore fields we don't understand, as by AUX field
|
||||
* contract. */
|
||||
redisLog(REDIS_DEBUG,"Unrecognized RDB AUX field: '%s'",
|
||||
auxkey->ptr);
|
||||
(char*)auxkey->ptr);
|
||||
}
|
||||
|
||||
zfree(auxkey);
|
||||
zfree(auxval);
|
||||
decrRefCount(auxkey);
|
||||
decrRefCount(auxval);
|
||||
continue; /* Read type again. */
|
||||
}
|
||||
|
||||
@@ -1361,7 +1375,7 @@ int rdbLoad(char *filename) {
|
||||
redisLog(REDIS_WARNING,"RDB file was saved with checksum disabled: no check performed.");
|
||||
} else if (cksum != expected) {
|
||||
redisLog(REDIS_WARNING,"Wrong RDB checksum. Aborting now.");
|
||||
exit(1);
|
||||
rdbExitReportCorruptRDB("RDB CRC error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1371,7 +1385,7 @@ int rdbLoad(char *filename) {
|
||||
|
||||
eoferr: /* unexpected end of file is handled here with a fatal exit */
|
||||
redisLog(REDIS_WARNING,"Short read or OOM loading DB. Unrecoverable error, aborting now.");
|
||||
exit(1);
|
||||
rdbExitReportCorruptRDB("Unexpected EOF reading RDB file");
|
||||
return REDIS_ERR; /* Just to avoid warning */
|
||||
}
|
||||
|
||||
|
||||
@@ -29,74 +29,19 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "redis.h"
|
||||
#include "rdb.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include "lzf.h"
|
||||
#include "crc64.h"
|
||||
|
||||
/* Object types */
|
||||
#define REDIS_STRING 0
|
||||
#define REDIS_LIST 1
|
||||
#define REDIS_SET 2
|
||||
#define REDIS_ZSET 3
|
||||
#define REDIS_HASH 4
|
||||
#define REDIS_HASH_ZIPMAP 9
|
||||
#define REDIS_LIST_ZIPLIST 10
|
||||
#define REDIS_SET_INTSET 11
|
||||
#define REDIS_ZSET_ZIPLIST 12
|
||||
#define REDIS_HASH_ZIPLIST 13
|
||||
|
||||
/* Objects encoding. Some kind of objects like Strings and Hashes can be
|
||||
* internally represented in multiple ways. The 'encoding' field of the object
|
||||
* is set to one of this fields for this object. */
|
||||
#define REDIS_ENCODING_RAW 0 /* Raw representation */
|
||||
#define REDIS_ENCODING_INT 1 /* Encoded as integer */
|
||||
#define REDIS_ENCODING_ZIPMAP 2 /* Encoded as zipmap */
|
||||
#define REDIS_ENCODING_HT 3 /* Encoded as a hash table */
|
||||
|
||||
/* Object types only used for dumping to disk */
|
||||
#define REDIS_EXPIRETIME_MS 252
|
||||
#define REDIS_EXPIRETIME 253
|
||||
#define REDIS_SELECTDB 254
|
||||
#define REDIS_EOF 255
|
||||
|
||||
/* Defines related to the dump file format. To store 32 bits lengths for short
|
||||
* keys requires a lot of space, so we check the most significant 2 bits of
|
||||
* the first byte to interpreter the length:
|
||||
*
|
||||
* 00|000000 => if the two MSB are 00 the len is the 6 bits of this byte
|
||||
* 01|000000 00000000 => 01, the len is 14 byes, 6 bits + 8 bits of next byte
|
||||
* 10|000000 [32 bit integer] => if it's 01, a full 32 bit len will follow
|
||||
* 11|000000 this means: specially encoded object will follow. The six bits
|
||||
* number specify the kind of object that follows.
|
||||
* See the REDIS_RDB_ENC_* defines.
|
||||
*
|
||||
* Lengths up to 63 are stored using a single byte, most DB keys, and may
|
||||
* values, will fit inside. */
|
||||
#define REDIS_RDB_6BITLEN 0
|
||||
#define REDIS_RDB_14BITLEN 1
|
||||
#define REDIS_RDB_32BITLEN 2
|
||||
#define REDIS_RDB_ENCVAL 3
|
||||
#define REDIS_RDB_LENERR UINT_MAX
|
||||
|
||||
/* When a length of a string object stored on disk has the first two bits
|
||||
* set, the remaining two bits specify a special encoding for the object
|
||||
* accordingly to the following defines: */
|
||||
#define REDIS_RDB_ENC_INT8 0 /* 8 bit signed integer */
|
||||
#define REDIS_RDB_ENC_INT16 1 /* 16 bit signed integer */
|
||||
#define REDIS_RDB_ENC_INT32 2 /* 32 bit signed integer */
|
||||
#define REDIS_RDB_ENC_LZF 3 /* string compressed with FASTLZ */
|
||||
|
||||
#define ERROR(...) { \
|
||||
printf(__VA_ARGS__); \
|
||||
redisLog(REDIS_WARNING, __VA_ARGS__); \
|
||||
exit(1); \
|
||||
}
|
||||
|
||||
@@ -133,28 +78,23 @@ typedef struct {
|
||||
char success;
|
||||
} entry;
|
||||
|
||||
/* Global vars that are actually used as constants. The following double
|
||||
* values are used for double on-disk serialization, and are initialized
|
||||
* at runtime to avoid strange compiler optimizations. */
|
||||
static double R_Zero, R_PosInf, R_NegInf, R_Nan;
|
||||
|
||||
#define MAX_TYPES_NUM 256
|
||||
#define MAX_TYPE_NAME_LEN 16
|
||||
/* store string types for output */
|
||||
static char types[MAX_TYPES_NUM][MAX_TYPE_NAME_LEN];
|
||||
|
||||
/* Return true if 't' is a valid object type. */
|
||||
int checkType(unsigned char t) {
|
||||
static int rdbCheckType(unsigned char t) {
|
||||
/* In case a new object type is added, update the following
|
||||
* condition as necessary. */
|
||||
return
|
||||
(t >= REDIS_HASH_ZIPMAP && t <= REDIS_HASH_ZIPLIST) ||
|
||||
t <= REDIS_HASH ||
|
||||
t >= REDIS_EXPIRETIME_MS;
|
||||
(t >= REDIS_RDB_TYPE_HASH_ZIPMAP && t <= REDIS_RDB_TYPE_HASH_ZIPLIST) ||
|
||||
t <= REDIS_RDB_TYPE_HASH ||
|
||||
t >= REDIS_RDB_OPCODE_EXPIRETIME_MS;
|
||||
}
|
||||
|
||||
/* when number of bytes to read is negative, do a peek */
|
||||
int readBytes(void *target, long num) {
|
||||
static int readBytes(void *target, long num) {
|
||||
char peek = (num < 0) ? 1 : 0;
|
||||
num = (num < 0) ? -num : num;
|
||||
|
||||
@@ -173,28 +113,28 @@ int processHeader(void) {
|
||||
int dump_version;
|
||||
|
||||
if (!readBytes(buf, 9)) {
|
||||
ERROR("Cannot read header\n");
|
||||
ERROR("Cannot read header");
|
||||
}
|
||||
|
||||
/* expect the first 5 bytes to equal REDIS */
|
||||
if (memcmp(buf,"REDIS",5) != 0) {
|
||||
ERROR("Wrong signature in header\n");
|
||||
ERROR("Wrong signature in header");
|
||||
}
|
||||
|
||||
dump_version = (int)strtol(buf + 5, NULL, 10);
|
||||
if (dump_version < 1 || dump_version > 6) {
|
||||
ERROR("Unknown RDB format version: %d\n", dump_version);
|
||||
ERROR("Unknown RDB format version: %d", dump_version);
|
||||
}
|
||||
return dump_version;
|
||||
}
|
||||
|
||||
int loadType(entry *e) {
|
||||
static int loadType(entry *e) {
|
||||
uint32_t offset = CURR_OFFSET;
|
||||
|
||||
/* this byte needs to qualify as type */
|
||||
unsigned char t;
|
||||
if (readBytes(&t, 1)) {
|
||||
if (checkType(t)) {
|
||||
if (rdbCheckType(t)) {
|
||||
e->type = t;
|
||||
return 1;
|
||||
} else {
|
||||
@@ -208,18 +148,18 @@ int loadType(entry *e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int peekType() {
|
||||
static int peekType() {
|
||||
unsigned char t;
|
||||
if (readBytes(&t, -1) && (checkType(t)))
|
||||
if (readBytes(&t, -1) && (rdbCheckType(t)))
|
||||
return t;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* discard time, just consume the bytes */
|
||||
int processTime(int type) {
|
||||
static int processTime(int type) {
|
||||
uint32_t offset = CURR_OFFSET;
|
||||
unsigned char t[8];
|
||||
int timelen = (type == REDIS_EXPIRETIME_MS) ? 8 : 4;
|
||||
int timelen = (type == REDIS_RDB_OPCODE_EXPIRETIME_MS) ? 8 : 4;
|
||||
|
||||
if (readBytes(t,timelen)) {
|
||||
return 1;
|
||||
@@ -231,7 +171,7 @@ int processTime(int type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t loadLength(int *isencoded) {
|
||||
static uint32_t loadLength(int *isencoded) {
|
||||
unsigned char buf[2];
|
||||
uint32_t len;
|
||||
int type;
|
||||
@@ -257,7 +197,7 @@ uint32_t loadLength(int *isencoded) {
|
||||
}
|
||||
}
|
||||
|
||||
char *loadIntegerObject(int enctype) {
|
||||
static char *loadIntegerObject(int enctype) {
|
||||
uint32_t offset = CURR_OFFSET;
|
||||
unsigned char enc[4];
|
||||
long long val;
|
||||
@@ -284,36 +224,36 @@ char *loadIntegerObject(int enctype) {
|
||||
|
||||
/* convert val into string */
|
||||
char *buf;
|
||||
buf = malloc(sizeof(char) * 128);
|
||||
buf = zmalloc(sizeof(char) * 128);
|
||||
sprintf(buf, "%lld", val);
|
||||
return buf;
|
||||
}
|
||||
|
||||
char* loadLzfStringObject() {
|
||||
static char* loadLzfStringObject() {
|
||||
unsigned int slen, clen;
|
||||
char *c, *s;
|
||||
|
||||
if ((clen = loadLength(NULL)) == REDIS_RDB_LENERR) return NULL;
|
||||
if ((slen = loadLength(NULL)) == REDIS_RDB_LENERR) return NULL;
|
||||
|
||||
c = malloc(clen);
|
||||
c = zmalloc(clen);
|
||||
if (!readBytes(c, clen)) {
|
||||
free(c);
|
||||
zfree(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s = malloc(slen+1);
|
||||
s = zmalloc(slen+1);
|
||||
if (lzf_decompress(c,clen,s,slen) == 0) {
|
||||
free(c); free(s);
|
||||
zfree(c); zfree(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free(c);
|
||||
zfree(c);
|
||||
return s;
|
||||
}
|
||||
|
||||
/* returns NULL when not processable, char* when valid */
|
||||
char* loadStringObject() {
|
||||
static char* loadStringObject() {
|
||||
uint32_t offset = CURR_OFFSET;
|
||||
int isencoded;
|
||||
uint32_t len;
|
||||
@@ -336,48 +276,48 @@ char* loadStringObject() {
|
||||
|
||||
if (len == REDIS_RDB_LENERR) return NULL;
|
||||
|
||||
char *buf = malloc(sizeof(char) * (len+1));
|
||||
char *buf = zmalloc(sizeof(char) * (len+1));
|
||||
if (buf == NULL) return NULL;
|
||||
buf[len] = '\0';
|
||||
if (!readBytes(buf, len)) {
|
||||
free(buf);
|
||||
zfree(buf);
|
||||
return NULL;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
int processStringObject(char** store) {
|
||||
static int processStringObject(char** store) {
|
||||
unsigned long offset = CURR_OFFSET;
|
||||
char *key = loadStringObject();
|
||||
if (key == NULL) {
|
||||
SHIFT_ERROR(offset, "Error reading string object");
|
||||
free(key);
|
||||
zfree(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (store != NULL) {
|
||||
*store = key;
|
||||
} else {
|
||||
free(key);
|
||||
zfree(key);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
double* loadDoubleValue() {
|
||||
static double* loadDoubleValue() {
|
||||
char buf[256];
|
||||
unsigned char len;
|
||||
double* val;
|
||||
|
||||
if (!readBytes(&len,1)) return NULL;
|
||||
|
||||
val = malloc(sizeof(double));
|
||||
val = zmalloc(sizeof(double));
|
||||
switch(len) {
|
||||
case 255: *val = R_NegInf; return val;
|
||||
case 254: *val = R_PosInf; return val;
|
||||
case 253: *val = R_Nan; return val;
|
||||
default:
|
||||
if (!readBytes(buf, len)) {
|
||||
free(val);
|
||||
zfree(val);
|
||||
return NULL;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
@@ -386,24 +326,24 @@ double* loadDoubleValue() {
|
||||
}
|
||||
}
|
||||
|
||||
int processDoubleValue(double** store) {
|
||||
static int processDoubleValue(double** store) {
|
||||
unsigned long offset = CURR_OFFSET;
|
||||
double *val = loadDoubleValue();
|
||||
if (val == NULL) {
|
||||
SHIFT_ERROR(offset, "Error reading double value");
|
||||
free(val);
|
||||
zfree(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (store != NULL) {
|
||||
*store = val;
|
||||
} else {
|
||||
free(val);
|
||||
zfree(val);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int loadPair(entry *e) {
|
||||
static int loadPair(entry *e) {
|
||||
uint32_t offset = CURR_OFFSET;
|
||||
uint32_t i;
|
||||
|
||||
@@ -417,10 +357,10 @@ int loadPair(entry *e) {
|
||||
}
|
||||
|
||||
uint32_t length = 0;
|
||||
if (e->type == REDIS_LIST ||
|
||||
e->type == REDIS_SET ||
|
||||
e->type == REDIS_ZSET ||
|
||||
e->type == REDIS_HASH) {
|
||||
if (e->type == REDIS_RDB_TYPE_LIST ||
|
||||
e->type == REDIS_RDB_TYPE_SET ||
|
||||
e->type == REDIS_RDB_TYPE_ZSET ||
|
||||
e->type == REDIS_RDB_TYPE_HASH) {
|
||||
if ((length = loadLength(NULL)) == REDIS_RDB_LENERR) {
|
||||
SHIFT_ERROR(offset, "Error reading %s length", types[e->type]);
|
||||
return 0;
|
||||
@@ -428,19 +368,19 @@ int loadPair(entry *e) {
|
||||
}
|
||||
|
||||
switch(e->type) {
|
||||
case REDIS_STRING:
|
||||
case REDIS_HASH_ZIPMAP:
|
||||
case REDIS_LIST_ZIPLIST:
|
||||
case REDIS_SET_INTSET:
|
||||
case REDIS_ZSET_ZIPLIST:
|
||||
case REDIS_HASH_ZIPLIST:
|
||||
case REDIS_RDB_TYPE_STRING:
|
||||
case REDIS_RDB_TYPE_HASH_ZIPMAP:
|
||||
case REDIS_RDB_TYPE_LIST_ZIPLIST:
|
||||
case REDIS_RDB_TYPE_SET_INTSET:
|
||||
case REDIS_RDB_TYPE_ZSET_ZIPLIST:
|
||||
case REDIS_RDB_TYPE_HASH_ZIPLIST:
|
||||
if (!processStringObject(NULL)) {
|
||||
SHIFT_ERROR(offset, "Error reading entry value");
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case REDIS_LIST:
|
||||
case REDIS_SET:
|
||||
case REDIS_RDB_TYPE_LIST:
|
||||
case REDIS_RDB_TYPE_SET:
|
||||
for (i = 0; i < length; i++) {
|
||||
offset = CURR_OFFSET;
|
||||
if (!processStringObject(NULL)) {
|
||||
@@ -449,7 +389,7 @@ int loadPair(entry *e) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case REDIS_ZSET:
|
||||
case REDIS_RDB_TYPE_ZSET:
|
||||
for (i = 0; i < length; i++) {
|
||||
offset = CURR_OFFSET;
|
||||
if (!processStringObject(NULL)) {
|
||||
@@ -463,7 +403,7 @@ int loadPair(entry *e) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case REDIS_HASH:
|
||||
case REDIS_RDB_TYPE_HASH:
|
||||
for (i = 0; i < length; i++) {
|
||||
offset = CURR_OFFSET;
|
||||
if (!processStringObject(NULL)) {
|
||||
@@ -486,7 +426,7 @@ int loadPair(entry *e) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
entry loadEntry() {
|
||||
static entry loadEntry() {
|
||||
entry e = { NULL, -1, 0 };
|
||||
uint32_t length, offset[4];
|
||||
|
||||
@@ -499,7 +439,7 @@ entry loadEntry() {
|
||||
}
|
||||
|
||||
offset[1] = CURR_OFFSET;
|
||||
if (e.type == REDIS_SELECTDB) {
|
||||
if (e.type == REDIS_RDB_OPCODE_SELECTDB) {
|
||||
if ((length = loadLength(NULL)) == REDIS_RDB_LENERR) {
|
||||
SHIFT_ERROR(offset[1], "Error reading database number");
|
||||
return e;
|
||||
@@ -508,7 +448,7 @@ entry loadEntry() {
|
||||
SHIFT_ERROR(offset[1], "Database number out of range (%d)", length);
|
||||
return e;
|
||||
}
|
||||
} else if (e.type == REDIS_EOF) {
|
||||
} else if (e.type == REDIS_RDB_OPCODE_EOF) {
|
||||
if (positions[level].offset < positions[level].size) {
|
||||
SHIFT_ERROR(offset[0], "Unexpected EOF");
|
||||
} else {
|
||||
@@ -517,8 +457,8 @@ entry loadEntry() {
|
||||
return e;
|
||||
} else {
|
||||
/* optionally consume expire */
|
||||
if (e.type == REDIS_EXPIRETIME ||
|
||||
e.type == REDIS_EXPIRETIME_MS) {
|
||||
if (e.type == REDIS_RDB_OPCODE_EXPIRETIME ||
|
||||
e.type == REDIS_RDB_OPCODE_EXPIRETIME_MS) {
|
||||
if (!processTime(e.type)) return e;
|
||||
if (!loadType(&e)) return e;
|
||||
}
|
||||
@@ -544,31 +484,31 @@ entry loadEntry() {
|
||||
return e;
|
||||
}
|
||||
|
||||
void printCentered(int indent, int width, char* body) {
|
||||
static void printCentered(int indent, int width, char* body) {
|
||||
char head[256], tail[256];
|
||||
memset(head, '\0', 256);
|
||||
memset(tail, '\0', 256);
|
||||
|
||||
memset(head, '=', indent);
|
||||
memset(tail, '=', width - 2 - indent - strlen(body));
|
||||
printf("%s %s %s\n", head, body, tail);
|
||||
redisLog(REDIS_WARNING, "%s %s %s", head, body, tail);
|
||||
}
|
||||
|
||||
void printValid(uint64_t ops, uint64_t bytes) {
|
||||
static void printValid(uint64_t ops, uint64_t bytes) {
|
||||
char body[80];
|
||||
sprintf(body, "Processed %llu valid opcodes (in %llu bytes)",
|
||||
(unsigned long long) ops, (unsigned long long) bytes);
|
||||
printCentered(4, 80, body);
|
||||
}
|
||||
|
||||
void printSkipped(uint64_t bytes, uint64_t offset) {
|
||||
static void printSkipped(uint64_t bytes, uint64_t offset) {
|
||||
char body[80];
|
||||
sprintf(body, "Skipped %llu bytes (resuming at 0x%08llx)",
|
||||
(unsigned long long) bytes, (unsigned long long) offset);
|
||||
printCentered(4, 80, body);
|
||||
}
|
||||
|
||||
void printErrorStack(entry *e) {
|
||||
static void printErrorStack(entry *e) {
|
||||
unsigned int i;
|
||||
char body[64];
|
||||
|
||||
@@ -598,20 +538,20 @@ void printErrorStack(entry *e) {
|
||||
|
||||
/* display error stack */
|
||||
for (i = 0; i < errors.level; i++) {
|
||||
printf("0x%08lx - %s\n",
|
||||
redisLog(REDIS_WARNING, "0x%08lx - %s",
|
||||
(unsigned long) errors.offset[i], errors.error[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void process(void) {
|
||||
uint64_t num_errors = 0, num_valid_ops = 0, num_valid_bytes = 0;
|
||||
entry entry;
|
||||
entry entry = { NULL, -1, 0 };
|
||||
int dump_version = processHeader();
|
||||
|
||||
/* Exclude the final checksum for RDB >= 5. Will be checked at the end. */
|
||||
if (dump_version >= 5) {
|
||||
if (positions[0].size < 8) {
|
||||
printf("RDB version >= 5 but no room for checksum.\n");
|
||||
redisLog(REDIS_WARNING, "RDB version >= 5 but no room for checksum.");
|
||||
exit(1);
|
||||
}
|
||||
positions[0].size -= 8;
|
||||
@@ -660,7 +600,7 @@ void process(void) {
|
||||
/* advance position */
|
||||
positions[0] = positions[1];
|
||||
}
|
||||
free(entry.key);
|
||||
zfree(entry.key);
|
||||
}
|
||||
|
||||
/* because there is another potential error,
|
||||
@@ -668,7 +608,7 @@ void process(void) {
|
||||
printValid(num_valid_ops, num_valid_bytes);
|
||||
|
||||
/* expect an eof */
|
||||
if (entry.type != REDIS_EOF) {
|
||||
if (entry.type != REDIS_RDB_OPCODE_EOF) {
|
||||
/* last byte should be EOF, add error */
|
||||
errors.level = 0;
|
||||
SHIFT_ERROR(positions[0].offset, "Expected EOF, got %s", types[entry.type]);
|
||||
@@ -696,47 +636,40 @@ void process(void) {
|
||||
if (crc != crc2) {
|
||||
SHIFT_ERROR(positions[0].offset, "RDB CRC64 does not match.");
|
||||
} else {
|
||||
printf("CRC64 checksum is OK\n");
|
||||
redisLog(REDIS_WARNING, "CRC64 checksum is OK");
|
||||
}
|
||||
}
|
||||
|
||||
/* print summary on errors */
|
||||
if (num_errors) {
|
||||
printf("\n");
|
||||
printf("Total unprocessable opcodes: %llu\n",
|
||||
redisLog(REDIS_WARNING, "Total unprocessable opcodes: %llu",
|
||||
(unsigned long long) num_errors);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
/* expect the first argument to be the dump file */
|
||||
if (argc <= 1) {
|
||||
printf("Usage: %s <dump.rdb>\n", argv[0]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int redis_check_rdb(char *rdbfilename) {
|
||||
int fd;
|
||||
off_t size;
|
||||
struct stat stat;
|
||||
void *data;
|
||||
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
fd = open(rdbfilename, O_RDONLY);
|
||||
if (fd < 1) {
|
||||
ERROR("Cannot open file: %s\n", argv[1]);
|
||||
ERROR("Cannot open file: %s", rdbfilename);
|
||||
}
|
||||
if (fstat(fd, &stat) == -1) {
|
||||
ERROR("Cannot stat: %s\n", argv[1]);
|
||||
ERROR("Cannot stat: %s", rdbfilename);
|
||||
} else {
|
||||
size = stat.st_size;
|
||||
}
|
||||
|
||||
if (sizeof(size_t) == sizeof(int32_t) && size >= INT_MAX) {
|
||||
ERROR("Cannot check dump files >2GB on a 32-bit platform\n");
|
||||
ERROR("Cannot check dump files >2GB on a 32-bit platform");
|
||||
}
|
||||
|
||||
data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (data == MAP_FAILED) {
|
||||
ERROR("Cannot mmap: %s\n", argv[1]);
|
||||
ERROR("Cannot mmap: %s", rdbfilename);
|
||||
}
|
||||
|
||||
/* Initialize static vars */
|
||||
@@ -746,22 +679,16 @@ int main(int argc, char **argv) {
|
||||
errors.level = 0;
|
||||
|
||||
/* Object types */
|
||||
sprintf(types[REDIS_STRING], "STRING");
|
||||
sprintf(types[REDIS_LIST], "LIST");
|
||||
sprintf(types[REDIS_SET], "SET");
|
||||
sprintf(types[REDIS_ZSET], "ZSET");
|
||||
sprintf(types[REDIS_HASH], "HASH");
|
||||
sprintf(types[REDIS_RDB_TYPE_STRING], "STRING");
|
||||
sprintf(types[REDIS_RDB_TYPE_LIST], "LIST");
|
||||
sprintf(types[REDIS_RDB_TYPE_SET], "SET");
|
||||
sprintf(types[REDIS_RDB_TYPE_ZSET], "ZSET");
|
||||
sprintf(types[REDIS_RDB_TYPE_HASH], "HASH");
|
||||
|
||||
/* Object types only used for dumping to disk */
|
||||
sprintf(types[REDIS_EXPIRETIME], "EXPIRETIME");
|
||||
sprintf(types[REDIS_SELECTDB], "SELECTDB");
|
||||
sprintf(types[REDIS_EOF], "EOF");
|
||||
|
||||
/* Double constants initialization */
|
||||
R_Zero = 0.0;
|
||||
R_PosInf = 1.0/R_Zero;
|
||||
R_NegInf = -1.0/R_Zero;
|
||||
R_Nan = R_Zero/R_Zero;
|
||||
sprintf(types[REDIS_RDB_OPCODE_EXPIRETIME], "EXPIRETIME");
|
||||
sprintf(types[REDIS_RDB_OPCODE_SELECTDB], "SELECTDB");
|
||||
sprintf(types[REDIS_RDB_OPCODE_EOF], "EOF");
|
||||
|
||||
process();
|
||||
|
||||
@@ -769,3 +696,15 @@ int main(int argc, char **argv) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* RDB check main: called form redis.c when Redis is executed with the
|
||||
* redis-check-rdb alias. */
|
||||
int redis_check_rdb_main(char **argv, int argc) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <rdb-file-name>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
redisLog(REDIS_WARNING, "Checking RDB file %s", argv[1]);
|
||||
exit(redis_check_rdb(argv[1]));
|
||||
return 0;
|
||||
}
|
||||
+281
-9
@@ -44,6 +44,7 @@
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "hiredis.h"
|
||||
#include "sds.h"
|
||||
@@ -76,7 +77,10 @@ static struct config {
|
||||
int monitor_mode;
|
||||
int pubsub_mode;
|
||||
int latency_mode;
|
||||
int latency_dist_mode;
|
||||
int latency_history;
|
||||
int lru_test_mode;
|
||||
long long lru_test_sample_size;
|
||||
int cluster_mode;
|
||||
int cluster_reissue_command;
|
||||
int slave_mode;
|
||||
@@ -518,7 +522,7 @@ static sds cliFormatReplyCSV(redisReply *r) {
|
||||
out = sdscatrepr(out,r->str,r->len);
|
||||
break;
|
||||
case REDIS_REPLY_NIL:
|
||||
out = sdscat(out,"NIL\n");
|
||||
out = sdscat(out,"NIL");
|
||||
break;
|
||||
case REDIS_REPLY_ARRAY:
|
||||
for (i = 0; i < r->elements; i++) {
|
||||
@@ -700,16 +704,17 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
|
||||
return REDIS_OK;
|
||||
}
|
||||
|
||||
/* Send the INFO command, reconnecting the link if needed. */
|
||||
static redisReply *reconnectingInfo(void) {
|
||||
redisContext *c = context;
|
||||
/* Send a command reconnecting the link if needed. */
|
||||
static redisReply *reconnectingRedisCommand(redisContext *c, const char *fmt, ...) {
|
||||
redisReply *reply = NULL;
|
||||
int tries = 0;
|
||||
va_list ap;
|
||||
|
||||
assert(!c->err);
|
||||
while(reply == NULL) {
|
||||
while (c->err & (REDIS_ERR_IO | REDIS_ERR_EOF)) {
|
||||
printf("Reconnecting (%d)...\r", ++tries);
|
||||
printf("\r\x1b[0K"); /* Cursor to left edge + clear line. */
|
||||
printf("Reconnecting... %d\r", ++tries);
|
||||
fflush(stdout);
|
||||
|
||||
redisFree(c);
|
||||
@@ -717,12 +722,15 @@ static redisReply *reconnectingInfo(void) {
|
||||
usleep(1000000);
|
||||
}
|
||||
|
||||
reply = redisCommand(c,"INFO");
|
||||
va_start(ap,fmt);
|
||||
reply = redisvCommand(c,fmt,ap);
|
||||
va_end(ap);
|
||||
|
||||
if (c->err && !(c->err & (REDIS_ERR_IO | REDIS_ERR_EOF))) {
|
||||
fprintf(stderr, "Error: %s\n", c->errstr);
|
||||
exit(1);
|
||||
} else if (tries > 0) {
|
||||
printf("\n");
|
||||
printf("\r\x1b[0K"); /* Cursor to left edge + clear line. */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -770,9 +778,14 @@ static int parseOptions(int argc, char **argv) {
|
||||
config.output = OUTPUT_CSV;
|
||||
} else if (!strcmp(argv[i],"--latency")) {
|
||||
config.latency_mode = 1;
|
||||
} else if (!strcmp(argv[i],"--latency-dist")) {
|
||||
config.latency_dist_mode = 1;
|
||||
} else if (!strcmp(argv[i],"--latency-history")) {
|
||||
config.latency_mode = 1;
|
||||
config.latency_history = 1;
|
||||
} else if (!strcmp(argv[i],"--lru-test") && !lastarg) {
|
||||
config.lru_test_mode = 1;
|
||||
config.lru_test_sample_size = strtoll(argv[++i],NULL,10);
|
||||
} else if (!strcmp(argv[i],"--slave")) {
|
||||
config.slave_mode = 1;
|
||||
} else if (!strcmp(argv[i],"--stat")) {
|
||||
@@ -862,6 +875,9 @@ static void usage(void) {
|
||||
" --latency Enter a special mode continuously sampling latency.\n"
|
||||
" --latency-history Like --latency but tracking latency changes over time.\n"
|
||||
" Default time interval is 15 sec. Change it using -i.\n"
|
||||
" --latency-dist Shows latency as a spectrum, requires xterm 256 colors.\n"
|
||||
" Default time interval is 1 sec. Change it using -i.\n"
|
||||
" --lru-test <keys> Simulate a cache workload with an 80-20 distribution.\n"
|
||||
" --slave Simulate a slave showing commands received from the master.\n"
|
||||
" --rdb <filename> Transfer an RDB dump from remote server to local file.\n"
|
||||
" --pipe Transfer raw Redis protocol from stdin to server.\n"
|
||||
@@ -1077,7 +1093,7 @@ static void latencyMode(void) {
|
||||
if (!context) exit(1);
|
||||
while(1) {
|
||||
start = mstime();
|
||||
reply = redisCommand(context,"PING");
|
||||
reply = reconnectingRedisCommand(context,"PING");
|
||||
if (reply == NULL) {
|
||||
fprintf(stderr,"\nI/O error\n");
|
||||
exit(1);
|
||||
@@ -1107,6 +1123,155 @@ static void latencyMode(void) {
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Latency distribution mode -- requires 256 colors xterm
|
||||
*--------------------------------------------------------------------------- */
|
||||
|
||||
#define LATENCY_DIST_DEFAULT_INTERVAL 1000 /* milliseconds. */
|
||||
#define LATENCY_DIST_MIN_GRAY 233 /* Less than that is too hard to see gray. */
|
||||
#define LATENCY_DIST_MAX_GRAY 255
|
||||
#define LATENCY_DIST_GRAYS (LATENCY_DIST_MAX_GRAY-LATENCY_DIST_MIN_GRAY+1)
|
||||
|
||||
/* Gray palette. */
|
||||
int spectrum_palette_size = 24;
|
||||
int spectrum_palette[] = {0, 233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255};
|
||||
|
||||
/* Structure to store samples distribution. */
|
||||
struct distsamples {
|
||||
long long max; /* Max latency to fit into this interval (usec). */
|
||||
long long count; /* Number of samples in this interval. */
|
||||
int character; /* Associated character in visualization. */
|
||||
};
|
||||
|
||||
/* Helper function for latencyDistMode(). Performs the spectrum visualization
|
||||
* of the collected samples targeting an xterm 256 terminal.
|
||||
*
|
||||
* Takes an array of distsamples structures, ordered from smaller to bigger
|
||||
* 'max' value. Last sample max must be 0, to mean that it olds all the
|
||||
* samples greater than the previous one, and is also the stop sentinel.
|
||||
*
|
||||
* "tot' is the total number of samples in the different buckets, so it
|
||||
* is the SUM(samples[i].conut) for i to 0 up to the max sample.
|
||||
*
|
||||
* As a side effect the function sets all the buckets count to 0. */
|
||||
void showLatencyDistSamples(struct distsamples *samples, long long tot) {
|
||||
int j;
|
||||
|
||||
/* We convert samples into a index inside the palette
|
||||
* proportional to the percentage a given bucket represents.
|
||||
* This way intensity of the different parts of the spectrum
|
||||
* don't change relative to the number of requests, which avoids to
|
||||
* pollute the visualization with non-latency related info. */
|
||||
printf("\033[38;5;0m"); /* Set foreground color to black. */
|
||||
for (j = 0; ; j++) {
|
||||
int coloridx =
|
||||
ceil((float) samples[j].count / tot * (spectrum_palette_size-1));
|
||||
int color = spectrum_palette[coloridx];
|
||||
printf("\033[48;5;%dm%c", (int)color, samples[j].character);
|
||||
samples[j].count = 0;
|
||||
if (samples[j].max == 0) break; /* Last sample. */
|
||||
}
|
||||
printf("\033[0m\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* Show the legend: different buckets values and colors meaning, so
|
||||
* that the spectrum is more easily readable. */
|
||||
void showLatencyDistLegend(void) {
|
||||
int j;
|
||||
|
||||
printf("---------------------------------------------\n");
|
||||
printf(". - * # .01 .125 .25 .5 milliseconds\n");
|
||||
printf("1,2,3,...,9 from 1 to 9 milliseconds\n");
|
||||
printf("A,B,C,D,E 10,20,30,40,50 milliseconds\n");
|
||||
printf("F,G,H,I,J .1,.2,.3,.4,.5 seconds\n");
|
||||
printf("K,L,M,N,O,P,Q,? 1,2,4,8,16,30,60,>60 seconds\n");
|
||||
printf("From 0 to 100%%: ");
|
||||
for (j = 0; j < spectrum_palette_size; j++) {
|
||||
printf("\033[48;5;%dm ", spectrum_palette[j]);
|
||||
}
|
||||
printf("\033[0m\n");
|
||||
printf("---------------------------------------------\n");
|
||||
}
|
||||
|
||||
static void latencyDistMode(void) {
|
||||
redisReply *reply;
|
||||
long long start, latency, count = 0;
|
||||
long long history_interval =
|
||||
config.interval ? config.interval/1000 :
|
||||
LATENCY_DIST_DEFAULT_INTERVAL;
|
||||
long long history_start = ustime();
|
||||
int j, outputs = 0;
|
||||
|
||||
struct distsamples samples[] = {
|
||||
/* We use a mostly logarithmic scale, with certain linear intervals
|
||||
* which are more interesting than others, like 1-10 milliseconds
|
||||
* range. */
|
||||
{10,0,'.'}, /* 0.01 ms */
|
||||
{125,0,'-'}, /* 0.125 ms */
|
||||
{250,0,'*'}, /* 0.25 ms */
|
||||
{500,0,'#'}, /* 0.5 ms */
|
||||
{1000,0,'1'}, /* 1 ms */
|
||||
{2000,0,'2'}, /* 2 ms */
|
||||
{3000,0,'3'}, /* 3 ms */
|
||||
{4000,0,'4'}, /* 4 ms */
|
||||
{5000,0,'5'}, /* 5 ms */
|
||||
{6000,0,'6'}, /* 6 ms */
|
||||
{7000,0,'7'}, /* 7 ms */
|
||||
{8000,0,'8'}, /* 8 ms */
|
||||
{9000,0,'9'}, /* 9 ms */
|
||||
{10000,0,'A'}, /* 10 ms */
|
||||
{20000,0,'B'}, /* 20 ms */
|
||||
{30000,0,'C'}, /* 30 ms */
|
||||
{40000,0,'D'}, /* 40 ms */
|
||||
{50000,0,'E'}, /* 50 ms */
|
||||
{100000,0,'F'}, /* 0.1 s */
|
||||
{200000,0,'G'}, /* 0.2 s */
|
||||
{300000,0,'H'}, /* 0.3 s */
|
||||
{400000,0,'I'}, /* 0.4 s */
|
||||
{500000,0,'J'}, /* 0.5 s */
|
||||
{1000000,0,'K'}, /* 1 s */
|
||||
{2000000,0,'L'}, /* 2 s */
|
||||
{4000000,0,'M'}, /* 4 s */
|
||||
{8000000,0,'N'}, /* 8 s */
|
||||
{16000000,0,'O'}, /* 16 s */
|
||||
{30000000,0,'P'}, /* 30 s */
|
||||
{60000000,0,'Q'}, /* 1 minute */
|
||||
{0,0,'?'}, /* > 1 minute */
|
||||
};
|
||||
|
||||
if (!context) exit(1);
|
||||
while(1) {
|
||||
start = ustime();
|
||||
reply = reconnectingRedisCommand(context,"PING");
|
||||
if (reply == NULL) {
|
||||
fprintf(stderr,"\nI/O error\n");
|
||||
exit(1);
|
||||
}
|
||||
latency = ustime()-start;
|
||||
freeReplyObject(reply);
|
||||
count++;
|
||||
|
||||
/* Populate the relevant bucket. */
|
||||
for (j = 0; ; j++) {
|
||||
if (samples[j].max == 0 || latency <= samples[j].max) {
|
||||
samples[j].count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* From time to time show the spectrum. */
|
||||
if (count && (ustime()-history_start)/1000 > history_interval) {
|
||||
if ((outputs++ % 20) == 0)
|
||||
showLatencyDistLegend();
|
||||
showLatencyDistSamples(samples,count);
|
||||
history_start = ustime();
|
||||
count = 0;
|
||||
}
|
||||
usleep(LATENCY_SAMPLE_RATE * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Slave mode
|
||||
*--------------------------------------------------------------------------- */
|
||||
@@ -1726,7 +1891,7 @@ static void statMode(void) {
|
||||
char buf[64];
|
||||
int j;
|
||||
|
||||
reply = reconnectingInfo();
|
||||
reply = reconnectingRedisCommand(context,"INFO");
|
||||
if (reply->type == REDIS_REPLY_ERROR) {
|
||||
printf("ERROR: %s\n", reply->str);
|
||||
exit(1);
|
||||
@@ -1780,6 +1945,7 @@ static void statMode(void) {
|
||||
/* Children */
|
||||
aux = getLongInfoField(reply->str,"bgsave_in_progress");
|
||||
aux |= getLongInfoField(reply->str,"aof_rewrite_in_progress") << 1;
|
||||
aux |= getLongInfoField(reply->str,"loading") << 2;
|
||||
switch(aux) {
|
||||
case 0: break;
|
||||
case 1:
|
||||
@@ -1791,6 +1957,9 @@ static void statMode(void) {
|
||||
case 3:
|
||||
printf("SAVE+AOF");
|
||||
break;
|
||||
case 4:
|
||||
printf("LOAD");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
@@ -1832,6 +2001,94 @@ static void scanMode(void) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* LRU test mode
|
||||
*--------------------------------------------------------------------------- */
|
||||
|
||||
/* Return an integer from min to max (both inclusive) using a power-law
|
||||
* distribution, depending on the value of alpha: the greater the alpha
|
||||
* the more bias towards lower values.
|
||||
*
|
||||
* With alpha = 6.2 the output follows the 80-20 rule where 20% of
|
||||
* the returned numbers will account for 80% of the frequency. */
|
||||
long long powerLawRand(long long min, long long max, double alpha) {
|
||||
double pl, r;
|
||||
|
||||
max += 1;
|
||||
r = ((double)rand()) / RAND_MAX;
|
||||
pl = pow(
|
||||
((pow(max,alpha+1) - pow(min,alpha+1))*r + pow(min,alpha+1)),
|
||||
(1.0/(alpha+1)));
|
||||
return (max-1-(long long)pl)+min;
|
||||
}
|
||||
|
||||
/* Generates a key name among a set of lru_test_sample_size keys, using
|
||||
* an 80-20 distribution. */
|
||||
void LRUTestGenKey(char *buf, size_t buflen) {
|
||||
snprintf(buf, buflen, "lru:%lld\n",
|
||||
powerLawRand(1, config.lru_test_sample_size, 6.2));
|
||||
}
|
||||
|
||||
#define LRU_CYCLE_PERIOD 1000 /* 1000 milliseconds. */
|
||||
#define LRU_CYCLE_PIPELINE_SIZE 250
|
||||
static void LRUTestMode(void) {
|
||||
redisReply *reply;
|
||||
char key[128];
|
||||
long long start_cycle;
|
||||
int j;
|
||||
|
||||
srand(time(NULL)^getpid());
|
||||
while(1) {
|
||||
/* Perform cycles of 1 second with 50% writes and 50% reads.
|
||||
* We use pipelining batching writes / reads N times per cycle in order
|
||||
* to fill the target instance easily. */
|
||||
start_cycle = mstime();
|
||||
long long hits = 0, misses = 0;
|
||||
while(mstime() - start_cycle < 1000) {
|
||||
/* Write cycle. */
|
||||
for (j = 0; j < LRU_CYCLE_PIPELINE_SIZE; j++) {
|
||||
LRUTestGenKey(key,sizeof(key));
|
||||
redisAppendCommand(context, "SET %s val",key);
|
||||
}
|
||||
for (j = 0; j < LRU_CYCLE_PIPELINE_SIZE; j++)
|
||||
redisGetReply(context, (void**)&reply);
|
||||
|
||||
/* Read cycle. */
|
||||
for (j = 0; j < LRU_CYCLE_PIPELINE_SIZE; j++) {
|
||||
LRUTestGenKey(key,sizeof(key));
|
||||
redisAppendCommand(context, "GET %s",key);
|
||||
}
|
||||
for (j = 0; j < LRU_CYCLE_PIPELINE_SIZE; j++) {
|
||||
if (redisGetReply(context, (void**)&reply) == REDIS_OK) {
|
||||
switch(reply->type) {
|
||||
case REDIS_REPLY_ERROR:
|
||||
printf("%s\n", reply->str);
|
||||
break;
|
||||
case REDIS_REPLY_NIL:
|
||||
misses++;
|
||||
break;
|
||||
default:
|
||||
hits++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (context->err) {
|
||||
fprintf(stderr,"I/O error during LRU test\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
/* Print stats. */
|
||||
printf(
|
||||
"%lld Gets/sec | Hits: %lld (%.2f%%) | Misses: %lld (%.2f%%)\n",
|
||||
hits+misses,
|
||||
hits, (double)hits/(hits+misses)*100,
|
||||
misses, (double)misses/(hits+misses)*100);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Intrisic latency mode.
|
||||
*
|
||||
@@ -1923,7 +2180,10 @@ int main(int argc, char **argv) {
|
||||
config.monitor_mode = 0;
|
||||
config.pubsub_mode = 0;
|
||||
config.latency_mode = 0;
|
||||
config.latency_dist_mode = 0;
|
||||
config.latency_history = 0;
|
||||
config.lru_test_mode = 0;
|
||||
config.lru_test_sample_size = 0;
|
||||
config.cluster_mode = 0;
|
||||
config.slave_mode = 0;
|
||||
config.getrdb_mode = 0;
|
||||
@@ -1957,6 +2217,12 @@ int main(int argc, char **argv) {
|
||||
latencyMode();
|
||||
}
|
||||
|
||||
/* Latency distribution mode */
|
||||
if (config.latency_dist_mode) {
|
||||
if (cliConnect(0) == REDIS_ERR) exit(1);
|
||||
latencyDistMode();
|
||||
}
|
||||
|
||||
/* Slave mode */
|
||||
if (config.slave_mode) {
|
||||
if (cliConnect(0) == REDIS_ERR) exit(1);
|
||||
@@ -1994,6 +2260,12 @@ int main(int argc, char **argv) {
|
||||
scanMode();
|
||||
}
|
||||
|
||||
/* LRU test mode */
|
||||
if (config.lru_test_mode) {
|
||||
if (cliConnect(0) == REDIS_ERR) exit(1);
|
||||
LRUTestMode();
|
||||
}
|
||||
|
||||
/* Intrinsic latency mode */
|
||||
if (config.intrinsic_latency_mode) intrinsicLatencyMode();
|
||||
|
||||
|
||||
+17
-8
@@ -72,7 +72,7 @@ class ClusterNode
|
||||
@friends
|
||||
end
|
||||
|
||||
def slots
|
||||
def slots
|
||||
@info[:slots]
|
||||
end
|
||||
|
||||
@@ -154,7 +154,7 @@ class ClusterNode
|
||||
end
|
||||
} if slots
|
||||
@dirty = false
|
||||
@r.cluster("info").split("\n").each{|e|
|
||||
@r.cluster("info").split("\n").each{|e|
|
||||
k,v=e.split(":")
|
||||
k = k.to_sym
|
||||
v.chop!
|
||||
@@ -213,7 +213,7 @@ class ClusterNode
|
||||
#
|
||||
# Note: this could be easily written without side effects,
|
||||
# we use 'slots' just to split the computation into steps.
|
||||
|
||||
|
||||
# First step: we want an increasing array of integers
|
||||
# for instance: [1,2,3,4,5,8,9,20,21,22,23,24,25,30]
|
||||
slots = @info[:slots].keys.sort
|
||||
@@ -273,7 +273,7 @@ class ClusterNode
|
||||
def info
|
||||
@info
|
||||
end
|
||||
|
||||
|
||||
def is_dirty?
|
||||
@dirty
|
||||
end
|
||||
@@ -563,8 +563,17 @@ class RedisTrib
|
||||
# Take one node from each IP until we run out of nodes
|
||||
# across every IP.
|
||||
ips.each do |ip,nodes|
|
||||
stop = nodes.empty? and next
|
||||
interleaved.push nodes.shift
|
||||
if nodes.empty?
|
||||
# if this IP has no remaining nodes, check for termination
|
||||
if interleaved.length == nodes_count
|
||||
# stop when 'interleaved' has accumulated all nodes
|
||||
stop = true
|
||||
next
|
||||
end
|
||||
else
|
||||
# else, move one node from this IP to 'interleaved'
|
||||
interleaved.push nodes.shift
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -780,7 +789,7 @@ class RedisTrib
|
||||
|
||||
# Move slots between source and target nodes using MIGRATE.
|
||||
#
|
||||
# Options:
|
||||
# Options:
|
||||
# :verbose -- Print a dot for every moved key.
|
||||
# :fix -- We are moving in the context of a fix. Use REPLACE.
|
||||
# :cold -- Move keys without opening / reconfiguring the nodes.
|
||||
@@ -1223,7 +1232,7 @@ end
|
||||
|
||||
#################################################################################
|
||||
# Libraries
|
||||
#
|
||||
#
|
||||
# We try to don't depend on external libs since this is a critical part
|
||||
# of Redis Cluster.
|
||||
#################################################################################
|
||||
|
||||
+123
-43
@@ -1416,6 +1416,7 @@ void initServerConfig(void) {
|
||||
server.syslog_facility = LOG_LOCAL0;
|
||||
server.daemonize = REDIS_DEFAULT_DAEMONIZE;
|
||||
server.supervised = 0;
|
||||
server.supervised_mode = REDIS_SUPERVISED_NONE;
|
||||
server.aof_state = REDIS_AOF_OFF;
|
||||
server.aof_fsync = REDIS_DEFAULT_AOF_FSYNC;
|
||||
server.aof_no_fsync_on_rewrite = REDIS_DEFAULT_AOF_NO_FSYNC_ON_REWRITE;
|
||||
@@ -1433,7 +1434,7 @@ void initServerConfig(void) {
|
||||
server.aof_flush_postponed_start = 0;
|
||||
server.aof_rewrite_incremental_fsync = REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC;
|
||||
server.aof_load_truncated = REDIS_DEFAULT_AOF_LOAD_TRUNCATED;
|
||||
server.pidfile = zstrdup(REDIS_DEFAULT_PID_FILE);
|
||||
server.pidfile = NULL;
|
||||
server.rdb_filename = zstrdup(REDIS_DEFAULT_RDB_FILENAME);
|
||||
server.aof_filename = zstrdup(REDIS_DEFAULT_AOF_FILENAME);
|
||||
server.requirepass = NULL;
|
||||
@@ -1495,6 +1496,7 @@ void initServerConfig(void) {
|
||||
server.repl_disable_tcp_nodelay = REDIS_DEFAULT_REPL_DISABLE_TCP_NODELAY;
|
||||
server.repl_diskless_sync = REDIS_DEFAULT_REPL_DISKLESS_SYNC;
|
||||
server.repl_diskless_sync_delay = REDIS_DEFAULT_REPL_DISKLESS_SYNC_DELAY;
|
||||
server.repl_no_sync = REDIS_DEFAULT_REPL_NO_SYNC;
|
||||
server.slave_priority = REDIS_DEFAULT_SLAVE_PRIORITY;
|
||||
server.master_repl_offset = 0;
|
||||
|
||||
@@ -1528,6 +1530,7 @@ void initServerConfig(void) {
|
||||
server.lpushCommand = lookupCommandByCString("lpush");
|
||||
server.lpopCommand = lookupCommandByCString("lpop");
|
||||
server.rpopCommand = lookupCommandByCString("rpop");
|
||||
server.sremCommand = lookupCommandByCString("srem");
|
||||
|
||||
/* Slow log */
|
||||
server.slowlog_log_slower_than = REDIS_SLOWLOG_LOG_SLOWER_THAN;
|
||||
@@ -2000,6 +2003,9 @@ struct redisCommand *lookupCommandOrOriginal(sds name) {
|
||||
* + REDIS_PROPAGATE_NONE (no propagation of command at all)
|
||||
* + REDIS_PROPAGATE_AOF (propagate into the AOF file if is enabled)
|
||||
* + REDIS_PROPAGATE_REPL (propagate into the replication link)
|
||||
*
|
||||
* This should not be used inside commands implementation. Use instead
|
||||
* alsoPropagate(), preventCommandPropagation(), forceCommandPropagation().
|
||||
*/
|
||||
void propagate(struct redisCommand *cmd, int dbid, robj **argv, int argc,
|
||||
int flags)
|
||||
@@ -2011,11 +2017,31 @@ void propagate(struct redisCommand *cmd, int dbid, robj **argv, int argc,
|
||||
}
|
||||
|
||||
/* Used inside commands to schedule the propagation of additional commands
|
||||
* after the current command is propagated to AOF / Replication. */
|
||||
* after the current command is propagated to AOF / Replication.
|
||||
*
|
||||
* 'cmd' must be a pointer to the Redis command to replicate, dbid is the
|
||||
* database ID the command should be propagated into.
|
||||
* Arguments of the command to propagte are passed as an array of redis
|
||||
* objects pointers of len 'argc', using the 'argv' vector.
|
||||
*
|
||||
* The function does not take a reference to the passed 'argv' vector,
|
||||
* so it is up to the caller to release the passed argv (but it is usually
|
||||
* stack allocated). The function autoamtically increments ref count of
|
||||
* passed objects, so the caller does not need to. */
|
||||
void alsoPropagate(struct redisCommand *cmd, int dbid, robj **argv, int argc,
|
||||
int target)
|
||||
{
|
||||
redisOpArrayAppend(&server.also_propagate,cmd,dbid,argv,argc,target);
|
||||
robj **argvcopy;
|
||||
int j;
|
||||
|
||||
if (server.loading) return; /* No propagation during loading. */
|
||||
|
||||
argvcopy = zmalloc(sizeof(robj*)*argc);
|
||||
for (j = 0; j < argc; j++) {
|
||||
argvcopy[j] = argv[j];
|
||||
incrRefCount(argv[j]);
|
||||
}
|
||||
redisOpArrayAppend(&server.also_propagate,cmd,dbid,argvcopy,argc,target);
|
||||
}
|
||||
|
||||
/* It is possible to call the function forceCommandPropagation() inside a
|
||||
@@ -2026,6 +2052,13 @@ void forceCommandPropagation(redisClient *c, int flags) {
|
||||
if (flags & REDIS_PROPAGATE_AOF) c->flags |= REDIS_FORCE_AOF;
|
||||
}
|
||||
|
||||
/* Avoid that the executed command is propagated at all. This way we
|
||||
* are free to just propagate what we want using the alsoPropagate()
|
||||
* API. */
|
||||
void preventCommandPropagation(redisClient *c) {
|
||||
c->flags |= REDIS_PREVENT_PROP;
|
||||
}
|
||||
|
||||
/* Call() is the core of Redis execution of a command */
|
||||
void call(redisClient *c, int flags) {
|
||||
long long dirty, start, duration;
|
||||
@@ -2079,7 +2112,7 @@ void call(redisClient *c, int flags) {
|
||||
}
|
||||
|
||||
/* Propagate the command into the AOF and replication link */
|
||||
if (flags & REDIS_CALL_PROPAGATE) {
|
||||
if (flags & REDIS_CALL_PROPAGATE && (c->flags & REDIS_PREVENT_PROP) == 0) {
|
||||
int flags = REDIS_PROPAGATE_NONE;
|
||||
|
||||
if (c->flags & REDIS_FORCE_REPL) flags |= REDIS_PROPAGATE_REPL;
|
||||
@@ -2090,20 +2123,24 @@ void call(redisClient *c, int flags) {
|
||||
propagate(c->cmd,c->db->id,c->argv,c->argc,flags);
|
||||
}
|
||||
|
||||
/* Restore the old FORCE_AOF/REPL flags, since call can be executed
|
||||
/* Restore the old replication flags, since call can be executed
|
||||
* recursively. */
|
||||
c->flags &= ~(REDIS_FORCE_AOF|REDIS_FORCE_REPL);
|
||||
c->flags |= client_old_flags & (REDIS_FORCE_AOF|REDIS_FORCE_REPL);
|
||||
c->flags &= ~(REDIS_FORCE_AOF|REDIS_FORCE_REPL|REDIS_PREVENT_PROP);
|
||||
c->flags |= client_old_flags &
|
||||
(REDIS_FORCE_AOF|REDIS_FORCE_REPL|REDIS_PREVENT_PROP);
|
||||
|
||||
/* Handle the alsoPropagate() API to handle commands that want to propagate
|
||||
* multiple separated commands. */
|
||||
* multiple separated commands. Note that alsoPropagate() is not affected
|
||||
* by REDIS_PREVENT_PROP flag. */
|
||||
if (server.also_propagate.numops) {
|
||||
int j;
|
||||
redisOp *rop;
|
||||
|
||||
for (j = 0; j < server.also_propagate.numops; j++) {
|
||||
rop = &server.also_propagate.ops[j];
|
||||
propagate(rop->cmd, rop->dbid, rop->argv, rop->argc, rop->target);
|
||||
if (flags & REDIS_CALL_PROPAGATE) {
|
||||
for (j = 0; j < server.also_propagate.numops; j++) {
|
||||
rop = &server.also_propagate.ops[j];
|
||||
propagate(rop->cmd,rop->dbid,rop->argv,rop->argc,rop->target);
|
||||
}
|
||||
}
|
||||
redisOpArrayFree(&server.also_propagate);
|
||||
}
|
||||
@@ -2374,7 +2411,7 @@ int prepareForShutdown(int flags) {
|
||||
return REDIS_ERR;
|
||||
}
|
||||
}
|
||||
if (server.daemonize) {
|
||||
if (server.daemonize || server.pidfile) {
|
||||
redisLog(REDIS_NOTICE,"Removing the pid file.");
|
||||
unlink(server.pidfile);
|
||||
}
|
||||
@@ -3146,13 +3183,7 @@ void evictionPoolPopulate(dict *sampledict, dict *keydict, struct evictionPoolEn
|
||||
samples = zmalloc(sizeof(samples[0])*server.maxmemory_samples);
|
||||
}
|
||||
|
||||
#if 1 /* Use bulk get by default. */
|
||||
count = dictGetRandomKeys(sampledict,samples,server.maxmemory_samples);
|
||||
#else
|
||||
count = server.maxmemory_samples;
|
||||
for (j = 0; j < count; j++) samples[j] = dictGetRandomKey(sampledict);
|
||||
#endif
|
||||
|
||||
count = dictGetSomeKeys(sampledict,samples,server.maxmemory_samples);
|
||||
for (j = 0; j < count; j++) {
|
||||
unsigned long long idle;
|
||||
sds key;
|
||||
@@ -3207,7 +3238,7 @@ void evictionPoolPopulate(dict *sampledict, dict *keydict, struct evictionPoolEn
|
||||
int freeMemoryIfNeeded(void) {
|
||||
size_t mem_used, mem_tofree, mem_freed;
|
||||
int slaves = listLength(server.slaves);
|
||||
mstime_t latency;
|
||||
mstime_t latency, eviction_latency;
|
||||
|
||||
/* Remove the size of slaves output buffers and AOF buffer from the
|
||||
* count of used memory. */
|
||||
@@ -3338,7 +3369,11 @@ int freeMemoryIfNeeded(void) {
|
||||
* AOF and Output buffer memory will be freed eventually so
|
||||
* we only care about memory used by the key space. */
|
||||
delta = (long long) zmalloc_used_memory();
|
||||
latencyStartMonitor(eviction_latency);
|
||||
dbDelete(db,keyobj);
|
||||
latencyEndMonitor(eviction_latency);
|
||||
latencyAddSampleIfNeeded("eviction-del",eviction_latency);
|
||||
latencyRemoveNestedEvent(latency,eviction_latency);
|
||||
delta -= (long long) zmalloc_used_memory();
|
||||
mem_freed += delta;
|
||||
server.stat_evictedkeys++;
|
||||
@@ -3393,6 +3428,10 @@ void linuxMemoryWarnings(void) {
|
||||
#endif /* __linux__ */
|
||||
|
||||
void createPidFile(void) {
|
||||
/* If pidfile requested, but no pidfile defined, use
|
||||
* default pidfile path */
|
||||
if (!server.pidfile) server.pidfile = zstrdup(REDIS_DEFAULT_PID_FILE);
|
||||
|
||||
/* Try to write the pid file in a best-effort way. */
|
||||
FILE *fp = fopen(server.pidfile,"w");
|
||||
if (fp) {
|
||||
@@ -3587,8 +3626,23 @@ void redisSetProcTitle(char *title) {
|
||||
/*
|
||||
* Check whether systemd or upstart have been used to start redis.
|
||||
*/
|
||||
int redisIsSupervised(void) {
|
||||
|
||||
int redisSupervisedUpstart(void) {
|
||||
const char *upstart_job = getenv("UPSTART_JOB");
|
||||
|
||||
if (!upstart_job) {
|
||||
redisLog(REDIS_WARNING,
|
||||
"upstart supervision requested, but UPSTART_JOB not found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
redisLog(REDIS_NOTICE, "supervised by upstart, will stop to signal readyness");
|
||||
raise(SIGSTOP);
|
||||
unsetenv("UPSTART_JOB");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int redisSupervisedSystemd(void) {
|
||||
const char *notify_socket = getenv("NOTIFY_SOCKET");
|
||||
int fd = 1;
|
||||
struct sockaddr_un su;
|
||||
@@ -3596,31 +3650,24 @@ int redisIsSupervised(void) {
|
||||
struct msghdr hdr;
|
||||
int sendto_flags = 0;
|
||||
|
||||
if (upstart_job == NULL && notify_socket == NULL)
|
||||
if (!notify_socket) {
|
||||
redisLog(REDIS_WARNING,
|
||||
"systemd supervision requested, but NOTIFY_SOCKET not found");
|
||||
return 0;
|
||||
|
||||
if (upstart_job != NULL) {
|
||||
redisLog(REDIS_NOTICE, "supervised by upstart, will stop to signal readyness");
|
||||
raise(SIGSTOP);
|
||||
unsetenv("UPSTART_JOB");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we got here, we're supervised by systemd.
|
||||
*/
|
||||
if ((strchr("@/", notify_socket[0])) == NULL ||
|
||||
strlen(notify_socket) < 2)
|
||||
if ((strchr("@/", notify_socket[0])) == NULL || strlen(notify_socket) < 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
redisLog(REDIS_NOTICE, "supervised by systemd, will signal readyness");
|
||||
if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
|
||||
redisLog(REDIS_WARNING, "cannot contact systemd socket %s", notify_socket);
|
||||
if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
|
||||
redisLog(REDIS_WARNING,
|
||||
"Can't connect to systemd socket %s", notify_socket);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bzero(&su, sizeof(su));
|
||||
memset(&su, 0, sizeof(su));
|
||||
su.sun_family = AF_UNIX;
|
||||
strncpy (su.sun_path, notify_socket, sizeof(su.sun_path) -1);
|
||||
su.sun_path[sizeof(su.sun_path) - 1] = '\0';
|
||||
@@ -3628,11 +3675,11 @@ int redisIsSupervised(void) {
|
||||
if (notify_socket[0] == '@')
|
||||
su.sun_path[0] = '\0';
|
||||
|
||||
bzero(&iov, sizeof(iov));
|
||||
memset(&iov, 0, sizeof(iov));
|
||||
iov.iov_base = "READY=1";
|
||||
iov.iov_len = strlen("READY=1");
|
||||
|
||||
bzero(&hdr, sizeof(hdr));
|
||||
memset(&hdr, 0, sizeof(hdr));
|
||||
hdr.msg_name = &su;
|
||||
hdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) +
|
||||
strlen(notify_socket);
|
||||
@@ -3644,7 +3691,7 @@ int redisIsSupervised(void) {
|
||||
sendto_flags |= MSG_NOSIGNAL;
|
||||
#endif
|
||||
if (sendmsg(fd, &hdr, sendto_flags) < 0) {
|
||||
redisLog(REDIS_WARNING, "Cannot send notification to systemd");
|
||||
redisLog(REDIS_WARNING, "Can't send notification to systemd");
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
@@ -3652,6 +3699,26 @@ int redisIsSupervised(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int redisIsSupervised(int mode) {
|
||||
if (mode == REDIS_SUPERVISED_AUTODETECT) {
|
||||
const char *upstart_job = getenv("UPSTART_JOB");
|
||||
const char *notify_socket = getenv("NOTIFY_SOCKET");
|
||||
|
||||
if (upstart_job) {
|
||||
redisSupervisedUpstart();
|
||||
} else if (notify_socket) {
|
||||
redisSupervisedSystemd();
|
||||
}
|
||||
} else if (mode == REDIS_SUPERVISED_UPSTART) {
|
||||
return redisSupervisedUpstart();
|
||||
} else if (mode == REDIS_SUPERVISED_SYSTEMD) {
|
||||
return redisSupervisedSystemd();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct timeval tv;
|
||||
|
||||
@@ -3702,6 +3769,12 @@ int main(int argc, char **argv) {
|
||||
initSentinel();
|
||||
}
|
||||
|
||||
/* Check if we need to start in redis-check-rdb mode. We just execute
|
||||
* the program main. However the program is part of the Redis executable
|
||||
* so that we can easily execute an RDB check on loading errors. */
|
||||
if (strstr(argv[0],"redis-check-rdb") != NULL)
|
||||
exit(redis_check_rdb_main(argv,argc));
|
||||
|
||||
if (argc >= 2) {
|
||||
int j = 1; /* First option to parse in argv[] */
|
||||
sds options = sdsempty();
|
||||
@@ -3733,6 +3806,11 @@ int main(int argc, char **argv) {
|
||||
while(j != argc) {
|
||||
if (argv[j][0] == '-' && argv[j][1] == '-') {
|
||||
/* Option name */
|
||||
if (!strcmp(argv[j], "--check-rdb")) {
|
||||
/* Argument has no options, need to skip for parsing. */
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
if (sdslen(options)) options = sdscat(options,"\n");
|
||||
options = sdscat(options,argv[j]+2);
|
||||
options = sdscat(options," ");
|
||||
@@ -3758,10 +3836,12 @@ int main(int argc, char **argv) {
|
||||
redisLog(REDIS_WARNING, "Warning: no config file specified, using the default config. In order to specify a config file use %s /path/to/%s.conf", argv[0], server.sentinel_mode ? "sentinel" : "redis");
|
||||
}
|
||||
|
||||
server.supervised = redisIsSupervised();
|
||||
if (server.daemonize && server.supervised == 0) daemonize();
|
||||
server.supervised = redisIsSupervised(server.supervised_mode);
|
||||
int background = server.daemonize && !server.supervised;
|
||||
if (background) daemonize();
|
||||
|
||||
initServer();
|
||||
if (server.daemonize && server.supervised == 0) createPidFile();
|
||||
if (background || server.pidfile) createPidFile();
|
||||
redisSetProcTitle(argv[0]);
|
||||
redisAsciiArt();
|
||||
|
||||
|
||||
+19
-6
@@ -32,10 +32,7 @@
|
||||
|
||||
#include "fmacros.h"
|
||||
#include "config.h"
|
||||
|
||||
#if defined(__sun)
|
||||
#include "solarisfixes.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -122,6 +119,7 @@ typedef long long mstime_t; /* millisecond time type. */
|
||||
#define REDIS_DEFAULT_RDB_FILENAME "dump.rdb"
|
||||
#define REDIS_DEFAULT_REPL_DISKLESS_SYNC 0
|
||||
#define REDIS_DEFAULT_REPL_DISKLESS_SYNC_DELAY 5
|
||||
#define REDIS_DEFAULT_REPL_NO_SYNC 0
|
||||
#define REDIS_DEFAULT_SLAVE_SERVE_STALE_DATA 1
|
||||
#define REDIS_DEFAULT_SLAVE_READ_ONLY 1
|
||||
#define REDIS_DEFAULT_REPL_DISABLE_TCP_NODELAY 0
|
||||
@@ -134,7 +132,7 @@ typedef long long mstime_t; /* millisecond time type. */
|
||||
#define REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC 1
|
||||
#define REDIS_DEFAULT_MIN_SLAVES_TO_WRITE 0
|
||||
#define REDIS_DEFAULT_MIN_SLAVES_MAX_LAG 10
|
||||
#define REDIS_IP_STR_LEN INET6_ADDRSTRLEN
|
||||
#define REDIS_IP_STR_LEN 46 /* INET6_ADDRSTRLEN is 46, but we need to be sure */
|
||||
#define REDIS_PEER_ID_LEN (REDIS_IP_STR_LEN+32) /* Must be enough for ip:port */
|
||||
#define REDIS_BINDADDR_MAX 16
|
||||
#define REDIS_MIN_RESERVED_FDS 32
|
||||
@@ -260,6 +258,8 @@ typedef long long mstime_t; /* millisecond time type. */
|
||||
#define REDIS_PRE_PSYNC (1<<16) /* Instance don't understand PSYNC. */
|
||||
#define REDIS_READONLY (1<<17) /* Cluster client is in read-only state. */
|
||||
#define REDIS_PUBSUB (1<<18) /* Client is in Pub/Sub mode. */
|
||||
#define REDIS_PREVENT_PROP (1<<19) /* Don't propagate to AOF / Slaves. */
|
||||
#define REDIS_SLAVE_NO_SYNC (1<<20) /* Result of: REPLCONF use-sync 0. */
|
||||
|
||||
/* Client block type (btype field in client structure)
|
||||
* if REDIS_BLOCKED flag is set. */
|
||||
@@ -316,6 +316,12 @@ typedef long long mstime_t; /* millisecond time type. */
|
||||
#define REDIS_LOG_RAW (1<<10) /* Modifier to log without timestamp */
|
||||
#define REDIS_DEFAULT_VERBOSITY REDIS_NOTICE
|
||||
|
||||
/* Supervision options */
|
||||
#define REDIS_SUPERVISED_NONE 0
|
||||
#define REDIS_SUPERVISED_AUTODETECT 1
|
||||
#define REDIS_SUPERVISED_SYSTEMD 2
|
||||
#define REDIS_SUPERVISED_UPSTART 3
|
||||
|
||||
/* Anti-warning macro... */
|
||||
#define REDIS_NOTUSED(V) ((void) V)
|
||||
|
||||
@@ -705,7 +711,7 @@ struct redisServer {
|
||||
off_t loading_process_events_interval_bytes;
|
||||
/* Fast pointers to often looked up command */
|
||||
struct redisCommand *delCommand, *multiCommand, *lpushCommand, *lpopCommand,
|
||||
*rpopCommand;
|
||||
*rpopCommand, *sremCommand;
|
||||
/* Fields used only for stats */
|
||||
time_t stat_starttime; /* Server start time */
|
||||
long long stat_numcommands; /* Number of processed commands */
|
||||
@@ -743,7 +749,8 @@ struct redisServer {
|
||||
int active_expire_enabled; /* Can be disabled for testing purposes. */
|
||||
size_t client_max_querybuf_len; /* Limit for client query buffer length */
|
||||
int dbnum; /* Total number of configured DBs */
|
||||
int supervised; /* True if supervised by upstart or systemd */
|
||||
int supervised; /* 1 if supervised, 0 otherwise. */
|
||||
int supervised_mode; /* See REDIS_SUPERVISED_* */
|
||||
int daemonize; /* True if running as a daemon */
|
||||
clientBufferLimitsConfig client_obuf_limits[REDIS_CLIENT_TYPE_COUNT];
|
||||
/* AOF persistence */
|
||||
@@ -848,6 +855,7 @@ struct redisServer {
|
||||
int slave_priority; /* Reported in INFO and used by Sentinel. */
|
||||
char repl_master_runid[REDIS_RUN_ID_SIZE+1]; /* Master run id for PSYNC. */
|
||||
long long repl_master_initial_offset; /* Master PSYNC offset. */
|
||||
int repl_no_sync; /* Streaming replication, no SYNC. */
|
||||
/* Replication script cache. */
|
||||
dict *repl_scriptcache_dict; /* SHA1 all slaves are aware of. */
|
||||
list *repl_scriptcache_fifo; /* First in, first out LRU eviction. */
|
||||
@@ -1248,6 +1256,7 @@ void call(redisClient *c, int flags);
|
||||
void propagate(struct redisCommand *cmd, int dbid, robj **argv, int argc, int flags);
|
||||
void alsoPropagate(struct redisCommand *cmd, int dbid, robj **argv, int argc, int target);
|
||||
void forceCommandPropagation(redisClient *c, int flags);
|
||||
void preventCommandPropagation(redisClient *c);
|
||||
int prepareForShutdown();
|
||||
#ifdef __GNUC__
|
||||
void redisLog(int level, const char *fmt, ...)
|
||||
@@ -1376,6 +1385,10 @@ void sentinelTimer(void);
|
||||
char *sentinelHandleConfiguration(char **argv, int argc);
|
||||
void sentinelIsRunning(void);
|
||||
|
||||
/* redis-check-rdb */
|
||||
int redis_check_rdb(char *rdbfilename);
|
||||
int redis_check_rdb_main(char **argv, int argc);
|
||||
|
||||
/* Scripting */
|
||||
void scriptingInit(void);
|
||||
|
||||
|
||||
+71
-13
@@ -480,6 +480,9 @@ void syncCommand(redisClient *c) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Accept the slave ASAP if it requested no-sync mode. */
|
||||
if (c->flags & REDIS_SLAVE_NO_SYNC) goto attach_slave;
|
||||
|
||||
redisLog(REDIS_NOTICE,"Slave %s asks for synchronization",
|
||||
replicationGetSlaveName(c));
|
||||
|
||||
@@ -571,6 +574,8 @@ void syncCommand(redisClient *c) {
|
||||
}
|
||||
}
|
||||
|
||||
attach_slave:
|
||||
|
||||
if (server.repl_disable_tcp_nodelay)
|
||||
anetDisableTcpNoDelay(NULL, c->fd); /* Non critical if it fails. */
|
||||
c->repldbfd = -1;
|
||||
@@ -579,6 +584,18 @@ void syncCommand(redisClient *c) {
|
||||
listAddNodeTail(server.slaves,c);
|
||||
if (listLength(server.slaves) == 1 && server.repl_backlog == NULL)
|
||||
createReplicationBacklog();
|
||||
|
||||
/* Put the slave fully online right now if it is a no-sync one. */
|
||||
if (c->flags & REDIS_SLAVE_NO_SYNC) {
|
||||
char buf[128];
|
||||
int buflen;
|
||||
|
||||
/* Inform the slave with +NOTNEEDED that the request was accepted. */
|
||||
buflen = snprintf(buf,sizeof(buf),"+NOTNEEDED\r\n");
|
||||
if (write(c->fd,buf,buflen) != buflen) freeClientAsync(c);
|
||||
aeDeleteFileEvent(server.el,c->fd,AE_WRITABLE);
|
||||
putSlaveOnline(c);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -613,6 +630,18 @@ void replconfCommand(redisClient *c) {
|
||||
&port,NULL) != REDIS_OK))
|
||||
return;
|
||||
c->slave_listening_port = port;
|
||||
} else if (!strcasecmp(c->argv[j]->ptr,"use-sync")) {
|
||||
/* REPLCONF USE-SYNC is used in order for the slave to request
|
||||
* synchronization-less replication, the master will just send
|
||||
* new data without trying to synchronize the slave. */
|
||||
long long val;
|
||||
|
||||
if ((getLongLongFromObject(c->argv[j+1], &val) != REDIS_OK))
|
||||
return;
|
||||
if (val)
|
||||
c->flags &= ~REDIS_SLAVE_NO_SYNC;
|
||||
else
|
||||
c->flags |= REDIS_SLAVE_NO_SYNC;
|
||||
} else if (!strcasecmp(c->argv[j]->ptr,"ack")) {
|
||||
/* REPLCONF ACK is used by slave to inform the master the amount
|
||||
* of replication stream that it processed so far. It is an
|
||||
@@ -854,6 +883,23 @@ void replicationEmptyDbCallback(void *privdata) {
|
||||
replicationSendNewlineToMaster();
|
||||
}
|
||||
|
||||
/* Once we have a link with the master and the synchroniziation was
|
||||
* performed, this function materializes the master client we store
|
||||
* at server.master, starting from the specified file descriptor. */
|
||||
void replicationCreateMasterClient(int fd) {
|
||||
server.master = createClient(fd);
|
||||
server.master->flags |= REDIS_MASTER;
|
||||
server.master->authenticated = 1;
|
||||
server.repl_state = REDIS_REPL_CONNECTED;
|
||||
server.master->reploff = server.repl_master_initial_offset;
|
||||
memcpy(server.master->replrunid, server.repl_master_runid,
|
||||
sizeof(server.repl_master_runid));
|
||||
/* If master offset is set to -1, this master is old and is not
|
||||
* PSYNC capable, so we flag it accordingly. */
|
||||
if (server.master->reploff == -1)
|
||||
server.master->flags |= REDIS_PRE_PSYNC;
|
||||
}
|
||||
|
||||
/* Asynchronously read the SYNC payload we receive from a master */
|
||||
#define REPL_MAX_WRITTEN_BEFORE_FSYNC (1024*1024*8) /* 8 MB */
|
||||
void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
@@ -1017,17 +1063,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
/* Final setup of the connected slave <- master link */
|
||||
zfree(server.repl_transfer_tmpfile);
|
||||
close(server.repl_transfer_fd);
|
||||
server.master = createClient(server.repl_transfer_s);
|
||||
server.master->flags |= REDIS_MASTER;
|
||||
server.master->authenticated = 1;
|
||||
server.repl_state = REDIS_REPL_CONNECTED;
|
||||
server.master->reploff = server.repl_master_initial_offset;
|
||||
memcpy(server.master->replrunid, server.repl_master_runid,
|
||||
sizeof(server.repl_master_runid));
|
||||
/* If master offset is set to -1, this master is old and is not
|
||||
* PSYNC capable, so we flag it accordingly. */
|
||||
if (server.master->reploff == -1)
|
||||
server.master->flags |= REDIS_PRE_PSYNC;
|
||||
replicationCreateMasterClient(server.repl_transfer_s);
|
||||
redisLog(REDIS_NOTICE, "MASTER <-> SLAVE sync: Finished with success");
|
||||
/* Restart the AOF subsystem now that we finished the sync. This
|
||||
* will trigger an AOF rewrite, and when done will start appending
|
||||
@@ -1133,7 +1169,7 @@ int slaveTryPartialResynchronization(int fd) {
|
||||
* client structure representing the master into server.master. */
|
||||
server.repl_master_initial_offset = -1;
|
||||
|
||||
if (server.cached_master) {
|
||||
if (server.cached_master && server.repl_no_sync == 0) {
|
||||
psync_runid = server.cached_master->replrunid;
|
||||
snprintf(psync_offset,sizeof(psync_offset),"%lld", server.cached_master->reploff+1);
|
||||
redisLog(REDIS_NOTICE,"Trying a partial resynchronization (request %s:%s).", psync_runid, psync_offset);
|
||||
@@ -1179,6 +1215,15 @@ int slaveTryPartialResynchronization(int fd) {
|
||||
return PSYNC_FULLRESYNC;
|
||||
}
|
||||
|
||||
if (!strncmp(reply,"+NOTNEEDED",10)) {
|
||||
/* No-sync replication. */
|
||||
redisLog(REDIS_NOTICE, "No-sync slave accepted without SYNC phase.");
|
||||
sdsfree(reply);
|
||||
server.repl_master_initial_offset = 0;
|
||||
replicationCreateMasterClient(fd);
|
||||
return PSYNC_CONTINUE;
|
||||
}
|
||||
|
||||
if (!strncmp(reply,"+CONTINUE",9)) {
|
||||
/* Partial resync was accepted, set the replication state accordingly */
|
||||
redisLog(REDIS_NOTICE,
|
||||
@@ -1285,7 +1330,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
}
|
||||
|
||||
/* AUTH with the master if required. */
|
||||
if(server.masterauth) {
|
||||
if (server.masterauth) {
|
||||
err = sendSynchronousCommand(fd,"AUTH",server.masterauth,NULL);
|
||||
if (err[0] == '-') {
|
||||
redisLog(REDIS_WARNING,"Unable to AUTH to MASTER: %s",err);
|
||||
@@ -1295,6 +1340,18 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
sdsfree(err);
|
||||
}
|
||||
|
||||
/* Inform the master we don't want to synchronize if we are using
|
||||
* repl-no-sync mode. */
|
||||
if (server.repl_no_sync) {
|
||||
err = sendSynchronousCommand(fd,"REPLCONF","use-sync","0",NULL);
|
||||
if (err[0] == '-') {
|
||||
redisLog(REDIS_WARNING,"Unable to enable no-sync mode: %s",err);
|
||||
sdsfree(err);
|
||||
goto error;
|
||||
}
|
||||
sdsfree(err);
|
||||
}
|
||||
|
||||
/* Set the slave port, so that Master's INFO command can list the
|
||||
* slave listening port correctly. */
|
||||
{
|
||||
@@ -1691,6 +1748,7 @@ void refreshGoodSlavesCount(void) {
|
||||
time_t lag = server.unixtime - slave->repl_ack_time;
|
||||
|
||||
if (slave->replstate == REDIS_REPL_ONLINE &&
|
||||
!(slave->flags & REDIS_SLAVE_NO_SYNC) &&
|
||||
lag <= server.repl_min_slaves_max_lag) good++;
|
||||
}
|
||||
server.repl_good_slaves_count = good;
|
||||
|
||||
+37
-1
@@ -30,6 +30,7 @@
|
||||
#include "redis.h"
|
||||
#include "sha1.h"
|
||||
#include "rand.h"
|
||||
#include "cluster.h"
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
@@ -213,11 +214,27 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
|
||||
static int argv_size = 0;
|
||||
static robj *cached_objects[LUA_CMD_OBJCACHE_SIZE];
|
||||
static size_t cached_objects_len[LUA_CMD_OBJCACHE_SIZE];
|
||||
static int inuse = 0; /* Recursive calls detection. */
|
||||
|
||||
/* By using Lua debug hooks it is possible to trigger a recursive call
|
||||
* to luaRedisGenericCommand(), which normally should never happen.
|
||||
* To make this function reentrant is futile and makes it slower, but
|
||||
* we should at least detect such a misuse, and abort. */
|
||||
if (inuse) {
|
||||
char *recursion_warning =
|
||||
"luaRedisGenericCommand() recursive call detected. "
|
||||
"Are you doing funny stuff with Lua debug hooks?";
|
||||
redisLog(REDIS_WARNING,"%s",recursion_warning);
|
||||
luaPushError(lua,recursion_warning);
|
||||
return 1;
|
||||
}
|
||||
inuse++;
|
||||
|
||||
/* Require at least one argument */
|
||||
if (argc == 0) {
|
||||
luaPushError(lua,
|
||||
"Please specify at least one argument for redis.call()");
|
||||
inuse--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -272,6 +289,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
|
||||
}
|
||||
luaPushError(lua,
|
||||
"Lua redis() command arguments must be strings or integers");
|
||||
inuse--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -291,6 +309,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
|
||||
luaPushError(lua,"Unknown Redis command called from Lua script");
|
||||
goto cleanup;
|
||||
}
|
||||
c->cmd = cmd;
|
||||
|
||||
/* There are commands that are not allowed inside scripts. */
|
||||
if (cmd->flags & REDIS_CMD_NOSCRIPT) {
|
||||
@@ -337,8 +356,23 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
|
||||
if (cmd->flags & REDIS_CMD_RANDOM) server.lua_random_dirty = 1;
|
||||
if (cmd->flags & REDIS_CMD_WRITE) server.lua_write_dirty = 1;
|
||||
|
||||
/* If this is a Redis Cluster node, we need to make sure Lua is not
|
||||
* trying to access non-local keys. */
|
||||
if (server.cluster_enabled) {
|
||||
/* Duplicate relevant flags in the lua client. */
|
||||
c->flags &= ~(REDIS_READONLY|REDIS_ASKING);
|
||||
c->flags |= server.lua_caller->flags & (REDIS_READONLY|REDIS_ASKING);
|
||||
if (getNodeByQuery(c,c->cmd,c->argv,c->argc,NULL,NULL) !=
|
||||
server.cluster->myself)
|
||||
{
|
||||
luaPushError(lua,
|
||||
"Lua script attempted to access a non local key in a "
|
||||
"cluster node");
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Run the command */
|
||||
c->cmd = cmd;
|
||||
call(c,REDIS_CALL_SLOWLOG | REDIS_CALL_STATS);
|
||||
|
||||
/* Convert the result of the Redis command into a suitable Lua type.
|
||||
@@ -409,8 +443,10 @@ cleanup:
|
||||
* return the plain error. */
|
||||
lua_pushstring(lua,"err");
|
||||
lua_gettable(lua,-2);
|
||||
inuse--;
|
||||
return lua_error(lua);
|
||||
}
|
||||
inuse--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@ A million repetitions of "a"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h> /* for u_int*_t */
|
||||
#if defined(__sun)
|
||||
#include "solarisfixes.h"
|
||||
#endif
|
||||
#include "sha1.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(__sun)
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#include <math.h>
|
||||
#undef isnan
|
||||
@@ -48,3 +50,5 @@
|
||||
#define u_int uint
|
||||
#define u_int32_t uint32_t
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#endif /* __sun */
|
||||
|
||||
+35
-14
@@ -322,17 +322,17 @@ void sortCommand(redisClient *c) {
|
||||
}
|
||||
if (end >= vectorlen) end = vectorlen-1;
|
||||
|
||||
/* Optimization:
|
||||
/* Whenever possible, we load elements into the output array in a more
|
||||
* direct way. This is possible if:
|
||||
*
|
||||
* 1) if the object to sort is a sorted set.
|
||||
* 1) The object to sort is a sorted set or a list (internally sorted).
|
||||
* 2) There is nothing to sort as dontsort is true (BY <constant string>).
|
||||
* 3) We have a LIMIT option that actually reduces the number of elements
|
||||
* to fetch.
|
||||
*
|
||||
* In this case to load all the objects in the vector is a huge waste of
|
||||
* resources. We just allocate a vector that is big enough for the selected
|
||||
* range length, and make sure to load just this part in the vector. */
|
||||
if (sortval->type == REDIS_ZSET &&
|
||||
* In this special case, if we have a LIMIT option that actually reduces
|
||||
* the number of elements to fetch, we also optimize to just load the
|
||||
* range we are interested in and allocating a vector that is big enough
|
||||
* for the selected range length. */
|
||||
if ((sortval->type == REDIS_ZSET || sortval->type == REDIS_LIST) &&
|
||||
dontsort &&
|
||||
(start != 0 || end != vectorlen-1))
|
||||
{
|
||||
@@ -343,7 +343,32 @@ void sortCommand(redisClient *c) {
|
||||
vector = zmalloc(sizeof(redisSortObject)*vectorlen);
|
||||
j = 0;
|
||||
|
||||
if (sortval->type == REDIS_LIST) {
|
||||
if (sortval->type == REDIS_LIST && dontsort) {
|
||||
/* Special handling for a list, if 'dontsort' is true.
|
||||
* This makes sure we return elements in the list original
|
||||
* ordering, accordingly to DESC / ASC options.
|
||||
*
|
||||
* Note that in this case we also handle LIMIT here in a direct
|
||||
* way, just getting the required range, as an optimization. */
|
||||
if (end >= start) {
|
||||
listTypeIterator *li;
|
||||
listTypeEntry entry;
|
||||
li = listTypeInitIterator(sortval,
|
||||
desc ? (long)(listTypeLength(sortval) - start - 1) : start,
|
||||
desc ? REDIS_HEAD : REDIS_TAIL);
|
||||
|
||||
while(j < vectorlen && listTypeNext(li,&entry)) {
|
||||
vector[j].obj = listTypeGet(&entry);
|
||||
vector[j].u.score = 0;
|
||||
vector[j].u.cmpobj = NULL;
|
||||
j++;
|
||||
}
|
||||
listTypeReleaseIterator(li);
|
||||
/* Fix start/end: output code is not aware of this optimization. */
|
||||
end -= start;
|
||||
start = 0;
|
||||
}
|
||||
} else if (sortval->type == REDIS_LIST) {
|
||||
listTypeIterator *li = listTypeInitIterator(sortval,0,REDIS_TAIL);
|
||||
listTypeEntry entry;
|
||||
while(listTypeNext(li,&entry)) {
|
||||
@@ -399,10 +424,7 @@ void sortCommand(redisClient *c) {
|
||||
j++;
|
||||
ln = desc ? ln->backward : ln->level[0].forward;
|
||||
}
|
||||
/* The code producing the output does not know that in the case of
|
||||
* sorted set, 'dontsort', and LIMIT, we are able to get just the
|
||||
* range, already sorted, so we need to adjust "start" and "end"
|
||||
* to make sure start is set to 0. */
|
||||
/* Fix start/end: output code is not aware of this optimization. */
|
||||
end -= start;
|
||||
start = 0;
|
||||
} else if (sortval->type == REDIS_ZSET) {
|
||||
@@ -420,7 +442,6 @@ void sortCommand(redisClient *c) {
|
||||
} else {
|
||||
redisPanic("Unknown type");
|
||||
}
|
||||
printf("j: %d; vectorlen: %d\n", j, vectorlen);
|
||||
redisAssertWithInfo(c,sortval,j == vectorlen);
|
||||
|
||||
/* Now it's time to load the right scores in the sorting vector */
|
||||
|
||||
+105
-162
@@ -45,6 +45,11 @@ robj *setTypeCreate(robj *value) {
|
||||
return createSetObject();
|
||||
}
|
||||
|
||||
/* Add the specified value into a set. The function takes care of incrementing
|
||||
* the reference count of the object if needed in order to retain a copy.
|
||||
*
|
||||
* If the value was already member of the set, nothing is done and 0 is
|
||||
* returned, otherwise the new element is added and 1 is returned. */
|
||||
int setTypeAdd(robj *subject, robj *value) {
|
||||
long long llval;
|
||||
if (subject->encoding == REDIS_ENCODING_HT) {
|
||||
@@ -207,106 +212,6 @@ int setTypeRandomElement(robj *setobj, robj **objele, int64_t *llele) {
|
||||
return setobj->encoding;
|
||||
}
|
||||
|
||||
/* Return a number of random elements from a non empty set.
|
||||
*
|
||||
* This is a version of setTypeRandomElement() that is modified in order to
|
||||
* return multiple entries, using dictGetRandomKeys() and intsetRandomMembers().
|
||||
*
|
||||
* The elements are stored into 'aux_set' which should be of a set type.
|
||||
*
|
||||
* The function returns the number of items stored into 'aux_set', that may
|
||||
* be less than 'count' if the hash table has less than 'count' elements
|
||||
* inside.
|
||||
*
|
||||
* Note that this function is not suitable when you need a good distribution
|
||||
* of the returned items, but only when you need to "sample" a given number
|
||||
* of continuous elements to run some kind of algorithm or to produce
|
||||
* statistics. However the function is much faster than setTypeRandomElement()
|
||||
* at producing N elements, and the elements are guaranteed to be non
|
||||
* repeating.
|
||||
*/
|
||||
unsigned long setTypeRandomElements(robj *set, unsigned long count,
|
||||
robj *aux_set) {
|
||||
unsigned long set_size;
|
||||
unsigned long elements_to_return = count;
|
||||
unsigned long elements_copied = 0;
|
||||
unsigned long current_element = 0;
|
||||
|
||||
/* Like all setType* functions, we assume good behavior on part of the
|
||||
* caller, so no extra parameter checks are made. */
|
||||
|
||||
/* If the number of elements in the the set is less than the count
|
||||
* requested, just return all of them. */
|
||||
set_size = setTypeSize(set);
|
||||
if (set_size < count) {
|
||||
elements_to_return = set_size;
|
||||
}
|
||||
|
||||
/* TODO: It is definitely faster adding items to the set by directly
|
||||
* handling the Dict or intset inside it, avoiding the constant encoding
|
||||
* checks inside setTypeAdd(). However, We don't want to touch the set
|
||||
* internals in non setType* functions. So, we just call setTypeAdd()
|
||||
* multiple times, but this isn't an optimal solution.
|
||||
* Another option would be to create a bulk-add function:
|
||||
* setTypeAddBulk(). */
|
||||
if (set->encoding == REDIS_ENCODING_HT) {
|
||||
/* Allocate result array */
|
||||
dictEntry **random_elements =
|
||||
zmalloc(sizeof(dictEntry*) * elements_to_return);
|
||||
|
||||
/* Get the random elements */
|
||||
elements_copied =
|
||||
dictGetRandomKeys(set->ptr, random_elements, elements_to_return);
|
||||
redisAssert(elements_copied == elements_to_return);
|
||||
|
||||
/* Put them into the set */
|
||||
for (current_element = 0; current_element < elements_copied;
|
||||
current_element++) {
|
||||
|
||||
/* We get the key and duplicate it, as we know it is a string */
|
||||
setTypeAdd(aux_set,
|
||||
dictGetKey(random_elements[current_element]));
|
||||
}
|
||||
|
||||
zfree(random_elements);
|
||||
|
||||
} else if (set->encoding == REDIS_ENCODING_INTSET) {
|
||||
/* Allocate result array */
|
||||
int64_t *random_elements =
|
||||
zmalloc(sizeof(int64_t) * elements_to_return);
|
||||
robj* element_as_str = NULL;
|
||||
|
||||
elements_copied =
|
||||
intsetRandomMembers((intset*) set->ptr,
|
||||
random_elements,
|
||||
elements_to_return);
|
||||
|
||||
redisAssert(elements_copied == elements_to_return);
|
||||
|
||||
/* Put them into the set */
|
||||
for (current_element = 0; current_element < elements_copied;
|
||||
current_element++) {
|
||||
|
||||
element_as_str = createStringObjectFromLongLong(
|
||||
random_elements[current_element]);
|
||||
|
||||
/* Put the values in the set */
|
||||
setTypeAdd(aux_set,
|
||||
element_as_str);
|
||||
|
||||
decrRefCount(element_as_str);
|
||||
}
|
||||
|
||||
zfree(random_elements);
|
||||
} else {
|
||||
redisPanic("Unknown set encoding");
|
||||
}
|
||||
|
||||
/* We have a set with random elements. Return the actual elements in
|
||||
the aux_set. */
|
||||
return elements_copied;
|
||||
}
|
||||
|
||||
unsigned long setTypeSize(robj *subject) {
|
||||
if (subject->encoding == REDIS_ENCODING_HT) {
|
||||
return dictSize((dict*)subject->ptr);
|
||||
@@ -480,15 +385,18 @@ void scardCommand(redisClient *c) {
|
||||
addReplyLongLong(c,setTypeSize(o));
|
||||
}
|
||||
|
||||
/* handle the "SPOP key <count>" variant. The normal version of the
|
||||
/* Handle the "SPOP key <count>" variant. The normal version of the
|
||||
* command is handled by the spopCommand() function itself. */
|
||||
|
||||
/* How many times bigger should be the set compared to the remaining size
|
||||
* for us to use the "create new set" strategy? Read later in the
|
||||
* implementation for more info. */
|
||||
#define SPOP_MOVE_STRATEGY_MUL 5
|
||||
|
||||
void spopWithCountCommand(redisClient *c) {
|
||||
long l;
|
||||
unsigned long count, size;
|
||||
unsigned long elements_returned;
|
||||
robj *set, *aux, *aux_set;
|
||||
int64_t llele;
|
||||
robj *set;
|
||||
|
||||
/* Get the count argument */
|
||||
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != REDIS_OK) return;
|
||||
@@ -511,18 +419,16 @@ void spopWithCountCommand(redisClient *c) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the size of the set. It is always > 0, as empty sets get
|
||||
* deleted. */
|
||||
size = setTypeSize(set);
|
||||
|
||||
/* Generate an SPOP keyspace notification */
|
||||
notifyKeyspaceEvent(REDIS_NOTIFY_SET,"spop",c->argv[1],c->db->id);
|
||||
server.dirty += count;
|
||||
|
||||
/* CASE 1:
|
||||
* The number of requested elements is greater than or equal to
|
||||
* the number of elements inside the set: simply return the whole set. */
|
||||
if (count >= size) {
|
||||
|
||||
/* We just return the entire set */
|
||||
sunionDiffGenericCommand(c,c->argv+1,1,NULL,REDIS_OP_UNION);
|
||||
|
||||
@@ -530,73 +436,110 @@ void spopWithCountCommand(redisClient *c) {
|
||||
dbDelete(c->db,c->argv[1]);
|
||||
notifyKeyspaceEvent(REDIS_NOTIFY_GENERIC,"del",c->argv[1],c->db->id);
|
||||
|
||||
/* Replicate/AOF this command as an SREM operation */
|
||||
aux = createStringObject("DEL",3);
|
||||
rewriteClientCommandVector(c,2,aux,c->argv[1]);
|
||||
decrRefCount(aux);
|
||||
|
||||
/* Propagate this command as an DEL operation */
|
||||
rewriteClientCommandVector(c,2,shared.del,c->argv[1]);
|
||||
signalModifiedKey(c->db,c->argv[1]);
|
||||
server.dirty++;
|
||||
return;
|
||||
}
|
||||
|
||||
/* CASE 2:
|
||||
* The number of requested elements is less than the number
|
||||
* of elements inside the set. */
|
||||
/* Case 2 and 3 require to replicate SPOP as a set of SERM commands.
|
||||
* Prepare our replication argument vector. Also send the array length
|
||||
* which is common to both the code paths. */
|
||||
robj *propargv[3];
|
||||
propargv[0] = createStringObject("SREM",4);
|
||||
propargv[1] = c->argv[1];
|
||||
addReplyMultiBulkLen(c,count);
|
||||
|
||||
/* We need an auxiliary set. Optimistically, we create a set using an
|
||||
* Intset internally. */
|
||||
aux = createStringObjectFromLongLong(0);
|
||||
aux_set = setTypeCreate(aux);
|
||||
decrRefCount(aux);
|
||||
/* Common iteration vars. */
|
||||
robj *objele;
|
||||
int encoding;
|
||||
int64_t llele;
|
||||
unsigned long remaining = size-count; /* Elements left after SPOP. */
|
||||
|
||||
/* Get the count requested of random elements from the set into our
|
||||
* auxiliary set. */
|
||||
elements_returned = setTypeRandomElements(set, count, aux_set);
|
||||
redisAssert(elements_returned == count);
|
||||
|
||||
{
|
||||
setTypeIterator *si;
|
||||
robj *objele;
|
||||
int element_encoding;
|
||||
|
||||
addReplyMultiBulkLen(c, elements_returned);
|
||||
|
||||
/* Replicate/AOF this command as an SREM operation */
|
||||
aux = createStringObject("SREM",4);
|
||||
|
||||
si = setTypeInitIterator(aux_set);
|
||||
while ((element_encoding = setTypeNext(si, &objele, &llele)) != -1) {
|
||||
if (element_encoding == REDIS_ENCODING_HT) {
|
||||
|
||||
addReplyBulk(c, objele);
|
||||
|
||||
/* Replicate/AOF this command as an SREM commands */
|
||||
rewriteClientCommandVector(c, 3, aux, c->argv[1], objele);
|
||||
setTypeRemove(set, objele);
|
||||
}
|
||||
else if (element_encoding == REDIS_ENCODING_INTSET) {
|
||||
/* TODO: setTypeRemove() forces us to convert all of the ints
|
||||
* to string... isn't there a nicer way to do this? */
|
||||
/* If we are here, the number of requested elements is less than the
|
||||
* number of elements inside the set. Also we are sure that count < size.
|
||||
* Use two different strategies.
|
||||
*
|
||||
* CASE 2: The number of elements to return is small compared to the
|
||||
* set size. We can just extract random elements and return them to
|
||||
* the set. */
|
||||
if (remaining*SPOP_MOVE_STRATEGY_MUL > count) {
|
||||
while(count--) {
|
||||
encoding = setTypeRandomElement(set,&objele,&llele);
|
||||
if (encoding == REDIS_ENCODING_INTSET) {
|
||||
objele = createStringObjectFromLongLong(llele);
|
||||
addReplyBulk(c, objele);
|
||||
|
||||
/* Replicate/AOF this command as an SREM commands */
|
||||
rewriteClientCommandVector(c, 3, aux, c->argv[1], objele);
|
||||
setTypeRemove(set, objele);
|
||||
|
||||
/* We created it, we kill it. */
|
||||
decrRefCount(objele);
|
||||
} else {
|
||||
incrRefCount(objele);
|
||||
}
|
||||
else {
|
||||
redisPanic("Unknown set encoding");
|
||||
|
||||
/* Return the element to the client and remove from the set. */
|
||||
addReplyBulk(c,objele);
|
||||
setTypeRemove(set,objele);
|
||||
|
||||
/* Replicate/AOF this command as an SREM operation */
|
||||
propargv[2] = objele;
|
||||
alsoPropagate(server.sremCommand,c->db->id,propargv,3,
|
||||
REDIS_PROPAGATE_AOF|REDIS_PROPAGATE_REPL);
|
||||
decrRefCount(objele);
|
||||
}
|
||||
} else {
|
||||
/* CASE 3: The number of elements to return is very big, approaching
|
||||
* the size of the set itself. After some time extracting random elements
|
||||
* from such a set becomes computationally expensive, so we use
|
||||
* a different strategy, we extract random elements that we don't
|
||||
* want to return (the elements that will remain part of the set),
|
||||
* creating a new set as we do this (that will be stored as the original
|
||||
* set). Then we return the elements left in the original set and
|
||||
* release it. */
|
||||
robj *newset = NULL;
|
||||
|
||||
/* Create a new set with just the remaining elements. */
|
||||
while(remaining--) {
|
||||
encoding = setTypeRandomElement(set,&objele,&llele);
|
||||
if (encoding == REDIS_ENCODING_INTSET) {
|
||||
objele = createStringObjectFromLongLong(llele);
|
||||
} else {
|
||||
incrRefCount(objele);
|
||||
}
|
||||
if (!newset) newset = setTypeCreate(objele);
|
||||
setTypeAdd(newset,objele);
|
||||
setTypeRemove(set,objele);
|
||||
decrRefCount(objele);
|
||||
}
|
||||
|
||||
/* Assign the new set as the key value. */
|
||||
incrRefCount(set); /* Protect the old set value. */
|
||||
dbOverwrite(c->db,c->argv[1],newset);
|
||||
|
||||
/* Tranfer the old set to the client and release it. */
|
||||
setTypeIterator *si;
|
||||
si = setTypeInitIterator(set);
|
||||
while((encoding = setTypeNext(si,&objele,&llele)) != -1) {
|
||||
if (encoding == REDIS_ENCODING_INTSET) {
|
||||
objele = createStringObjectFromLongLong(llele);
|
||||
} else {
|
||||
incrRefCount(objele);
|
||||
}
|
||||
addReplyBulk(c,objele);
|
||||
|
||||
/* Replicate/AOF this command as an SREM operation */
|
||||
propargv[2] = objele;
|
||||
alsoPropagate(server.sremCommand,c->db->id,propargv,3,
|
||||
REDIS_PROPAGATE_AOF|REDIS_PROPAGATE_REPL);
|
||||
|
||||
decrRefCount(objele);
|
||||
}
|
||||
setTypeReleaseIterator(si);
|
||||
|
||||
decrRefCount(aux);
|
||||
decrRefCount(set);
|
||||
}
|
||||
|
||||
/* Free the auxiliary set - we need it no more. */
|
||||
decrRefCount(aux_set);
|
||||
/* Don't propagate the command itself even if we incremented the
|
||||
* dirty counter. We don't want to propagate an SPOP command since
|
||||
* we propagated the command as a set of SREMs operations using
|
||||
* the alsoPropagate() API. */
|
||||
decrRefCount(propargv[0]);
|
||||
preventCommandPropagation(c);
|
||||
}
|
||||
|
||||
void spopCommand(redisClient *c) {
|
||||
|
||||
+16
-4
@@ -61,6 +61,8 @@ static int checkStringLength(redisClient *c, long long size) {
|
||||
#define REDIS_SET_NO_FLAGS 0
|
||||
#define REDIS_SET_NX (1<<0) /* Set if key not exists. */
|
||||
#define REDIS_SET_XX (1<<1) /* Set if key exists. */
|
||||
#define REDIS_SET_EX (1<<2) /* Set if time in seconds is given */
|
||||
#define REDIS_SET_PX (1<<3) /* Set if time in ms in given */
|
||||
|
||||
void setGenericCommand(redisClient *c, int flags, robj *key, robj *val, robj *expire, int unit, robj *ok_reply, robj *abort_reply) {
|
||||
long long milliseconds = 0; /* initialized to avoid any harmness warning */
|
||||
@@ -102,18 +104,28 @@ void setCommand(redisClient *c) {
|
||||
robj *next = (j == c->argc-1) ? NULL : c->argv[j+1];
|
||||
|
||||
if ((a[0] == 'n' || a[0] == 'N') &&
|
||||
(a[1] == 'x' || a[1] == 'X') && a[2] == '\0') {
|
||||
(a[1] == 'x' || a[1] == 'X') && a[2] == '\0' &&
|
||||
!(flags & REDIS_SET_XX))
|
||||
{
|
||||
flags |= REDIS_SET_NX;
|
||||
} else if ((a[0] == 'x' || a[0] == 'X') &&
|
||||
(a[1] == 'x' || a[1] == 'X') && a[2] == '\0') {
|
||||
(a[1] == 'x' || a[1] == 'X') && a[2] == '\0' &&
|
||||
!(flags & REDIS_SET_NX))
|
||||
{
|
||||
flags |= REDIS_SET_XX;
|
||||
} else if ((a[0] == 'e' || a[0] == 'E') &&
|
||||
(a[1] == 'x' || a[1] == 'X') && a[2] == '\0' && next) {
|
||||
(a[1] == 'x' || a[1] == 'X') && a[2] == '\0' &&
|
||||
!(flags & REDIS_SET_PX) && next)
|
||||
{
|
||||
flags |= REDIS_SET_EX;
|
||||
unit = UNIT_SECONDS;
|
||||
expire = next;
|
||||
j++;
|
||||
} else if ((a[0] == 'p' || a[0] == 'P') &&
|
||||
(a[1] == 'x' || a[1] == 'X') && a[2] == '\0' && next) {
|
||||
(a[1] == 'x' || a[1] == 'X') && a[2] == '\0' &&
|
||||
!(flags & REDIS_SET_EX) && next)
|
||||
{
|
||||
flags |= REDIS_SET_PX;
|
||||
unit = UNIT_MILLISECONDS;
|
||||
expire = next;
|
||||
j++;
|
||||
|
||||
+58
-13
@@ -38,8 +38,10 @@
|
||||
#include <sys/time.h>
|
||||
#include <float.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "sha1.h"
|
||||
|
||||
/* Glob-style pattern matching. */
|
||||
int stringmatchlen(const char *pattern, int patternLen,
|
||||
@@ -169,11 +171,12 @@ int stringmatch(const char *pattern, const char *string, int nocase) {
|
||||
}
|
||||
|
||||
/* Convert a string representing an amount of memory into the number of
|
||||
* bytes, so for instance memtoll("1Gi") will return 1073741824 that is
|
||||
* bytes, so for instance memtoll("1Gb") will return 1073741824 that is
|
||||
* (1024*1024*1024).
|
||||
*
|
||||
* On parsing error, if *err is not NULL, it's set to 1, otherwise it's
|
||||
* set to 0 */
|
||||
* set to 0. On error the function return value is 0, regardless of the
|
||||
* fact 'err' is NULL or not. */
|
||||
long long memtoll(const char *p, int *err) {
|
||||
const char *u;
|
||||
char buf[128];
|
||||
@@ -182,6 +185,7 @@ long long memtoll(const char *p, int *err) {
|
||||
unsigned int digits;
|
||||
|
||||
if (err) *err = 0;
|
||||
|
||||
/* Search the first non digit character. */
|
||||
u = p;
|
||||
if (*u == '-') u++;
|
||||
@@ -202,16 +206,26 @@ long long memtoll(const char *p, int *err) {
|
||||
mul = 1024L*1024*1024;
|
||||
} else {
|
||||
if (err) *err = 1;
|
||||
mul = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Copy the digits into a buffer, we'll use strtoll() to convert
|
||||
* the digit (without the unit) into a number. */
|
||||
digits = u-p;
|
||||
if (digits >= sizeof(buf)) {
|
||||
if (err) *err = 1;
|
||||
return LLONG_MAX;
|
||||
return 0;
|
||||
}
|
||||
memcpy(buf,p,digits);
|
||||
buf[digits] = '\0';
|
||||
val = strtoll(buf,NULL,10);
|
||||
|
||||
char *endptr;
|
||||
errno = 0;
|
||||
val = strtoll(buf,&endptr,10);
|
||||
if ((val == 0 && errno == EINVAL) || *endptr != '\0') {
|
||||
if (err) *err = 1;
|
||||
return 0;
|
||||
}
|
||||
return val*mul;
|
||||
}
|
||||
|
||||
@@ -428,11 +442,44 @@ int d2string(char *buf, size_t len, double value) {
|
||||
* having run_id == A, and you reconnect and it has run_id == B, you can be
|
||||
* sure that it is either a different instance or it was restarted. */
|
||||
void getRandomHexChars(char *p, unsigned int len) {
|
||||
FILE *fp = fopen("/dev/urandom","r");
|
||||
char *charset = "0123456789abcdef";
|
||||
unsigned int j;
|
||||
|
||||
if (fp == NULL || fread(p,len,1,fp) == 0) {
|
||||
/* Global state. */
|
||||
static int seed_initialized = 0;
|
||||
static unsigned char seed[20]; /* The SHA1 seed, from /dev/urandom. */
|
||||
static uint64_t counter = 0; /* The counter we hash with the seed. */
|
||||
|
||||
if (!seed_initialized) {
|
||||
/* Initialize a seed and use SHA1 in counter mode, where we hash
|
||||
* the same seed with a progressive counter. For the goals of this
|
||||
* function we just need non-colliding strings, there are no
|
||||
* cryptographic security needs. */
|
||||
FILE *fp = fopen("/dev/urandom","r");
|
||||
if (fp && fread(seed,sizeof(seed),1,fp) == 1)
|
||||
seed_initialized = 1;
|
||||
if (fp) fclose(fp);
|
||||
}
|
||||
|
||||
if (seed_initialized) {
|
||||
while(len) {
|
||||
unsigned char digest[20];
|
||||
SHA1_CTX ctx;
|
||||
unsigned int copylen = len > 20 ? 20 : len;
|
||||
|
||||
SHA1Init(&ctx);
|
||||
SHA1Update(&ctx, seed, sizeof(seed));
|
||||
SHA1Update(&ctx, (unsigned char*)&counter,sizeof(counter));
|
||||
SHA1Final(digest, &ctx);
|
||||
counter++;
|
||||
|
||||
memcpy(p,digest,copylen);
|
||||
/* Convert to hex digits. */
|
||||
for (j = 0; j < copylen; j++) p[j] = charset[p[j] & 0x0F];
|
||||
len -= copylen;
|
||||
p += copylen;
|
||||
}
|
||||
} else {
|
||||
/* If we can't read from /dev/urandom, do some reasonable effort
|
||||
* in order to create some entropy, since this function is used to
|
||||
* generate run_id and cluster instance IDs */
|
||||
@@ -459,14 +506,12 @@ void getRandomHexChars(char *p, unsigned int len) {
|
||||
x += sizeof(pid);
|
||||
}
|
||||
/* Finally xor it with rand() output, that was already seeded with
|
||||
* time() at startup. */
|
||||
for (j = 0; j < len; j++)
|
||||
* time() at startup, and convert to hex digits. */
|
||||
for (j = 0; j < len; j++) {
|
||||
p[j] ^= rand();
|
||||
p[j] = charset[p[j] & 0x0F];
|
||||
}
|
||||
}
|
||||
/* Turn it into hex digits taking just 4 bits out of 8 for every byte. */
|
||||
for (j = 0; j < len; j++)
|
||||
p[j] = charset[p[j] & 0x0F];
|
||||
if (fp) fclose(fp);
|
||||
}
|
||||
|
||||
/* Given the filename, return the absolute path as an SDS string, or NULL
|
||||
|
||||
@@ -21,6 +21,7 @@ proc main {} {
|
||||
|
||||
if {[catch main e]} {
|
||||
puts $::errorInfo
|
||||
if {$::pause_on_error} pause_on_error
|
||||
cleanup
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -66,9 +66,18 @@ test "Cluster consistency during live resharding" {
|
||||
}
|
||||
|
||||
# Write random data to random list.
|
||||
set key "key:[randomInt $numkeys]"
|
||||
set listid [randomInt $numkeys]
|
||||
set key "key:$listid"
|
||||
set ele [randomValue]
|
||||
$cluster rpush $key $ele
|
||||
# We write both with Lua scripts and with plain commands.
|
||||
# This way we are able to stress Lua -> Redis command invocation
|
||||
# as well, that has tests to prevent Lua to write into wrong
|
||||
# hash slots.
|
||||
if {$listid % 2} {
|
||||
$cluster rpush $key $ele
|
||||
} else {
|
||||
$cluster eval {redis.call("rpush",KEYS[1],ARGV[1])} 1 $key $ele
|
||||
}
|
||||
lappend content($key) $ele
|
||||
|
||||
if {($j % 1000) == 0} {
|
||||
|
||||
@@ -27,10 +27,17 @@ test "Cluster nodes are reachable" {
|
||||
|
||||
test "Cluster nodes hard reset" {
|
||||
foreach_redis_id id {
|
||||
if {$::valgrind} {
|
||||
set node_timeout 10000
|
||||
} else {
|
||||
set node_timeout 3000
|
||||
}
|
||||
catch {R $id flushall} ; # May fail for readonly slaves.
|
||||
R $id MULTI
|
||||
R $id cluster reset hard
|
||||
R $id cluster set-config-epoch [expr {$id+1}]
|
||||
R $id config set cluster-node-timeout 3000
|
||||
R $id EXEC
|
||||
R $id config set cluster-node-timeout $node_timeout
|
||||
R $id config set cluster-slave-validity-factor 10
|
||||
R $id config rewrite
|
||||
}
|
||||
|
||||
+41
-14
@@ -16,6 +16,7 @@ source ../support/server.tcl
|
||||
source ../support/test.tcl
|
||||
|
||||
set ::verbose 0
|
||||
set ::valgrind 0
|
||||
set ::pause_on_error 0
|
||||
set ::simulate_error 0
|
||||
set ::sentinel_instances {}
|
||||
@@ -32,6 +33,25 @@ if {[catch {cd tmp}]} {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Execute the specified instance of the server specified by 'type', using
|
||||
# the provided configuration file. Returns the PID of the process.
|
||||
proc exec_instance {type cfgfile} {
|
||||
if {$type eq "redis"} {
|
||||
set prgname redis-server
|
||||
} elseif {$type eq "sentinel"} {
|
||||
set prgname redis-sentinel
|
||||
} else {
|
||||
error "Unknown instance type."
|
||||
}
|
||||
|
||||
if {$::valgrind} {
|
||||
set pid [exec valgrind --track-origins=yes --suppressions=../../../src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full ../../../src/${prgname} $cfgfile &]
|
||||
} else {
|
||||
set pid [exec ../../../src/${prgname} $cfgfile &]
|
||||
}
|
||||
return $pid
|
||||
}
|
||||
|
||||
# Spawn a redis or sentinel instance, depending on 'type'.
|
||||
proc spawn_instance {type base_port count {conf {}}} {
|
||||
for {set j 0} {$j < $count} {incr j} {
|
||||
@@ -58,14 +78,7 @@ proc spawn_instance {type base_port count {conf {}}} {
|
||||
close $cfg
|
||||
|
||||
# Finally exec it and remember the pid for later cleanup.
|
||||
if {$type eq "redis"} {
|
||||
set prgname redis-server
|
||||
} elseif {$type eq "sentinel"} {
|
||||
set prgname redis-sentinel
|
||||
} else {
|
||||
error "Unknown instance type."
|
||||
}
|
||||
set pid [exec ../../../src/${prgname} $cfgfile &]
|
||||
set pid [exec_instance $type $cfgfile]
|
||||
lappend ::pids $pid
|
||||
|
||||
# Check availability
|
||||
@@ -98,6 +111,7 @@ proc cleanup {} {
|
||||
proc abort_sentinel_test msg {
|
||||
puts "WARNING: Aborting the test."
|
||||
puts ">>>>>>>> $msg"
|
||||
if {$::pause_on_error} pause_on_error
|
||||
cleanup
|
||||
exit 1
|
||||
}
|
||||
@@ -113,6 +127,8 @@ proc parse_options {} {
|
||||
set ::pause_on_error 1
|
||||
} elseif {$opt eq "--fail"} {
|
||||
set ::simulate_error 1
|
||||
} elseif {$opt eq {--valgrind}} {
|
||||
set ::valgrind 1
|
||||
} elseif {$opt eq "--help"} {
|
||||
puts "Hello, I'm sentinel.tcl and I run Sentinel unit tests."
|
||||
puts "\nOptions:"
|
||||
@@ -360,15 +376,31 @@ proc get_instance_id_by_port {type port} {
|
||||
# The instance can be restarted with restart-instance.
|
||||
proc kill_instance {type id} {
|
||||
set pid [get_instance_attrib $type $id pid]
|
||||
set port [get_instance_attrib $type $id port]
|
||||
|
||||
if {$pid == -1} {
|
||||
error "You tried to kill $type $id twice."
|
||||
}
|
||||
|
||||
exec kill -9 $pid
|
||||
set_instance_attrib $type $id pid -1
|
||||
set_instance_attrib $type $id link you_tried_to_talk_with_killed_instance
|
||||
|
||||
# Remove the PID from the list of pids to kill at exit.
|
||||
set ::pids [lsearch -all -inline -not -exact $::pids $pid]
|
||||
|
||||
# Wait for the port it was using to be available again, so that's not
|
||||
# an issue to start a new server ASAP with the same port.
|
||||
set retry 10
|
||||
while {[incr retry -1]} {
|
||||
set port_is_free [catch {set s [socket 127.0.01 $port]}]
|
||||
if {$port_is_free} break
|
||||
catch {close $s}
|
||||
after 1000
|
||||
}
|
||||
if {$retry == 0} {
|
||||
error "Port $port does not return available after killing instance."
|
||||
}
|
||||
}
|
||||
|
||||
# Return true of the instance of the specified type/id is killed.
|
||||
@@ -385,12 +417,7 @@ proc restart_instance {type id} {
|
||||
|
||||
# Execute the instance with its old setup and append the new pid
|
||||
# file for cleanup.
|
||||
if {$type eq "redis"} {
|
||||
set prgname redis-server
|
||||
} else {
|
||||
set prgname redis-sentinel
|
||||
}
|
||||
set pid [exec ../../../src/${prgname} $cfgfile &]
|
||||
set pid [exec_instance $type $cfgfile]
|
||||
set_instance_attrib $type $id pid $pid
|
||||
lappend ::pids $pid
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ tags {"aof"} {
|
||||
}
|
||||
}
|
||||
|
||||
## Test that SPOP with <count> (that modifies the client's argc/argv) is correctly free'd
|
||||
## Uses the alsoPropagate() API.
|
||||
create_aof {
|
||||
append_to_aof [formatCommand sadd set foo]
|
||||
append_to_aof [formatCommand sadd set bar]
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
set server_path [tmpdir server.log]
|
||||
set system_name [string tolower [exec uname -s]]
|
||||
|
||||
if {$system_name eq {linux} || $system_name eq {darwin}} {
|
||||
start_server [list overrides [list dir $server_path]] {
|
||||
test "Server is able to generate a stack trace on selected systems" {
|
||||
r config set watchdog-period 200
|
||||
r debug sleep 1
|
||||
set pattern "*debugCommand*"
|
||||
set retry 10
|
||||
while {$retry} {
|
||||
set result [exec tail -100 < [srv 0 stdout]]
|
||||
if {[string match $pattern $result]} {
|
||||
break
|
||||
}
|
||||
incr retry -1
|
||||
after 1000
|
||||
}
|
||||
if {$retry == 0} {
|
||||
error "assertion:expected stack trace not found into log file"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ start_server_and_kill_it [list "dir" $server_path] {
|
||||
test {Server should not start if RDB is corrupted} {
|
||||
wait_for_condition 50 100 {
|
||||
[string match {*RDB checksum*} \
|
||||
[exec tail -n1 < [dict get $srv stdout]]]
|
||||
[exec tail -n10 < [dict get $srv stdout]]]
|
||||
} else {
|
||||
fail "Server started even if RDB was corrupted!"
|
||||
}
|
||||
|
||||
@@ -132,5 +132,24 @@ start_server {tags {"repl"}} {
|
||||
}
|
||||
assert {[$master dbsize] > 0}
|
||||
}
|
||||
|
||||
test {Replication of SPOP command -- alsoPropagate() API} {
|
||||
$master del myset
|
||||
set size [randomInt 100]
|
||||
set content {}
|
||||
for {set j 0} {$j < $size} {incr j} {
|
||||
lappend content [randomValue]
|
||||
}
|
||||
$master sadd myset {*}$content
|
||||
|
||||
set count [randomInt 100]
|
||||
set result [$master spop myset $count]
|
||||
|
||||
wait_for_condition 50 100 {
|
||||
[$master debug digest] eq [$slave debug digest]
|
||||
} else {
|
||||
fail "SPOP replication inconsistency"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +226,8 @@ proc ::redis_cluster::get_keys_from_command {cmd argv} {
|
||||
# Special handling for other commands
|
||||
switch -exact $cmd {
|
||||
mget {return $argv}
|
||||
eval {return [lrange $argv 2 1+[lindex $argv 1]]}
|
||||
evalsha {return [lrange $argv 2 1+[lindex $argv 1]]}
|
||||
}
|
||||
|
||||
# All the remaining commands are not handled.
|
||||
|
||||
@@ -207,7 +207,7 @@ proc start_server {options {code undefined}} {
|
||||
set stderr [format "%s/%s" [dict get $config "dir"] "stderr"]
|
||||
|
||||
if {$::valgrind} {
|
||||
set pid [exec valgrind --suppressions=src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full src/redis-server $config_file > $stdout 2> $stderr &]
|
||||
set pid [exec valgrind --track-origins=yes --suppressions=src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full src/redis-server $config_file > $stdout 2> $stderr &]
|
||||
} else {
|
||||
set pid [exec src/redis-server $config_file > $stdout 2> $stderr &]
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ set ::all_tests {
|
||||
integration/aof
|
||||
integration/rdb
|
||||
integration/convert-zipmap-hash-on-load
|
||||
integration/logging
|
||||
unit/pubsub
|
||||
unit/slowlog
|
||||
unit/scripting
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
proc test_memory_efficiency {range} {
|
||||
r flushall
|
||||
set rd [redis_deferring_client]
|
||||
set base_mem [s used_memory]
|
||||
set written 0
|
||||
for {set j 0} {$j < 10000} {incr j} {
|
||||
set key key:$j
|
||||
set val [string repeat A [expr {int(rand()*$range)}]]
|
||||
r set $key $val
|
||||
$rd set $key $val
|
||||
incr written [string length $key]
|
||||
incr written [string length $val]
|
||||
incr written 2 ;# A separator is the minimum to store key-value data.
|
||||
}
|
||||
for {set j 0} {$j < 10000} {incr j} {
|
||||
$rd read ; # Discard replies
|
||||
}
|
||||
|
||||
set current_mem [s used_memory]
|
||||
set used [expr {$current_mem-$base_mem}]
|
||||
set efficiency [expr {double($written)/$used}]
|
||||
|
||||
@@ -346,6 +346,33 @@ start_server {
|
||||
r spop nonexisting_key 100
|
||||
} {}
|
||||
|
||||
test "SPOP new implementation: code path #1" {
|
||||
set content {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
|
||||
create_set myset $content
|
||||
set res [r spop myset 30]
|
||||
assert {[lsort $content] eq [lsort $res]}
|
||||
}
|
||||
|
||||
test "SPOP new implementation: code path #2" {
|
||||
set content {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
|
||||
create_set myset $content
|
||||
set res [r spop myset 2]
|
||||
assert {[llength $res] == 2}
|
||||
assert {[r scard myset] == 18}
|
||||
set union [concat [r smembers myset] $res]
|
||||
assert {[lsort $union] eq [lsort $content]}
|
||||
}
|
||||
|
||||
test "SPOP new implementation: code path #3" {
|
||||
set content {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
|
||||
create_set myset $content
|
||||
set res [r spop myset 18]
|
||||
assert {[llength $res] == 18}
|
||||
assert {[r scard myset] == 2}
|
||||
set union [concat [r smembers myset] $res]
|
||||
assert {[lsort $union] eq [lsort $content]}
|
||||
}
|
||||
|
||||
test "SRANDMEMBER with <count> against non existing key" {
|
||||
r srandmember nonexisting_key 100
|
||||
} {}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# This simple script is used in order to estimate the average PFAIL->FAIL
|
||||
# state switch after a failure.
|
||||
|
||||
set ::sleep_time 10 ; # How much to sleep to trigger PFAIL.
|
||||
set ::fail_port 30016 ; # Node to put in sleep.
|
||||
set ::other_port 30001 ; # Node to use to monitor the flag switch.
|
||||
|
||||
proc avg vector {
|
||||
set sum 0.0
|
||||
foreach x $vector {
|
||||
set sum [expr {$sum+$x}]
|
||||
}
|
||||
expr {$sum/[llength $vector]}
|
||||
}
|
||||
|
||||
set samples {}
|
||||
while 1 {
|
||||
exec redis-cli -p $::fail_port debug sleep $::sleep_time > /dev/null &
|
||||
|
||||
# Wait for fail? to appear.
|
||||
while 1 {
|
||||
set output [exec redis-cli -p $::other_port cluster nodes]
|
||||
if {[string match {*fail\?*} $output]} break
|
||||
after 100
|
||||
}
|
||||
|
||||
puts "FAIL?"
|
||||
set start [clock milliseconds]
|
||||
|
||||
# Wait for fail? to disappear.
|
||||
while 1 {
|
||||
set output [exec redis-cli -p $::other_port cluster nodes]
|
||||
if {![string match {*fail\?*} $output]} break
|
||||
after 100
|
||||
}
|
||||
|
||||
puts "FAIL"
|
||||
set now [clock milliseconds]
|
||||
set elapsed [expr {$now-$start}]
|
||||
puts $elapsed
|
||||
lappend samples $elapsed
|
||||
|
||||
puts "AVG([llength $samples]): [avg $samples]"
|
||||
|
||||
# Wait for the instance to be available again.
|
||||
exec redis-cli -p $::fail_port ping
|
||||
|
||||
# Wait for the fail flag to be cleared.
|
||||
after 2000
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
config.sh
|
||||
@@ -0,0 +1,27 @@
|
||||
Create-custer is a small script used to easily start a big number of Redis
|
||||
instances configured to run in cluster mode. Its main goal is to allow manual
|
||||
testing in a condition which is not easy to replicate with the Redis cluster
|
||||
unit tests, for example when a lot of instances are needed in order to trigger
|
||||
a give bug.
|
||||
|
||||
The tool can also be used just to easily create a number of instances in a
|
||||
Redis Cluster in order to experiment a bit with the system.
|
||||
|
||||
USAGE
|
||||
---
|
||||
|
||||
To create a cluster, follow this steps:
|
||||
|
||||
1. Edit create-cluster and change the start / end port, depending on the
|
||||
number of instances you want to create.
|
||||
2. Use "./create-cluster start" in order to run the instances.
|
||||
3. Use "./create-cluster create" in order to execute redis-trib create, so that
|
||||
an actual Redis cluster will be created.
|
||||
4. Now you are ready to play with the cluster. AOF files and logs for each instances are created in the current directory.
|
||||
|
||||
In order to stop a cluster:
|
||||
|
||||
1. Use "./craete-cluster stop" to stop all the instances. After you stopped the instances you can use "./create-cluster start" to restart them if you change ideas.
|
||||
2. Use "./create-cluster clean" to remove all the AOF / log files to restat with a clean environment.
|
||||
|
||||
Use the command "./create-cluster help" to get the full list of features.
|
||||
Executable
+95
@@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Settings
|
||||
PORT=30000
|
||||
TIMEOUT=2000
|
||||
NODES=6
|
||||
REPLICAS=1
|
||||
|
||||
# You may want to put the above config parameters into config.sh in order to
|
||||
# override the defaults without modifying this script.
|
||||
|
||||
if [ -a config.sh ]
|
||||
then
|
||||
source "config.sh"
|
||||
fi
|
||||
|
||||
# Computed vars
|
||||
ENDPORT=$((PORT+NODES))
|
||||
|
||||
if [ "$1" == "start" ]
|
||||
then
|
||||
while [ $((PORT < ENDPORT)) != "0" ]; do
|
||||
PORT=$((PORT+1))
|
||||
echo "Starting $PORT"
|
||||
../../src/redis-server --port $PORT --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" == "create" ]
|
||||
then
|
||||
HOSTS=""
|
||||
while [ $((PORT < ENDPORT)) != "0" ]; do
|
||||
PORT=$((PORT+1))
|
||||
HOSTS="$HOSTS 127.0.0.1:$PORT"
|
||||
done
|
||||
../../src/redis-trib.rb create --replicas $REPLICAS $HOSTS
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" == "stop" ]
|
||||
then
|
||||
while [ $((PORT < ENDPORT)) != "0" ]; do
|
||||
PORT=$((PORT+1))
|
||||
echo "Stopping $PORT"
|
||||
redis-cli -p $PORT shutdown nosave
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" == "watch" ]
|
||||
then
|
||||
PORT=$((PORT+1))
|
||||
while [ 1 ]; do
|
||||
clear
|
||||
date
|
||||
redis-cli -p $PORT cluster nodes | head -30
|
||||
sleep 1
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" == "tail" ]
|
||||
then
|
||||
INSTANCE=$2
|
||||
PORT=$((PORT+INSTANCE))
|
||||
tail -f ${PORT}.log
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" == "call" ]
|
||||
then
|
||||
while [ $((PORT < ENDPORT)) != "0" ]; do
|
||||
PORT=$((PORT+1))
|
||||
../../src/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" == "clean" ]
|
||||
then
|
||||
rm -rf *.log
|
||||
rm -rf appendonly*.aof
|
||||
rm -rf dump*.rdb
|
||||
rm -rf nodes*.conf
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Usage: $0 [start|create|stop|watch|tail|clean]"
|
||||
echo "start -- Launch Redis Cluster instances."
|
||||
echo "create -- Create a cluster using redis-trib create."
|
||||
echo "stop -- Stop Redis Cluster instances."
|
||||
echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node."
|
||||
echo "tail <id> -- Run tail -f of instance at base port + ID."
|
||||
echo "clean -- Remove all instances data, logs, configs."
|
||||
@@ -0,0 +1,13 @@
|
||||
Hash table implementation related utilities.
|
||||
|
||||
rehashing.c
|
||||
---
|
||||
|
||||
Visually show buckets in the two hash tables between rehashings. Also stress
|
||||
test getRandomKeys() implementation, that may actually disappear from
|
||||
Redis soon, however visualizaiton some code is reusable in new bugs
|
||||
investigation.
|
||||
|
||||
Compile with:
|
||||
|
||||
cc -I ../../src/ rehashing.c ../../src/zmalloc.c ../../src/dict.c -o rehashing_test
|
||||
@@ -0,0 +1,132 @@
|
||||
#include "redis.h"
|
||||
#include "dict.h"
|
||||
|
||||
void _redisAssert(char *x, char *y, int l) {
|
||||
printf("ASSERT: %s %s %d\n",x,y,l);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unsigned int dictKeyHash(const void *keyp) {
|
||||
unsigned long key = (unsigned long)keyp;
|
||||
key = dictGenHashFunction(&key,sizeof(key));
|
||||
key += ~(key << 15);
|
||||
key ^= (key >> 10);
|
||||
key += (key << 3);
|
||||
key ^= (key >> 6);
|
||||
key += ~(key << 11);
|
||||
key ^= (key >> 16);
|
||||
return key;
|
||||
}
|
||||
|
||||
int dictKeyCompare(void *privdata, const void *key1, const void *key2) {
|
||||
unsigned long k1 = (unsigned long)key1;
|
||||
unsigned long k2 = (unsigned long)key2;
|
||||
return k1 == k2;
|
||||
}
|
||||
|
||||
dictType dictTypeTest = {
|
||||
dictKeyHash, /* hash function */
|
||||
NULL, /* key dup */
|
||||
NULL, /* val dup */
|
||||
dictKeyCompare, /* key compare */
|
||||
NULL, /* key destructor */
|
||||
NULL /* val destructor */
|
||||
};
|
||||
|
||||
void showBuckets(dictht ht) {
|
||||
if (ht.table == NULL) {
|
||||
printf("NULL\n");
|
||||
} else {
|
||||
int j;
|
||||
for (j = 0; j < ht.size; j++) {
|
||||
printf("%c", ht.table[j] ? '1' : '0');
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void show(dict *d) {
|
||||
int j;
|
||||
if (d->rehashidx != -1) {
|
||||
printf("rhidx: ");
|
||||
for (j = 0; j < d->rehashidx; j++)
|
||||
printf(".");
|
||||
printf("|\n");
|
||||
}
|
||||
printf("ht[0]: ");
|
||||
showBuckets(d->ht[0]);
|
||||
printf("ht[1]: ");
|
||||
showBuckets(d->ht[1]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int sortPointers(const void *a, const void *b) {
|
||||
unsigned long la, lb;
|
||||
|
||||
la = (long) (*((dictEntry**)a));
|
||||
lb = (long) (*((dictEntry**)b));
|
||||
return la-lb;
|
||||
}
|
||||
|
||||
void stressGetKeys(dict *d, int times) {
|
||||
int j;
|
||||
dictEntry **des = zmalloc(sizeof(dictEntry*)*dictSize(d));
|
||||
for (j = 0; j < times; j++) {
|
||||
int requested = rand() % (dictSize(d)+1);
|
||||
int returned = dictGetRandomKeys(d, des, requested);
|
||||
if (requested != returned) {
|
||||
printf("*** ERROR! Req: %d, Ret: %d\n", requested, returned);
|
||||
exit(1);
|
||||
}
|
||||
qsort(des,returned,sizeof(dictEntry*),sortPointers);
|
||||
if (returned > 1) {
|
||||
int i;
|
||||
for (i = 0; i < returned-1; i++) {
|
||||
if (des[i] == des[i+1]) {
|
||||
printf("*** ERROR! Duplicated element detected\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
zfree(des);
|
||||
}
|
||||
|
||||
#define MAX1 120
|
||||
#define MAX2 1000
|
||||
int main(void) {
|
||||
dict *d = dictCreate(&dictTypeTest,NULL);
|
||||
unsigned long i;
|
||||
srand(time(NULL));
|
||||
|
||||
for (i = 0; i < MAX1; i++) {
|
||||
dictAdd(d,(void*)i,NULL);
|
||||
show(d);
|
||||
}
|
||||
printf("Size: %d\n", (int)dictSize(d));
|
||||
|
||||
for (i = 0; i < MAX1; i++) {
|
||||
dictDelete(d,(void*)i);
|
||||
dictResize(d);
|
||||
show(d);
|
||||
}
|
||||
dictRelease(d);
|
||||
|
||||
d = dictCreate(&dictTypeTest,NULL);
|
||||
printf("Getkeys stress test\n");
|
||||
|
||||
for (i = 0; i < MAX2; i++) {
|
||||
dictAdd(d,(void*)i,NULL);
|
||||
stressGetKeys(d,100);
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX2; i++) {
|
||||
dictDelete(d,(void*)i);
|
||||
dictResize(d);
|
||||
stressGetKeys(d,100);
|
||||
}
|
||||
dictRelease(d);
|
||||
|
||||
printf("TEST PASSED!\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user