/* Don't fsync if no-appendfsync-on-rewrite is set to yes and there are
* children doing I/O in the background. */
if (server.aof_no_fsync_on_rewrite &&
- (server.aof_child_pid != -1 || server.bgsavechildpid != -1))
+ (server.aof_child_pid != -1 || server.rdb_child_pid != -1))
return;
/* Perform the fsync if needed. */
void bgrewriteaofCommand(redisClient *c) {
if (server.aof_child_pid != -1) {
addReplyError(c,"Background append only file rewriting already in progress");
- } else if (server.bgsavechildpid != -1) {
+ } else if (server.rdb_child_pid != -1) {
server.aof_rewrite_scheduled = 1;
addReplyStatus(c,"Background append only file rewriting scheduled");
} else if (rewriteAppendOnlyFileBackground() == REDIS_OK) {
} else if (!strcasecmp(argv[0],"glueoutputbuf")) {
redisLog(REDIS_WARNING, "Deprecated configuration directive: \"%s\"", argv[0]);
} else if (!strcasecmp(argv[0],"rdbcompression") && argc == 2) {
- if ((server.rdbcompression = yesnotoi(argv[1])) == -1) {
+ if ((server.rdb_compression = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"activerehashing") && argc == 2) {
zfree(server.pidfile);
server.pidfile = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"dbfilename") && argc == 2) {
- zfree(server.dbfilename);
- server.dbfilename = zstrdup(argv[1]);
+ zfree(server.rdb_filename);
+ server.rdb_filename = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"hash-max-zipmap-entries") && argc == 2) {
server.hash_max_zipmap_entries = memtoll(argv[1], NULL);
} else if (!strcasecmp(argv[0],"hash-max-zipmap-value") && argc == 2) {
o = c->argv[3];
if (!strcasecmp(c->argv[2]->ptr,"dbfilename")) {
- zfree(server.dbfilename);
- server.dbfilename = zstrdup(o->ptr);
+ zfree(server.rdb_filename);
+ server.rdb_filename = zstrdup(o->ptr);
} else if (!strcasecmp(c->argv[2]->ptr,"requirepass")) {
zfree(server.requirepass);
server.requirepass = ((char*)o->ptr)[0] ? zstrdup(o->ptr) : NULL;
}
if (stringmatch(pattern,"dbfilename",0)) {
addReplyBulkCString(c,"dbfilename");
- addReplyBulkCString(c,server.dbfilename);
+ addReplyBulkCString(c,server.rdb_filename);
matches++;
}
if (stringmatch(pattern,"requirepass",0)) {
/* Update the access time for the aging algorithm.
* Don't do it if we have a saving child, as this will trigger
* a copy on write madness. */
- if (server.bgsavechildpid == -1 && server.aof_child_pid == -1)
+ if (server.rdb_child_pid == -1 && server.aof_child_pid == -1)
val->lru = server.lruclock;
server.stat_keyspace_hits++;
return val;
signalFlushedDb(-1);
server.dirty += emptyDb();
addReply(c,shared.ok);
- if (server.bgsavechildpid != -1) {
- kill(server.bgsavechildpid,SIGKILL);
- rdbRemoveTempFile(server.bgsavechildpid);
+ if (server.rdb_child_pid != -1) {
+ kill(server.rdb_child_pid,SIGKILL);
+ rdbRemoveTempFile(server.rdb_child_pid);
}
if (server.saveparamslen > 0) {
/* Normally rdbSave() will reset dirty, but we don't want this here
* as otherwise FLUSHALL will not be replicated nor put into the AOF. */
int saved_dirty = server.dirty;
- rdbSave(server.dbfilename);
+ rdbSave(server.rdb_filename);
server.dirty = saved_dirty;
}
server.dirty++;
if (c->argc >= 3) c->argv[2] = tryObjectEncoding(c->argv[2]);
redisAssertWithInfo(c,c->argv[0],1 == 2);
} else if (!strcasecmp(c->argv[1]->ptr,"reload")) {
- if (rdbSave(server.dbfilename) != REDIS_OK) {
+ if (rdbSave(server.rdb_filename) != REDIS_OK) {
addReply(c,shared.err);
return;
}
emptyDb();
- if (rdbLoad(server.dbfilename) != REDIS_OK) {
+ if (rdbLoad(server.rdb_filename) != REDIS_OK) {
addReplyError(c,"Error trying to load the RDB dump");
return;
}
/* Try LZF compression - under 20 bytes it's unable to compress even
* aaaaaaaaaaaaaaaaaa so skip it */
- if (server.rdbcompression && len > 20) {
+ if (server.rdb_compression && len > 20) {
n = rdbSaveLzfStringObject(rdb,s,len);
if (n == -1) return -1;
if (n > 0) return n;
pid_t childpid;
long long start;
- if (server.bgsavechildpid != -1) return REDIS_ERR;
+ if (server.rdb_child_pid != -1) return REDIS_ERR;
server.dirty_before_bgsave = server.dirty;
return REDIS_ERR;
}
redisLog(REDIS_NOTICE,"Background saving started by pid %d",childpid);
- server.bgsavechildpid = childpid;
+ server.rdb_child_pid = childpid;
updateDictResizePolicy();
return REDIS_OK;
}
} else {
redisLog(REDIS_WARNING,
"Background saving terminated by signal %d", bysignal);
- rdbRemoveTempFile(server.bgsavechildpid);
+ rdbRemoveTempFile(server.rdb_child_pid);
}
- server.bgsavechildpid = -1;
+ server.rdb_child_pid = -1;
/* Possibly there are slaves waiting for a BGSAVE in order to be served
* (the first stage of SYNC is a bulk transfer of dump.rdb) */
updateSlavesWaitingBgsave(exitcode == 0 ? REDIS_OK : REDIS_ERR);
}
void saveCommand(redisClient *c) {
- if (server.bgsavechildpid != -1) {
+ if (server.rdb_child_pid != -1) {
addReplyError(c,"Background save already in progress");
return;
}
- if (rdbSave(server.dbfilename) == REDIS_OK) {
+ if (rdbSave(server.rdb_filename) == REDIS_OK) {
addReply(c,shared.ok);
} else {
addReply(c,shared.err);
}
void bgsaveCommand(redisClient *c) {
- if (server.bgsavechildpid != -1) {
+ if (server.rdb_child_pid != -1) {
addReplyError(c,"Background save already in progress");
} else if (server.aof_child_pid != -1) {
addReplyError(c,"Can't BGSAVE while AOF log rewriting is in progress");
- } else if (rdbSaveBackground(server.dbfilename) == REDIS_OK) {
+ } else if (rdbSaveBackground(server.rdb_filename) == REDIS_OK) {
addReplyStatus(c,"Background saving started");
} else {
addReply(c,shared.err);
* for dict.c to resize the hash tables accordingly to the fact we have o not
* running childs. */
void updateDictResizePolicy(void) {
- if (server.bgsavechildpid == -1 && server.aof_child_pid == -1)
+ if (server.rdb_child_pid == -1 && server.aof_child_pid == -1)
dictEnableResize();
else
dictDisableResize();
* if we resize the HT while there is the saving child at work actually
* a lot of memory movements in the parent will cause a lot of pages
* copied. */
- if (server.bgsavechildpid == -1 && server.aof_child_pid == -1) {
+ if (server.rdb_child_pid == -1 && server.aof_child_pid == -1) {
if (!(loops % 10)) tryResizeHashTables();
if (server.activerehashing) incrementallyRehash();
}
/* Start a scheduled AOF rewrite if this was requested by the user while
* a BGSAVE was in progress. */
- if (server.bgsavechildpid == -1 && server.aof_child_pid == -1 &&
+ if (server.rdb_child_pid == -1 && server.aof_child_pid == -1 &&
server.aof_rewrite_scheduled)
{
rewriteAppendOnlyFileBackground();
}
/* Check if a background saving or AOF rewrite in progress terminated. */
- if (server.bgsavechildpid != -1 || server.aof_child_pid != -1) {
+ if (server.rdb_child_pid != -1 || server.aof_child_pid != -1) {
int statloc;
pid_t pid;
if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc);
- if (pid == server.bgsavechildpid) {
+ if (pid == server.rdb_child_pid) {
backgroundSaveDoneHandler(exitcode,bysignal);
} else {
backgroundRewriteDoneHandler(exitcode,bysignal);
now-server.lastsave > sp->seconds) {
redisLog(REDIS_NOTICE,"%d changes in %d seconds. Saving...",
sp->changes, sp->seconds);
- rdbSaveBackground(server.dbfilename);
+ rdbSaveBackground(server.rdb_filename);
break;
}
}
/* Trigger an AOF rewrite if needed */
- if (server.bgsavechildpid == -1 &&
+ if (server.rdb_child_pid == -1 &&
server.aof_child_pid == -1 &&
server.aof_rewrite_perc &&
server.aof_current_size > server.aof_rewrite_min_size)
server.aof_selected_db = -1; /* Make sure the first time will not match */
server.aof_flush_postponed_start = 0;
server.pidfile = zstrdup("/var/run/redis.pid");
- server.dbfilename = zstrdup("dump.rdb");
+ server.rdb_filename = zstrdup("dump.rdb");
server.aof_filename = zstrdup("appendonly.aof");
server.requirepass = NULL;
- server.rdbcompression = 1;
+ server.rdb_compression = 1;
server.activerehashing = 1;
server.maxclients = REDIS_MAX_CLIENTS;
server.bpop_blocked_clients = 0;
listSetFreeMethod(server.pubsub_patterns,freePubsubPattern);
listSetMatchMethod(server.pubsub_patterns,listMatchPubsubPattern);
server.cronloops = 0;
- server.bgsavechildpid = -1;
+ server.rdb_child_pid = -1;
server.aof_child_pid = -1;
server.aof_rewrite_buf = sdsempty();
server.aof_buf = sdsempty();
/* Kill the saving child if there is a background saving in progress.
We want to avoid race conditions, for instance our saving child may
overwrite the synchronous saving did by SHUTDOWN. */
- if (server.bgsavechildpid != -1) {
+ if (server.rdb_child_pid != -1) {
redisLog(REDIS_WARNING,"There is a child saving an .rdb. Killing it!");
- kill(server.bgsavechildpid,SIGKILL);
- rdbRemoveTempFile(server.bgsavechildpid);
+ kill(server.rdb_child_pid,SIGKILL);
+ rdbRemoveTempFile(server.rdb_child_pid);
}
if (server.aof_state != REDIS_AOF_OFF) {
/* Kill the AOF saving child as the AOF we already have may be longer
if ((server.saveparamslen > 0 && !nosave) || save) {
redisLog(REDIS_NOTICE,"Saving the final RDB snapshot before exiting.");
/* Snapshotting. Perform a SYNC SAVE and exit */
- if (rdbSave(server.dbfilename) != REDIS_OK) {
+ if (rdbSave(server.rdb_filename) != REDIS_OK) {
/* Ooops.. error saving! The best we can do is to continue
* operating. Note that if there was a background saving process,
* in the next cron() Redis will be notified that the background
server.loading,
server.aof_state != REDIS_AOF_OFF,
server.dirty,
- server.bgsavechildpid != -1,
+ server.rdb_child_pid != -1,
server.lastsave,
server.aof_child_pid != -1);
if (loadAppendOnlyFile(server.aof_filename) == REDIS_OK)
redisLog(REDIS_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000);
} else {
- if (rdbLoad(server.dbfilename) == REDIS_OK) {
+ if (rdbLoad(server.rdb_filename) == REDIS_OK) {
redisLog(REDIS_NOTICE,"DB loaded from disk: %.3f seconds",
(float)(ustime()-start)/1000000);
} else if (errno != ENOENT) {
/* RDB persistence */
long long dirty; /* Changes to DB from the last save */
long long dirty_before_bgsave; /* Used to restore dirty on failed BGSAVE */
- pid_t bgsavechildpid; /* PID of RDB saving child */
+ pid_t rdb_child_pid; /* PID of RDB saving child */
struct saveparam *saveparams; /* Save points array for RDB */
int saveparamslen; /* Number of saving points */
- char *dbfilename; /* Name of RDB file */
- int rdbcompression; /* Use compression in RDB? */
+ char *rdb_filename; /* Name of RDB file */
+ int rdb_compression; /* Use compression in RDB? */
/* Logging */
char *logfile; /* Path of log file */
int syslog_enabled; /* Is syslog enabled? */
redisLog(REDIS_NOTICE,"Slave ask for synchronization");
/* Here we need to check if there is a background saving operation
* in progress, or if it is required to start one */
- if (server.bgsavechildpid != -1) {
+ if (server.rdb_child_pid != -1) {
/* Ok a background save is in progress. Let's check if it is a good
* one for replication, i.e. if there is another slave that is
* registering differences since the server forked to save */
} else {
/* Ok we don't have a BGSAVE in progress, let's start one */
redisLog(REDIS_NOTICE,"Starting BGSAVE for SYNC");
- if (rdbSaveBackground(server.dbfilename) != REDIS_OK) {
+ if (rdbSaveBackground(server.rdb_filename) != REDIS_OK) {
redisLog(REDIS_NOTICE,"Replication failed, can't BGSAVE");
addReplyError(c,"Unable to perform background save");
return;
redisLog(REDIS_WARNING,"SYNC failed. BGSAVE child returned an error");
continue;
}
- if ((slave->repldbfd = open(server.dbfilename,O_RDONLY)) == -1 ||
+ if ((slave->repldbfd = open(server.rdb_filename,O_RDONLY)) == -1 ||
redis_fstat(slave->repldbfd,&buf) == -1) {
freeClient(slave);
redisLog(REDIS_WARNING,"SYNC failed. Can't open/stat DB after BGSAVE: %s", strerror(errno));
}
}
if (startbgsave) {
- if (rdbSaveBackground(server.dbfilename) != REDIS_OK) {
+ if (rdbSaveBackground(server.rdb_filename) != REDIS_OK) {
listIter li;
listRewind(server.slaves,&li);
server.repl_transfer_left -= nread;
/* Check if the transfer is now complete */
if (server.repl_transfer_left == 0) {
- if (rename(server.repl_transfer_tmpfile,server.dbfilename) == -1) {
+ if (rename(server.repl_transfer_tmpfile,server.rdb_filename) == -1) {
redisLog(REDIS_WARNING,"Failed trying to rename the temp DB into dump.rdb in MASTER <-> SLAVE synchronization: %s", strerror(errno));
replicationAbortSyncTransfer();
return;
* rdbLoad() will call the event loop to process events from time to
* time for non blocking loading. */
aeDeleteFileEvent(server.el,server.repl_transfer_s,AE_READABLE);
- if (rdbLoad(server.dbfilename) != REDIS_OK) {
+ if (rdbLoad(server.rdb_filename) != REDIS_OK) {
redisLog(REDIS_WARNING,"Failed trying to load the MASTER synchronization DB from disk");
replicationAbortSyncTransfer();
return;