From a2f2b6f5b19569b5e414a2b9099aa880c070e1ac Mon Sep 17 00:00:00 2001 From: chenyang8094 Date: Sat, 12 Feb 2022 00:47:03 +0800 Subject: [PATCH] Modify AOF preamble related logs, and change the RDB aux field (#10283) In multi-part aof, We no longer have the concept of `RDB-preamble`, so the related logs should be removed. However, in order to print compatible logs when loading old-style AOFs, we also have to keep the relevant code. Additionally, when saving an RDB, change the RDB aux field from "aof-preamble" to "aof-base". --- src/aof.c | 23 ++++++++++++++++------- src/rdb.c | 14 +++++++++----- src/server.h | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/aof.c b/src/aof.c index dadc34612..47f4618b8 100644 --- a/src/aof.c +++ b/src/aof.c @@ -1338,26 +1338,35 @@ int loadSingleAppendOnlyFile(char *filename) { client *old_client = server.current_client; fakeClient = server.current_client = createAOFClient(); - /* Check if this AOF file has an RDB preamble. In that case we need to - * load the RDB file and later continue loading the AOF tail. */ + /* Check if the AOF file is in RDB format (it may be RDB encoded base AOF + * or old style RDB-preamble AOF). In that case we need to load the RDB file + * and later continue loading the AOF tail if it is an old style RDB-preamble AOF. */ char sig[5]; /* "REDIS" */ if (fread(sig,1,5,fp) != 5 || memcmp(sig,"REDIS",5) != 0) { - /* No RDB preamble, seek back at 0 offset. */ + /* Not in RDB format, seek back at 0 offset. */ if (fseek(fp,0,SEEK_SET) == -1) goto readerr; } else { - /* RDB preamble. Pass loading the RDB functions. */ + /* RDB format. Pass loading the RDB functions. */ rio rdb; + int old_style = !strcmp(filename, server.aof_filename); + if (old_style) + serverLog(LL_NOTICE, "Reading RDB preamble from AOF file..."); + else + serverLog(LL_NOTICE, "Reading RDB base file on AOF loading..."); - serverLog(LL_NOTICE,"Reading RDB preamble from AOF file..."); if (fseek(fp,0,SEEK_SET) == -1) goto readerr; rioInitWithFile(&rdb,fp); if (rdbLoadRio(&rdb,RDBFLAGS_AOF_PREAMBLE,NULL) != C_OK) { - serverLog(LL_WARNING,"Error reading the RDB preamble of the AOF file %s, AOF loading aborted", filename); + if (old_style) + serverLog(LL_WARNING, "Error reading the RDB preamble of the AOF file %s, AOF loading aborted", filename); + else + serverLog(LL_WARNING, "Error reading the RDB base file %s, AOF loading aborted", filename); + goto readerr; } else { loadingAbsProgress(ftello(fp)); last_progress_report_size = ftello(fp); - serverLog(LL_NOTICE,"Reading the remaining AOF tail..."); + if (old_style) serverLog(LL_NOTICE, "Reading the remaining AOF tail..."); } } diff --git a/src/rdb.c b/src/rdb.c index ac5aa1f86..533665d16 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -1151,8 +1151,9 @@ ssize_t rdbSaveAuxFieldStrInt(rio *rdb, char *key, long long val) { /* Save a few default AUX fields with information about the RDB generated. */ int rdbSaveInfoAuxFields(rio *rdb, int rdbflags, rdbSaveInfo *rsi) { + UNUSED(rdbflags); int redis_bits = (sizeof(void*) == 8) ? 64 : 32; - int aof_preamble = (rdbflags & RDBFLAGS_AOF_PREAMBLE) != 0; + int aof_base = (rdbflags & RDBFLAGS_AOF_PREAMBLE) != 0; /* Add a few fields about the state when the RDB was created. */ if (rdbSaveAuxFieldStrStr(rdb,"redis-ver",REDIS_VERSION) == -1) return -1; @@ -1169,7 +1170,7 @@ int rdbSaveInfoAuxFields(rio *rdb, int rdbflags, rdbSaveInfo *rsi) { if (rdbSaveAuxFieldStrInt(rdb,"repl-offset",server.master_repl_offset) == -1) return -1; } - if (rdbSaveAuxFieldStrInt(rdb,"aof-preamble",aof_preamble) == -1) return -1; + if (rdbSaveAuxFieldStrInt(rdb, "aof-base", aof_base) == -1) return -1; return 1; } @@ -2962,6 +2963,9 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin } else if (!strcasecmp(auxkey->ptr,"aof-preamble")) { long long haspreamble = strtoll(auxval->ptr,NULL,10); if (haspreamble) serverLog(LL_NOTICE,"RDB has an AOF tail"); + } else if (!strcasecmp(auxkey->ptr, "aof-base")) { + long long isbase = strtoll(auxval->ptr, NULL, 10); + if (isbase) serverLog(LL_NOTICE, "RDB is base AOF"); } else if (!strcasecmp(auxkey->ptr,"redis-bits")) { /* Just ignored. */ } else { @@ -3049,9 +3053,9 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin * received from the master. In the latter case, the master is * responsible for key expiry. If we would expire keys here, the * snapshot taken by the master may not be reflected on the slave. - * Similarly if the RDB is the preamble of an AOF file, we want to - * load all the keys as they are, since the log of operations later - * assume to work in an exact keyspace state. */ + * Similarly, if the base AOF is RDB format, we want to load all + * the keys they are, since the log of operations in the incr AOF + * is assumed to work in the exact keyspace state. */ if (val == NULL) { /* Since we used to have bug that could lead to empty keys * (See #8453), we rather not fail when empty key is encountered diff --git a/src/server.h b/src/server.h index 2083948c9..8c25d006b 100644 --- a/src/server.h +++ b/src/server.h @@ -1638,7 +1638,7 @@ struct redisServer { int aof_last_write_status; /* C_OK or C_ERR */ int aof_last_write_errno; /* Valid if aof write/fsync status is ERR */ int aof_load_truncated; /* Don't stop on unexpected AOF EOF. */ - int aof_use_rdb_preamble; /* Use RDB preamble on AOF rewrites. */ + int aof_use_rdb_preamble; /* Specify base AOF to use RDB encoding on AOF rewrites. */ redisAtomic int aof_bio_fsync_status; /* Status of AOF fsync in bio job. */ redisAtomic int aof_bio_fsync_errno; /* Errno of AOF fsync in bio job. */ aofManifest *aof_manifest; /* Used to track AOFs. */