[2156] 01 Sep 17:11:28.042 # Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename>
Your best solution is to stop your systems crashing. That's an extremely
abnormal behaviour. Redis (or some other userland process) crashing? Yep,
that can happen for a variety of reasons. A kernel-level crash? I'd be
taking a deeper look at that, because it *should* be a never event.
On Tue, Sep 02, 2014 at 08:15:18AM -0500, Jay Rolette wrote:In that case, you might be best to patch Redis itself to stop processing the
> It's a pre-alpha embedded product, so it isn't near as rare as it might be
> otherwise, but in truth, it doesn't matter. Production systems do crash and
> I need to make sure the appliance comes back up without requiring operator
> intervention.
AOF and startup when it discovers corruption. All the the corruption-fix
program does is to truncate the AOF to the end of the last-good command; the
reason why Redis doesn't automatically startup like this is to avoid the
possibility of corruption in the middle of a file from losing a huge amount
of otherwise recoverable data; if you're just automatically truncating the
AOF without examining it, Redis itself may as well do that, and save you the
extended delay of Redis trying to load the AOF, failing, running the
corruption fix (which scans the whole AOF again), and then Redis starting up
(reading the AOF a *third* time).
I've dug around in that corner of the codebase in the past, and from memory
it's a relatively simple thing to change.
> After some additional testing, it looks like I'm seeing this even after aUhm... that's a pretty serious bug somewhere. Either Redis is stopping in
> controlled shutdown/reboot of the system.
the middle of a write (which I didn't think was possible -- Redis issues the
write to the AOF pretty much immediately), or the OS isn't flushing to disk
before it shuts down. I'd consider that a fairly nasty bug, and one that
could potentially cause problems elsewhere.
Why would you clone the corrupted file? Just in case it was a mid-fileOn Tue, Sep 02, 2014 at 06:33:11PM -0500, Jay Rolette wrote:
> Good point on the startup performance implications. I'll look at adding a
> command line option that won't abort starting if the AOF file is bad.
> Instead it would clone the corrupted file and then truncate/fix and startup.
corruption and the remainder of the data could be recovered at a later time?
That'll end up consuming a lot of disk space, especially in the event of
multiple successive corruptions that aren't quickly examined and cleaned up
by an operator.
I wouldn't make a copy, in any event. I'd change the startup logic to be:
Load AOF
If corruption found:
Immediately trigger a rewrite, to get a clean base AOF
when AOF rewrite complete, move corrupted AOF out of the way instead of
overwriting it
Moving the corrupted AOF at the end of the rewrite avoids an extended period
when there's no AOF to load if Redis restarts, while avoiding the need to
chew disk I/O copying a file for which two copies aren't needed.
> Yep. My guess is it is a problem with the shutdown script not giving RedisBy "bouncing the box", you mean you're just hard-resetting the CPU, rather
> time to cleanup. It probably sends SIGTERM and then immediately bounces the
> box. It's on my list to chase that one down in the next couple of days.
than giving the kernel time to shutdown cleanly? That'll end badly for all
*sorts* of things. But yeah, you should definitely wait for Redis to
shutdown before letting the machine reboot.
For completeness, how about also adding a way to configure a forced start - I.e. even if the AOF corruption is in the middle? I assume this will be helpful in cases where availability is mandatory and data is secondary - e.g. avoid cache warning as much as possible.
On Wed, Sep 03, 2014 at 09:29:02AM -0500, Jay Rolette wrote:
> On Tue, Sep 2, 2014 at 7:49 PM, Matt Palmer <mpa...@hezmatt.org> wrote:
> > I wouldn't make a copy, in any event. I'd change the startup logic to be:No, I'm saying get Redis to run the same process as is done by sending a
> >
> > Load AOF
> > If corruption found:
> > Immediately trigger a rewrite, to get a clean base AOF
> > when AOF rewrite complete, move corrupted AOF out of the way instead of
> > overwriting it
> >
> > Moving the corrupted AOF at the end of the rewrite avoids an extended
> > period
> > when there's no AOF to load if Redis restarts, while avoiding the need to
> > chew disk I/O copying a file for which two copies aren't needed.
> >
>
> Not sure I'm seeing the difference in the startup logic you are suggesting.
> Maybe I'm missing what you mean by "trigger a rewrite"? Are you suggesting
> creating a new empty AOF file to run from?
BGREWRITEAOF command (fork, start writing a new AOF, queueing changes, when
the write is done, dump the cache of changes to the new AOF, then rename
that new AOF over the top of the existing AOF), *except* that you move the
known-corrupt AOF out of the way, for later diagnosis.
> Also, "move the corrupted AOF out of the way" sounds no different than> cloning the AOF file.It's very different. Cloning an AOF means, to me, copying it. That
requires reading and writing the entire AOF, during which time Redis isn't
doing anything. Perhaps you're only going to be storing a couple of MB of
AOF, in which case who cares, but if it's any non-trivial amount of data
you'll be waiting a *long* time (comparatively) for that copy to finish.
Perhaps I'm just scarred by my days of dealing with 100GB+ AOFs and the
"fun" involved in dealing with those when they corrupted.
By moving the corrupt AOF out of the way, you're performing a single write
(a rename) instead of a large copy, which will happen nearly
instantaneously, and get your Redis up and running a lot more quickly.