int rdbSaveBackground(char *filename) {
pid_t childpid;
+ long long start;
if (server.bgsavechildpid != -1 ||
server.bgsavethread != (pthread_t) -1) return REDIS_ERR;
return dsRdbSaveBackground(filename);
}
+ start = ustime();
if ((childpid = fork()) == 0) {
int retval;
_exit((retval == REDIS_OK) ? 0 : 1);
} else {
/* Parent */
+ server.stat_fork_time = ustime()-start;
if (childpid == -1) {
redisLog(REDIS_WARNING,"Can't save in background: fork: %s",
strerror(errno));
void bgsaveCommand(redisClient *c) {
if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread_t)-1) {
addReplyError(c,"Background save already in progress");
- return;
- }
- if (rdbSaveBackground(server.dbfilename) == REDIS_OK) {
+ } else if (server.bgrewritechildpid != -1) {
+ addReplyError(c,"Can't BGSAVE while AOF log rewriting is in progress");
+ } else if (rdbSaveBackground(server.dbfilename) == REDIS_OK) {
addReplyStatus(c,"Background saving started");
} else {
addReply(c,shared.err);