Unverified Commit 6013122c authored by zhaozhao.zz's avatar zhaozhao.zz Committed by GitHub
Browse files

check dbSize when rewrite AOF, in case unnecessary SELECT (#12775)

Introduced by #11695, should skip empty db in case unnecessary SELECT.
parent 9b6dded4
...@@ -2257,10 +2257,13 @@ int rewriteAppendOnlyFileRio(rio *aof) { ...@@ -2257,10 +2257,13 @@ int rewriteAppendOnlyFileRio(rio *aof) {
for (j = 0; j < server.dbnum; j++) { for (j = 0; j < server.dbnum; j++) {
char selectcmd[] = "*2\r\n$6\r\nSELECT\r\n"; char selectcmd[] = "*2\r\n$6\r\nSELECT\r\n";
redisDb *db = server.db + j;
if (dbSize(db, DB_MAIN) == 0) continue;
/* SELECT the new DB */ /* SELECT the new DB */
if (rioWrite(aof,selectcmd,sizeof(selectcmd)-1) == 0) goto werr; if (rioWrite(aof,selectcmd,sizeof(selectcmd)-1) == 0) goto werr;
if (rioWriteBulkLongLong(aof,j) == 0) goto werr; if (rioWriteBulkLongLong(aof,j) == 0) goto werr;
redisDb *db = server.db + j;
dbit = dbIteratorInit(db, DB_MAIN); dbit = dbIteratorInit(db, DB_MAIN);
/* Iterate this DB writing every entry */ /* Iterate this DB writing every entry */
while((de = dbIteratorNext(dbit)) != NULL) { while((de = dbIteratorNext(dbit)) != NULL) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment