提交 cc275067 编写于 作者: A antirez

blocking SAVE implemented

上级 43574a72
......@@ -474,7 +474,7 @@ werr:
return NULL;
}
int dsRdbSave(char *filename) {
int dsRdbSaveBackground(char *filename) {
pthread_t thread;
if (pthread_create(&thread,NULL,dsRdbSave_thread,zstrdup(filename)) != 0) {
......@@ -486,3 +486,24 @@ int dsRdbSave(char *filename) {
return REDIS_OK;
}
}
int dsRdbSave(char *filename) {
/* A blocking save is actually a non blocking save... just we wait
* for it to terminate in a non-busy loop. */
redisLog(REDIS_NOTICE,"Starting a blocking SAVE (BGSAVE + blocking wait)");
server.dirty_before_bgsave = server.dirty;
if (dsRdbSaveBackground(filename) == REDIS_ERR) return REDIS_ERR;
while(1) {
usleep(1000);
int state;
pthread_mutex_lock(&server.bgsavethread_mutex);
state = server.bgsavethread_state;
pthread_mutex_unlock(&server.bgsavethread_mutex);
if (state == REDIS_BGSAVE_THREAD_DONE_OK ||
state == REDIS_BGSAVE_THREAD_DONE_ERR) break;
}
return REDIS_OK;
}
......@@ -504,7 +504,7 @@ int rdbSaveBackground(char *filename) {
if (server.ds_enabled) {
cacheForcePointInTime();
return dsRdbSave(filename);
return dsRdbSaveBackground(filename);
}
if ((childpid = fork()) == 0) {
......
......@@ -802,6 +802,7 @@ robj *dsGet(redisDb *db, robj *key, time_t *expire);
int dsDel(redisDb *db, robj *key);
int dsExists(redisDb *db, robj *key);
void dsFlushDb(int dbid);
int dsRdbSaveBackground(char *filename);
int dsRdbSave(char *filename);
/* Disk Store Cache */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册