Bug 64116 - How does one fix journal corruptions?
Summary: How does one fix journal corruptions?
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: x86 (IA32) Linux (All)
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
Depends on:
Reported: 2013-05-01 15:24 UTC by George Mitchell
Modified: 2014-10-27 15:05 UTC (History)
5 users (show)

See Also:
i915 platform:
i915 features:


Description George Mitchell 2013-05-01 15:24:40 UTC
I have an issue with journal corruptions and need to know what is the accepted way to deal with them.


PASS: /var/log/journal/8846d97f611b49aa9f3d48eeac6a81f2/user-501@0004d8c0e67ae13b-b8129f5e2592f54a.journal~   
PASS: /var/log/journal/8846d97f611b49aa9f3d48eeac6a81f2/system@0004d8c1b2856725-2112e0afc66b4fe1.journal~     
Invalid object contents at 4968272█████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  48%
File corruption detected at /var/log/journal/8846d97f611b49aa9f3d48eeac6a81f2/system@0004d8c1c6f62f7e-fdafabfbf8b29e82.journal~:4968272 (of 4972544, 99%).
FAIL: /var/log/journal/8846d97f611b49aa9f3d48eeac6a81f2/system@0004d8c1c6f62f7e-fdafabfbf8b29e82.journal~ (Bad message)
PASS: /var/log/journal/8846d97f611b49aa9f3d48eeac6a81f2/system@0004d8c1d72c036c-272007256a8b1a19.journal~     
PASS: /var/log/journal/8846d97f611b49aa9f3d48eeac6a81f2/system@0004d8c1e77d0273-535b41ed3fedf561.journal~
Comment 1 Zbigniew Jedrzejewski-Szmek 2013-08-05 03:08:22 UTC
The only way to deal with journal corruptions, currently, is to ignore them: when a corruption is detected, journald will rename the file to <something>.journal~, and journalctl will try to do its best reading it. Actually fixing journal corruptions is a hard job, and it seems unlikely that it will be implemented in the near future.

Note that the corruption reporting has become more verbose since this bug was reported, and some "corruptions" that were reported as such are now reported as unusual, but acceptable events (happened after 204, so the changes are included in systemd-205).
Comment 2 Lennart Poettering 2014-06-25 09:51:01 UTC
Yupp, journal corruptions result in rotation, and when reading we try to make the best of it. they are nothing we really need to fix hence.
Comment 3 Lennart Poettering 2014-10-08 20:27:49 UTC
Since this bugyilla report is apparently sometimes linked these days as an example how we wouldn't fix a major bug in systemd:

Journal files are mostly append-only files. We keep adding to the end as we go, only updating minimal indexes and bookkeeping in the front earlier parts of the files. These files are rotated (rotation = renamed and replaced by a new one) from time to time, based on certain conditions, such as time, file size, and also when we find the files to be corrupted. As soon as they rotate they are entirely read-only, never modified again. When you use a tool like "journalctl" to read the journal files both the active and the rotated files are implicitly merged, so that they appear as a single stream again.

Now, our strategy to rotate-on-corruption is the safest thing we can do, as we make sure that the internal corruption is frozen in time, and not attempted to be "fixed" by a tool, that might end up making things worse. After all, in the case the often-run writing code really fucks something up, then it is not necessarily a good idea to try to make it better by running a tool on it that tries to fix it up again, a tool that is necessarily a lot more complex, and also less tested.

Now, of course, having corrupted files isn't great, and we should make sure the files even when corrupted stay as accessible as possible. Hence: the code that reads the journal files is actually written in a way that tries to make the best of corrupted files, and tries to read of them as much as possible, with the the subset of the file that is still valid. We do this implicitly on every access. 

Hence: journalctl implicitly does on read what a theoretical journal file fsck tool would do, but without actually making this persistent. This logic also has a major benefit: as our reader gets better and learns to deal with more types of corruptions you immediately benefit of it, even for old files!

File systems such as ext4 have an fsck tool since they don't have the luxury to just rotate the fs away and fix the structure on read: they have to use the same file system for all future writes, and they thus need to try hard to make the existing data workable again.

I hope this explains the rationale here a bit more.
Comment 4 Florian Hubold 2014-10-08 21:42:06 UTC
Is there any option for journalctl available to delete all known corrupted logfiles, or maybe some config option to regularly (every few months or so) remove corrupted journal files?

In case not, could one of those be added please?
Comment 5 Lennart Poettering 2014-10-08 21:56:45 UTC
(In reply to Florian Hubold from comment #4)
> Is there any option for journalctl available to delete all known corrupted
> logfiles, or maybe some config option to regularly (every few months or so)
> remove corrupted journal files?
> In case not, could one of those be added please?

Why? What's the usecase? Why would you want to throw-away the good parts in the journal files?

Again, the journalctl tries hard to salvage all data from the unit files, should there be a corrupted one, and it does this implicitly, all the time, when showing them. In the best case you hence never notice that something might have gotten corrupted.
Comment 6 Chernovsky Oleg 2014-10-14 06:42:11 UTC
I think he means that the rotated corrupted files don't get deleted on max log age hit. Is that so? I may be wrong

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.