X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/d4d3a70da2c9be4c5aa67a0be735568dbe436568..fbb23ce496eaffa8313846601a73a68df0c0ba5d:/src/rdb.c diff --git a/src/rdb.c b/src/rdb.c index 2557f5b8..cfbec3e8 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -413,11 +413,6 @@ int rdbSave(char *filename) { int j; time_t now = time(NULL); - if (server.ds_enabled) { - cacheForcePointInTime(); - return dsRdbSave(filename); - } - snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid()); fp = fopen(tmpfile,"w"); if (!fp) { @@ -425,12 +420,12 @@ int rdbSave(char *filename) { strerror(errno)); return REDIS_ERR; } - if (fwrite("REDIS0001",9,1,fp) == 0) goto werr; + if (fwrite("REDIS0002",9,1,fp) == 0) goto werr; for (j = 0; j < server.dbnum; j++) { redisDb *db = server.db+j; dict *d = db->dict; if (dictSize(d) == 0) continue; - di = dictGetIterator(d); + di = dictGetSafeIterator(d); if (!di) { fclose(fp); return REDIS_ERR; @@ -482,17 +477,13 @@ werr: int rdbSaveBackground(char *filename) { pid_t childpid; + long long start; - if (server.bgsavechildpid != -1 || - server.bgsavethread != (pthread_t) -1) return REDIS_ERR; + if (server.bgsavechildpid != -1) return REDIS_ERR; server.dirty_before_bgsave = server.dirty; - if (server.ds_enabled) { - cacheForcePointInTime(); - return dsRdbSaveBackground(filename); - } - + start = ustime(); if ((childpid = fork()) == 0) { int retval; @@ -503,6 +494,7 @@ int rdbSaveBackground(char *filename) { _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)); @@ -915,7 +907,7 @@ void stopLoading(void) { int rdbLoad(char *filename) { FILE *fp; uint32_t dbid; - int type, retval, rdbver; + int type, rdbver; redisDb *db = server.db+0; char buf[1024]; time_t expiretime, now = time(NULL); @@ -931,7 +923,7 @@ int rdbLoad(char *filename) { return REDIS_ERR; } rdbver = atoi(buf+5); - if (rdbver != 1) { + if (rdbver < 1 || rdbver > 2) { fclose(fp); redisLog(REDIS_WARNING,"Can't handle RDB format version %d",rdbver); return REDIS_ERR; @@ -978,11 +970,8 @@ int rdbLoad(char *filename) { continue; } /* Add the new object in the hash table */ - retval = dbAdd(db,key,val); - if (retval == REDIS_ERR) { - redisLog(REDIS_WARNING,"Loading DB, duplicated key (%s) found! Unrecoverable error, exiting now.", key->ptr); - exit(1); - } + dbAdd(db,key,val); + /* Set the expire time if needed */ if (expiretime != -1) setExpire(db,key,expiretime); @@ -1013,15 +1002,13 @@ void backgroundSaveDoneHandler(int exitcode, int bysignal) { rdbRemoveTempFile(server.bgsavechildpid); } server.bgsavechildpid = -1; - server.bgsavethread = (pthread_t) -1; - server.bgsavethread_state = REDIS_BGSAVE_THREAD_UNACTIVE; /* 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 || server.bgsavethread != (pthread_t)-1) { + if (server.bgsavechildpid != -1) { addReplyError(c,"Background save already in progress"); return; } @@ -1033,11 +1020,11 @@ void saveCommand(redisClient *c) { } void bgsaveCommand(redisClient *c) { - if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread_t)-1) { + if (server.bgsavechildpid != -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);