提交 8063b99d 编写于 作者: P Pieter Noordhuis

log error and quit when the AOF contains an unfinished MULTI

上级 98d2e23b
...@@ -8111,12 +8111,14 @@ static struct redisClient *createFakeClient(void) { ...@@ -8111,12 +8111,14 @@ static struct redisClient *createFakeClient(void) {
c->reply = listCreate(); c->reply = listCreate();
listSetFreeMethod(c->reply,decrRefCount); listSetFreeMethod(c->reply,decrRefCount);
listSetDupMethod(c->reply,dupClientReplyValue); listSetDupMethod(c->reply,dupClientReplyValue);
initClientMultiState(c);
return c; return c;
} }
static void freeFakeClient(struct redisClient *c) { static void freeFakeClient(struct redisClient *c) {
sdsfree(c->querybuf); sdsfree(c->querybuf);
listRelease(c->reply); listRelease(c->reply);
freeClientMultiState(c);
zfree(c); zfree(c);
} }
...@@ -8128,6 +8130,7 @@ int loadAppendOnlyFile(char *filename) { ...@@ -8128,6 +8130,7 @@ int loadAppendOnlyFile(char *filename) {
FILE *fp = fopen(filename,"r"); FILE *fp = fopen(filename,"r");
struct redis_stat sb; struct redis_stat sb;
unsigned long long loadedkeys = 0; unsigned long long loadedkeys = 0;
int appendonly = server.appendonly;
if (redis_fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) if (redis_fstat(fileno(fp),&sb) != -1 && sb.st_size == 0)
return REDIS_ERR; return REDIS_ERR;
...@@ -8137,6 +8140,10 @@ int loadAppendOnlyFile(char *filename) { ...@@ -8137,6 +8140,10 @@ int loadAppendOnlyFile(char *filename) {
exit(1); exit(1);
} }
/* Temporarily disable AOF, to prevent EXEC from feeding a MULTI
* to the same file we're about to read. */
server.appendonly = 0;
fakeClient = createFakeClient(); fakeClient = createFakeClient();
while(1) { while(1) {
int argc, j; int argc, j;
...@@ -8192,8 +8199,14 @@ int loadAppendOnlyFile(char *filename) { ...@@ -8192,8 +8199,14 @@ int loadAppendOnlyFile(char *filename) {
} }
} }
} }
/* This point can only be reached when EOF is reached without errors.
* If the client is in the middle of a MULTI/EXEC, log error and quit. */
if (fakeClient->flags & REDIS_MULTI) goto readerr;
fclose(fp); fclose(fp);
freeFakeClient(fakeClient); freeFakeClient(fakeClient);
server.appendonly = appendonly;
return REDIS_OK; return REDIS_OK;
readerr: readerr:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册