parent
fcd7df5eab
commit
b0ec22f948
17
src/aof.c
17
src/aof.c
@ -38,6 +38,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
void aofUpdateCurrentSize(void);
|
void aofUpdateCurrentSize(void);
|
||||||
void aofClosePipes(void);
|
void aofClosePipes(void);
|
||||||
@ -234,11 +235,20 @@ void stopAppendOnly(void) {
|
|||||||
/* Called when the user switches from "appendonly no" to "appendonly yes"
|
/* Called when the user switches from "appendonly no" to "appendonly yes"
|
||||||
* at runtime using the CONFIG command. */
|
* at runtime using the CONFIG command. */
|
||||||
int startAppendOnly(void) {
|
int startAppendOnly(void) {
|
||||||
|
char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */
|
||||||
|
|
||||||
server.aof_last_fsync = server.unixtime;
|
server.aof_last_fsync = server.unixtime;
|
||||||
server.aof_fd = open(server.aof_filename,O_WRONLY|O_APPEND|O_CREAT,0644);
|
server.aof_fd = open(server.aof_filename,O_WRONLY|O_APPEND|O_CREAT,0644);
|
||||||
serverAssert(server.aof_state == AOF_OFF);
|
serverAssert(server.aof_state == AOF_OFF);
|
||||||
if (server.aof_fd == -1) {
|
if (server.aof_fd == -1) {
|
||||||
serverLog(LL_WARNING,"Redis needs to enable the AOF but can't open the append only file: %s",strerror(errno));
|
char *cwdp = getcwd(cwd,MAXPATHLEN);
|
||||||
|
|
||||||
|
serverLog(LL_WARNING,
|
||||||
|
"Redis needs to enable the AOF but can't open the "
|
||||||
|
"append only file %s (in server root dir %s): %s",
|
||||||
|
server.aof_filename,
|
||||||
|
cwdp ? cwdp : "unknown",
|
||||||
|
strerror(errno));
|
||||||
return C_ERR;
|
return C_ERR;
|
||||||
}
|
}
|
||||||
if (rewriteAppendOnlyFileBackground() == C_ERR) {
|
if (rewriteAppendOnlyFileBackground() == C_ERR) {
|
||||||
@ -1413,7 +1423,10 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
|
|||||||
latencyStartMonitor(latency);
|
latencyStartMonitor(latency);
|
||||||
if (rename(tmpfile,server.aof_filename) == -1) {
|
if (rename(tmpfile,server.aof_filename) == -1) {
|
||||||
serverLog(LL_WARNING,
|
serverLog(LL_WARNING,
|
||||||
"Error trying to rename the temporary AOF file: %s", strerror(errno));
|
"Error trying to rename the temporary AOF file %s into %s: %s",
|
||||||
|
tmpfile,
|
||||||
|
server.aof_filename,
|
||||||
|
strerror(errno));
|
||||||
close(newfd);
|
close(newfd);
|
||||||
if (oldfd != -1) close(oldfd);
|
if (oldfd != -1) close(oldfd);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
19
src/rdb.c
19
src/rdb.c
@ -39,6 +39,7 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
#define RDB_LOAD_NONE 0
|
#define RDB_LOAD_NONE 0
|
||||||
#define RDB_LOAD_ENC (1<<0)
|
#define RDB_LOAD_ENC (1<<0)
|
||||||
@ -844,6 +845,7 @@ werr: /* Write error. */
|
|||||||
/* Save the DB on disk. Return C_ERR on error, C_OK on success. */
|
/* Save the DB on disk. Return C_ERR on error, C_OK on success. */
|
||||||
int rdbSave(char *filename) {
|
int rdbSave(char *filename) {
|
||||||
char tmpfile[256];
|
char tmpfile[256];
|
||||||
|
char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
rio rdb;
|
rio rdb;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
@ -851,7 +853,12 @@ int rdbSave(char *filename) {
|
|||||||
snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
|
snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
|
||||||
fp = fopen(tmpfile,"w");
|
fp = fopen(tmpfile,"w");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
serverLog(LL_WARNING, "Failed opening .rdb for saving: %s",
|
char *cwdp = getcwd(cwd,MAXPATHLEN);
|
||||||
|
serverLog(LL_WARNING,
|
||||||
|
"Failed opening the RDB file %s (in server root dir %s) "
|
||||||
|
"for saving: %s",
|
||||||
|
filename,
|
||||||
|
cwdp ? cwdp : "unknown",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return C_ERR;
|
return C_ERR;
|
||||||
}
|
}
|
||||||
@ -870,10 +877,18 @@ int rdbSave(char *filename) {
|
|||||||
/* Use RENAME to make sure the DB file is changed atomically only
|
/* Use RENAME to make sure the DB file is changed atomically only
|
||||||
* if the generate DB file is ok. */
|
* if the generate DB file is ok. */
|
||||||
if (rename(tmpfile,filename) == -1) {
|
if (rename(tmpfile,filename) == -1) {
|
||||||
serverLog(LL_WARNING,"Error moving temp DB file on the final destination: %s", strerror(errno));
|
char *cwdp = getcwd(cwd,MAXPATHLEN);
|
||||||
|
serverLog(LL_WARNING,
|
||||||
|
"Error moving temp DB file %s on the final "
|
||||||
|
"destination %s (in server root dir %s): %s",
|
||||||
|
tmpfile,
|
||||||
|
filename,
|
||||||
|
cwdp ? cwdp : "unknown",
|
||||||
|
strerror(errno));
|
||||||
unlink(tmpfile);
|
unlink(tmpfile);
|
||||||
return C_ERR;
|
return C_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
serverLog(LL_NOTICE,"DB saved on disk");
|
serverLog(LL_NOTICE,"DB saved on disk");
|
||||||
server.dirty = 0;
|
server.dirty = 0;
|
||||||
server.lastsave = time(NULL);
|
server.lastsave = time(NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user