Add a command to rewrite an optimized version of the AOF but NOT in the background. This makes sense when a server is stressed and starting a background rewrite is too expensive.
Comment From: yoav-steinberg
I can imagine the following scenario: - There's lots of activity on the server and memory is stressed so a background rewrite is dangerous because it might crash the server if it runs out of memory due to the rewrite copy-on-write/diff buffers overhead. - Disk space is running low and we must do the rewrite now to avoid a crash due to running out of disk space. This is the only possible scenario I can think of when you'd need this. But in this scenario it's clear we have an inadequate configuration: too much activity and not enough free memory to handle rewrites (without disrupting clients). So ideally, if you reach such a state, you'd down the server and reconfigure it (or due a failover to another server). That's the best solution because if you have to disrupt clients best do it only once and not block server access periodically with a foreground aof rewrite.
You might say, I don't want to reconfigure my server, I'm ok with disrupting clients periodically and don't want to pay for a bigger server. If that's the case, you can solve this with a CLIENT PAUSE timeout WRITE and then a BGREWRITEAOF to achieve the desired functionality. Note that this also give you the advantage of tracking rewrite progress instead of blocking the server completely. Once rewrite is done you can issue a CLIENT UNPAUSE.
Comment From: yoav-steinberg
I'm closing after discussing this with @oranagra and confirming with him the above proposed solution.