Skip to content

Commit 15b1f40

Browse files
committed
Merge remote-tracking branch 'upstream/2.4' into 2.4
2 parents d0ac0c5 + 18fe946 commit 15b1f40

File tree

7 files changed

+62
-10
lines changed

7 files changed

+62
-10
lines changed

redis.conf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ port 6379
3737
# unixsocketperm 755
3838

3939
# Close the connection after a client is idle for N seconds (0 to disable)
40-
timeout 300
40+
timeout 0
4141

4242
# Set server verbosity to 'debug'
4343
# it can be one of:
@@ -135,6 +135,21 @@ dir ./
135135
#
136136
slave-serve-stale-data yes
137137

138+
# Slaves send PINGs to server in a predefined interval. It's possible to change
139+
# this interval with the repl_ping_slave_period option. The default value is 10
140+
# seconds.
141+
#
142+
# repl-ping-slave-period 10
143+
144+
# The following option sets a timeout for both Bulk transfer I/O timeout and
145+
# master data or ping response timeout. The default value is 60 seconds.
146+
#
147+
# It is important to make sure that this value is greater than the value
148+
# specified for repl-ping-slave-period otherwise a timeout will be detected
149+
# every time there is low traffic between the master and the slave.
150+
#
151+
# repl-timeout 60
152+
138153
################################## SECURITY ###################################
139154

140155
# Require clients to issue AUTH <PASSWORD> before processing any other

src/config.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,18 @@ void loadServerConfig(char *filename) {
209209
server.masterhost = sdsnew(argv[1]);
210210
server.masterport = atoi(argv[2]);
211211
server.replstate = REDIS_REPL_CONNECT;
212+
} else if (!strcasecmp(argv[0],"repl-ping-slave-period") && argc == 2) {
213+
server.repl_ping_slave_period = atoi(argv[1]);
214+
if (server.repl_ping_slave_period <= 0) {
215+
err = "repl-ping-slave-period must be 1 or greater";
216+
goto loaderr;
217+
}
218+
} else if (!strcasecmp(argv[0],"repl-timeout") && argc == 2) {
219+
server.repl_timeout = atoi(argv[1]);
220+
if (server.repl_timeout <= 0) {
221+
err = "repl-timeout must be 1 or greater";
222+
goto loaderr;
223+
}
212224
} else if (!strcasecmp(argv[0],"masterauth") && argc == 2) {
213225
server.masterauth = zstrdup(argv[1]);
214226
} else if (!strcasecmp(argv[0],"slave-serve-stale-data") && argc == 2) {
@@ -380,7 +392,7 @@ void configSetCommand(redisClient *c) {
380392
server.dbfilename = zstrdup(o->ptr);
381393
} else if (!strcasecmp(c->argv[2]->ptr,"requirepass")) {
382394
zfree(server.requirepass);
383-
server.requirepass = zstrdup(o->ptr);
395+
server.requirepass = ((char*)o->ptr)[0] ? zstrdup(o->ptr) : NULL;
384396
} else if (!strcasecmp(c->argv[2]->ptr,"masterauth")) {
385397
zfree(server.masterauth);
386398
server.masterauth = zstrdup(o->ptr);

src/redis-cli.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ static void repl() {
690690

691691
if (argv == NULL) {
692692
printf("Invalid argument(s)\n");
693+
free(line);
693694
continue;
694695
} else if (argc > 0) {
695696
if (strcasecmp(argv[0],"quit") == 0 ||

src/redis.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ void initServerConfig() {
905905
server.zset_max_ziplist_entries = REDIS_ZSET_MAX_ZIPLIST_ENTRIES;
906906
server.zset_max_ziplist_value = REDIS_ZSET_MAX_ZIPLIST_VALUE;
907907
server.shutdown_asap = 0;
908+
server.repl_ping_slave_period = REDIS_REPL_PING_SLAVE_PERIOD;
909+
server.repl_timeout = REDIS_REPL_TIMEOUT;
908910

909911
updateLRUClock();
910912
resetServerSaveParams();

src/redis.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
#define REDIS_SLOWLOG_LOG_SLOWER_THAN 10000
6161
#define REDIS_SLOWLOG_MAX_LEN 64
6262

63+
#define REDIS_REPL_TIMEOUT 60
64+
#define REDIS_REPL_PING_SLAVE_PERIOD 10
65+
6366
/* Hash table parameters */
6467
#define REDIS_HT_MINFILL 10 /* Minimal hash table fill 10% */
6568

@@ -475,6 +478,8 @@ struct redisServer {
475478
char *masterauth;
476479
char *masterhost;
477480
int masterport;
481+
int repl_ping_slave_period;
482+
int repl_timeout;
478483
redisClient *master; /* client that is master for this slave */
479484
int repl_syncio_timeout; /* timeout for synchronous I/O calls */
480485
int replstate; /* replication status if the instance is a slave */

src/replication.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,21 +621,18 @@ void slaveofCommand(redisClient *c) {
621621

622622
/* --------------------------- REPLICATION CRON ---------------------------- */
623623

624-
#define REDIS_REPL_TIMEOUT 60
625-
#define REDIS_REPL_PING_SLAVE_PERIOD 10
626-
627624
void replicationCron(void) {
628625
/* Bulk transfer I/O timeout? */
629626
if (server.masterhost && server.replstate == REDIS_REPL_TRANSFER &&
630-
(time(NULL)-server.repl_transfer_lastio) > REDIS_REPL_TIMEOUT)
627+
(time(NULL)-server.repl_transfer_lastio) > server.repl_timeout)
631628
{
632629
redisLog(REDIS_WARNING,"Timeout receiving bulk data from MASTER...");
633630
replicationAbortSyncTransfer();
634631
}
635632

636633
/* Timed out master when we are an already connected slave? */
637634
if (server.masterhost && server.replstate == REDIS_REPL_CONNECTED &&
638-
(time(NULL)-server.master->lastinteraction) > REDIS_REPL_TIMEOUT)
635+
(time(NULL)-server.master->lastinteraction) > server.repl_timeout)
639636
{
640637
redisLog(REDIS_WARNING,"MASTER time out: no data nor PING received...");
641638
freeClient(server.master);
@@ -653,7 +650,7 @@ void replicationCron(void) {
653650
* So slaves can implement an explicit timeout to masters, and will
654651
* be able to detect a link disconnection even if the TCP connection
655652
* will not actually go down. */
656-
if (!(server.cronloops % (REDIS_REPL_PING_SLAVE_PERIOD*10))) {
653+
if (!(server.cronloops % (server.repl_ping_slave_period*10))) {
657654
listIter li;
658655
listNode *ln;
659656

src/sds.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ sds *sdssplitargs(char *line, int *argc) {
478478
while(*p && isspace(*p)) p++;
479479
if (*p) {
480480
/* get a token */
481-
int inq=0; /* set to 1 if we are in "quotes" */
481+
int inq=0; /* set to 1 if we are in "quotes" */
482+
int insq=0; /* set to 1 if we are in 'single quotes' */
482483
int done=0;
483484

484485
if (current == NULL) current = sdsempty();
@@ -508,7 +509,23 @@ sds *sdssplitargs(char *line, int *argc) {
508509
}
509510
current = sdscatlen(current,&c,1);
510511
} else if (*p == '"') {
511-
/* closing quote must be followed by a space */
512+
/* closing quote must be followed by a space or
513+
* nothing at all. */
514+
if (*(p+1) && !isspace(*(p+1))) goto err;
515+
done=1;
516+
} else if (!*p) {
517+
/* unterminated quotes */
518+
goto err;
519+
} else {
520+
current = sdscatlen(current,p,1);
521+
}
522+
} else if (insq) {
523+
if (*p == '\\' && *(p+1) == '\'') {
524+
p++;
525+
current = sdscatlen(current,"'",1);
526+
} else if (*p == '\'') {
527+
/* closing quote must be followed by a space or
528+
* nothing at all. */
512529
if (*(p+1) && !isspace(*(p+1))) goto err;
513530
done=1;
514531
} else if (!*p) {
@@ -529,6 +546,9 @@ sds *sdssplitargs(char *line, int *argc) {
529546
case '"':
530547
inq=1;
531548
break;
549+
case '\'':
550+
insq=1;
551+
break;
532552
default:
533553
current = sdscatlen(current,p,1);
534554
break;

0 commit comments

Comments
 (0)