* Implement MULTI/EXEC as transaction abstract API to diskstore.c, with transaction_start, transaction_end, and a journal to recover.
* Stop BGSAVE thread on shutdown and any other condition where the child is killed during normal bgsave.
* Use a mutex to log on the file, so that we don't get overlapping messages, or even better make sure to use a single write against it.
+* Fix RANDOMKEY to really do something interesting
+* Fix DBSIZE to really do something interesting
+* Add a DEBUG command to check if an entry is or not in memory currently
REPLICATION
===========
} else {
redisLog(REDIS_WARNING,
"Background append only file rewriting terminated by signal %d",
- bysitnal);
+ bysignal);
}
cleanup:
sdsfree(server.bgrewritebuf);
}
}
+void dsRdbSaveSetState(int state) {
+ pthread_mutex_lock(&server.bgsavethread_mutex);
+ server.bgsavethread_state = state;
+ pthread_mutex_unlock(&server.bgsavethread_mutex);
+}
+
void *dsRdbSave_thread(void *arg) {
char tmpfile[256], *filename = (char*)arg;
int j, i;
time_t now = time(NULL);
+ FILE *fp;
/* Change state to ACTIVE, to signal there is a saving thead working. */
pthread_mutex_lock(&server.bgsavethread_mutex);
snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
fp = fopen(tmpfile,"w");
if (!fp) {
- redisLog(REDIS_WARNING, "Failed saving the DB: %s", strerror(errno));
- return REDIS_ERR;
+ redisLog(REDIS_WARNING, "Failed opening .rdb for saving: %s",
+ strerror(errno));
+ dsRdbSaveSetState(REDIS_BGSAVE_THREAD_DONE_ERR);
+ return NULL;
}
if (fwrite("REDIS0001",9,1,fp) == 0) goto werr;
+ sleep(5);
+
+#if 0
/* Scan all diskstore dirs looking for keys */
for (j = 0; j < 256; j++) {
for (i = 0; i < 256; i++) {
if (rdbSaveLen(fp,j) == -1) goto werr;
}
}
+#endif
/* Make sure data will not remain on the OS's output buffers */
fflush(fp);
if (rename(tmpfile,filename) == -1) {
redisLog(REDIS_WARNING,"Error moving temp DB file on the final destination: %s", strerror(errno));
unlink(tmpfile);
- return REDIS_ERR;
+ dsRdbSaveSetState(REDIS_BGSAVE_THREAD_DONE_ERR);
+ return NULL;
}
redisLog(REDIS_NOTICE,"DB saved on disk");
- return REDIS_OK;
+ dsRdbSaveSetState(REDIS_BGSAVE_THREAD_DONE_OK);
+ return NULL;
werr:
zfree(filename);
fclose(fp);
unlink(tmpfile);
+ dsRdbSaveSetState(REDIS_BGSAVE_THREAD_DONE_ERR);
redisLog(REDIS_WARNING,"Write error saving DB on disk: %s", strerror(errno));
+ return NULL;
}
int dsRdbSave(char *filename) {
snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
fp = fopen(tmpfile,"w");
if (!fp) {
- redisLog(REDIS_WARNING, "Failed saving the DB: %s", strerror(errno));
+ redisLog(REDIS_WARNING, "Failed opening .rdb for saving: %s",
+ strerror(errno));
return REDIS_ERR;
}
if (fwrite("REDIS0001",9,1,fp) == 0) goto werr;
}
void saveCommand(redisClient *c) {
- if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread-t)-1) {
+ if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread_t)-1) {
addReplyError(c,"Background save already in progress");
return;
}
}
void bgsaveCommand(redisClient *c) {
- if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread-t)-1) {
+ if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread_t)-1) {
addReplyError(c,"Background save already in progress");
return;
}
state = server.bgsavethread_state;
pthread_mutex_unlock(&server.bgsavethread_mutex);
- if (state == REDIS_BGSAVE_DONE_OK || state == REDIS_BGSAVE_DONE_ERR)
+ if (state == REDIS_BGSAVE_THREAD_DONE_OK ||
+ state == REDIS_BGSAVE_THREAD_DONE_ERR)
{
backgroundSaveDoneHandler(
- (state == REDIS_BGSAVE_DONE_OK) ? 0 : 1, 0);
+ (state == REDIS_BGSAVE_THREAD_DONE_OK) ? 0 : 1, 0);
}
}
} else if (!server.ds_enabled) {
off_t rdbSavedObjectLen(robj *o);
off_t rdbSavedObjectPages(robj *o);
robj *rdbLoadObject(int type, FILE *fp);
-void backgroundSaveDoneHandler(int exitcode, int bysignal) {
+void backgroundSaveDoneHandler(int exitcode, int bysignal);
int rdbSaveKeyValuePair(FILE *fp, redisDb *db, robj *key, robj *val, time_t now);
int rdbLoadType(FILE *fp);
time_t rdbLoadTime(FILE *fp);
int dsDel(redisDb *db, robj *key);
int dsExists(redisDb *db, robj *key);
void dsFlushDb(int dbid);
+int dsRdbSave(char *filename);
/* Disk Store Cache */
void dsInit(void);