Search code examples
redispersistence

redis - load from RDB and keep writing the AOF


I'm working in combined mod - RDB + AOF.
I'm looking for a way to load after a restart from the RDB file - mainly for fast restarts.
On top of that, I want to continue writing the AOF.
Once I know there is a disaster, I will manually load from AOF.
This is my current config: (I know that appendonly yes is saying that the AOF will be loaded after restart, I'm looking for a wait load from RDB and keep writing the AOF.)

aof-use-rdb-preamble yes
aof-load-truncated yes
aof-rewrite-incremental-fsync yes
appendfilename "appendonly.aof"
appendfsync everysec
appendonly yes

Thanks


Solution

  • Redis will always load the AOF if both are enabled, as AOF gives you better durability.

    By using aof-use-rdb-preamble yes, you are already getting the best of both worlds. Your AOF is automatically rewritten every now and then automatically, with an RDB file first and a AOF tail. See redis.conf L1157.

    Since you want to have a predictable mean time to recovery (MTTR), you want to adjust the parameters for Automatic rewrite of the AOF, as described in redis.conf LL113

    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    

    You can also manually trigger a AOF rewrite with the BGREWRITEAOF command

    BGREWRITEAOF would work even if appendonly is configured to no. However, note that every time you call BGREWRITEAOF you are getting pretty much an rdb file inside the appendonly.aof file.

    Then, if appendonly is configured to yes, you also get an AOF tail (commands are appended to the appendonly.aof file).

    BGREWRITEAOF and BGSAVE are expensive operations and will degrade the performance of your server while running. So I suggest you use only AOF, that already gives you log compaction either automatically or every time you run BGREWRITEAOF.

    You can set auto-aof-rewrite-percentage to a low value, say 2 or 5 percent. Then you can test the MTTR (time it takes to restart) with both strategies. I am sure you'll find the difference is too small for it to make sense combining the two strategies separately (RDB and AOF). AOF already gives you RDB-inside if aof-use-rdb-preamble yes