Permalink
Browse files

reject mutable operation when slave readonly mode

  • Loading branch information...
Chris Song
Chris Song committed Mar 21, 2011
1 parent 1dd4756 commit 67b319eddcf98cfdf0a7fc183d14a77e8e7df03d
Showing with 12 additions and 0 deletions.
  1. +4 −0 src/config.c
  2. +7 −0 src/redis.c
  3. +1 −0 src/redis.h
View
@@ -208,6 +208,10 @@ void loadServerConfig(char *filename) {
if ((server.daemonize = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
+ } else if (!strcasecmp(argv[0],"slave-readonly") && argc == 2) {
+ if ((server.slave_readonly= yesnotoi(argv[1])) == -1) {
+ err = "argument must be 'yes' or 'no'"; goto loaderr;
+ }
} else if (!strcasecmp(argv[0],"appendonly") && argc == 2) {
if ((server.appendonly = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
View
@@ -795,6 +795,7 @@ void initServerConfig() {
server.syslog_ident = zstrdup("redis");
server.syslog_facility = LOG_LOCAL0;
server.daemonize = 0;
+ server.slave_readonly = 0;
server.appendonly = 0;
server.appendfsync = APPENDFSYNC_EVERYSEC;
server.no_appendfsync_on_rewrite = 0;
@@ -1051,6 +1052,12 @@ int processCommand(redisClient *c) {
return REDIS_OK;
}
+ /* Check readonly flag */
+ if (server.slave_readonly && (c->flags & REDIS_MASTER || c->flags & REDIS_SLAVE) && (cmd->flags & REDIS_CMD_IS_MUTABLE)) {
+ addReplyError(c,"operation is mutable, not permitted");
+ return REDIS_OK;
+ }
+
/* Handle the maxmemory directive.
*
* First we try to free some memory if possible (if there are volatile
View
@@ -404,6 +404,7 @@ struct redisServer {
int no_appendfsync_on_rewrite;
int shutdown_asap;
int activerehashing;
+ int slave_readonly;
char *requirepass;
/* Persistence */
long long dirty; /* changes to DB from the last save */

1 comment on commit 67b319e

@jokea

This comment has been minimized.

Show comment Hide comment
@jokea

jokea Nov 1, 2011

if (server.slave_readonly && (c->flags & REDIS_MASTER || c->flags & REDIS_SLAVE) && (cmd->flags & REDIS_CMD_IS_MUTABLE)) {
should be:
if (server.slave_readonly && (server.masterhost != NULL) && (!(c->flags & REDIS_MASTER)) && (cmd->flags & REDIS_CMD_IS_MUTABLE)) {

jokea commented on 67b319e Nov 1, 2011

if (server.slave_readonly && (c->flags & REDIS_MASTER || c->flags & REDIS_SLAVE) && (cmd->flags & REDIS_CMD_IS_MUTABLE)) {
should be:
if (server.slave_readonly && (server.masterhost != NULL) && (!(c->flags & REDIS_MASTER)) && (cmd->flags & REDIS_CMD_IS_MUTABLE)) {

Please sign in to comment.