mirror of
https://github.com/fluencelabs/redis
synced 2025-06-20 20:46:31 +00:00
Refuse writes if can't persist on disk.
Redis now refuses accepting write queries if RDB persistence is configured, but RDB snapshots can't be generated for some reason. The status of the latest background save operation is now exposed in the INFO output as well. This fixes issue #90.
This commit is contained in:
13
src/redis.c
13
src/redis.c
@ -833,6 +833,8 @@ void createSharedObjects(void) {
|
||||
"-LOADING Redis is loading the dataset in memory\r\n"));
|
||||
shared.slowscripterr = createObject(REDIS_STRING,sdsnew(
|
||||
"-BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.\r\n"));
|
||||
shared.bgsaveerr = createObject(REDIS_STRING,sdsnew(
|
||||
"-MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Write commands are disabled. Please check Redis logs for details about the error.\r\n"));
|
||||
shared.space = createObject(REDIS_STRING,sdsnew(" "));
|
||||
shared.colon = createObject(REDIS_STRING,sdsnew(":"));
|
||||
shared.plus = createObject(REDIS_STRING,sdsnew("+"));
|
||||
@ -1088,6 +1090,7 @@ void initServer() {
|
||||
server.stat_fork_time = 0;
|
||||
server.stat_rejected_conn = 0;
|
||||
server.unixtime = time(NULL);
|
||||
server.lastbgsave_status = REDIS_OK;
|
||||
aeCreateTimeEvent(server.el, 1, serverCron, NULL, NULL);
|
||||
if (server.ipfd > 0 && aeCreateFileEvent(server.el,server.ipfd,AE_READABLE,
|
||||
acceptTcpHandler,NULL) == AE_ERR) oom("creating file event");
|
||||
@ -1374,6 +1377,14 @@ int processCommand(redisClient *c) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Don't accept write commands if there are problems persisting on disk. */
|
||||
if (server.saveparamslen > 0 && server.lastbgsave_status == REDIS_ERR &&
|
||||
c->cmd->flags & REDIS_CMD_WRITE)
|
||||
{
|
||||
addReply(c, shared.bgsaveerr);
|
||||
return REDIS_OK;
|
||||
}
|
||||
|
||||
/* Only allow SUBSCRIBE and UNSUBSCRIBE in the context of Pub/Sub */
|
||||
if ((dictSize(c->pubsub_channels) > 0 || listLength(c->pubsub_patterns) > 0)
|
||||
&&
|
||||
@ -1645,12 +1656,14 @@ sds genRedisInfoString(char *section) {
|
||||
"changes_since_last_save:%lld\r\n"
|
||||
"bgsave_in_progress:%d\r\n"
|
||||
"last_save_time:%ld\r\n"
|
||||
"last_bgsave_status:%s\r\n"
|
||||
"bgrewriteaof_in_progress:%d\r\n",
|
||||
server.loading,
|
||||
server.aof_state != REDIS_AOF_OFF,
|
||||
server.dirty,
|
||||
server.rdb_child_pid != -1,
|
||||
server.lastsave,
|
||||
server.lastbgsave_status == REDIS_OK ? "ok" : "err",
|
||||
server.aof_child_pid != -1);
|
||||
|
||||
if (server.aof_state != REDIS_AOF_OFF) {
|
||||
|
Reference in New Issue
Block a user